TIM 초기화 함수

void TIM_Configuration()

{

  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

  TIM_OCInitTypeDef  TIM_OCInitStructure;

  uint16_t PrescalerValue = 0;

  

  /* Compute the prescaler value */

  PrescalerValue = (uint16_t) (SystemCoreClock / 50000) - 1;

  

  /* Time base configuration */

  TIM_TimeBaseStructure.TIM_Period = 1000-1;

  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

  

  TIM_PrescalerConfig(TIM4, PrescalerValue, TIM_PSCReloadMode_Immediate);

  

  /* PWM1 Mode configuration: Channel3 */

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse = CCR3_Val;

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;

  TIM_OC3Init(TIM4, &TIM_OCInitStructure);

  TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);

  

  TIM_ARRPreloadConfig(TIM4, ENABLE);

  

  /* TIM4 Update DMA Request enable */

  TIM_DMACmd(TIM4, TIM_DMA_CC3, ENABLE);

  

  /* TIM4 enable counter */

  TIM_Cmd(TIM4, ENABLE);

  

  /* Main Output Enable */

  TIM_CtrlPWMOutputs(TIM4, ENABLE);

}


Frequency, cycle을 결정하는 부분


TIM_TimeBaseStructure.TIM_Period = 1000-1;

TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;


stm32는 기본적으로 sysclk이 존재하고 TIM는 이것을 Presclaer로 분주한 후 분주된 CK_CNT으로 INT를 발생 시킨다. 여기서 TIM_TimeBaseStructure.TIM_Period의 단위도 Hz다.


Freq와 Cycle 계산 방법


Cycle은 TIM_TimeBaseStructure.TIM_Prescaler로 분주된 값(CK_CNT)으로 TIM_TimeBaseStructure.TIM_Period를 나누어주면 된다. 의미는 CK_CNT이 TIM_TimeBaseStructure.TIM_Period를 수행하기 위해서 몇 초 걸리는가. 예를 들어서 CK_CNT는 50kHz 이고, TIM_TimeBaseStructure.TIM_Period는 1000Hz 일 때 한번 INT발 생하는데에 20ms 가 걸린다.


Freq는 TIM_TimeBaseStructure.TIM_Period으로 CK_CNT를 나누어주면 된다. 여기서 잠깐 TIM_TimeBaseStructure.TIM_Period만큼 clock 발생하면 flag가 발생한다. 따라서 TIM_TimeBaseStructure.TIM_Period로 CK_CNT를 나누는 의미는 CK_CNT동안에 몇번 flag가 발생하느냐로 볼 수 있다. 예를 들어서  CK_CNT는 50kHz이고, TIM_TimeBaseStructure.TIM_Period는 1000Hz 일 때 1초 동안 50kHz를 진동하는 동안 (50kHz/1000Hz) 번 flag가 발생한다.

'MCU > ARM' 카테고리의 다른 글

ADC independent DMA (2)  (0) 2016.08.14
ADC main feature(1)  (0) 2016.08.13
SPI 통신 (3)  (0) 2016.08.11
SPI 통신 (2)  (0) 2016.08.11
SPI 통신 (1)  (0) 2016.08.11
Posted by 나무길 :

Accelerometer, Gyro and IMU Selection Guide (from www.sparkfun.com)


가속도센서, 자이로센서, IMU에 대한 설명 및 선택방법이 sparkfun.com에 간단하게 잘 설명되어 있어 옮겨봅니다.


Accelerometers and gyros are becoming increasingly popular in consumer electronics, so maybe it’s time you added them to your project! Scrolling through SparkFun’s sensors category reveals a huge list of these sensors that might be perfect for your next project, if only you knew what they did, and which one best fit your project. The goal of this buying guide is to get you speaking the same language as these sensors' datasheets and to help you select the one that is best-suited for your needs.


Accelerometers (가속도센서)

What’s an accelerometer measure? Well, acceleration. You know…how fast something is speeding up or slowing down. You’ll see acceleration displayed either in units of meters per second squared , or G-force (g), which is about 9.8(the exact value depends on your elevation and the mass of the planet you’re on).

가속도센서는 물체가 얼만큼 빨라지는지 또는 늦어지는지의 가속도를 측정합니다.  가속도의 단위는 m/s2 또는 G-force 중력가속도 = 9.8m/s2입니다. 


Accelerometers are used to sense both static (e.g. gravity) and dynamic (e.g. sudden starts/stops) acceleration.

가속도 센서는 중력가속도 등의 정적인 또는 갑자기 출발하거나 서는 동적인 가속도, 둘 모두 측정할 때 쓰입니다.


One of the more widely used applications for accelerometers is tilt-sensing. Because they are affected by the acceleration of gravity, an accelerometer can tell you how it’s oriented with respect to the Earth’s surface. For example, Apple’s iPhone has an accelerometer, which lets it know whether it’s being held in portrait or landscape mode.

가장 흔히 사용되는 용도중의 하나는 기울기 측정입니다.  중력가속도에 영향을 받으므로 가속도센서는 지구표면에 대하여 얼마큼 기울어져 있는지 알 수 있습니다. 예를 들면, 애플의 아이폰의 경우 가속도센서가 안에 있어 사용자가 전화기를 위아래로 보고 있는지 옆으로 보고 있는지를 알려줍니다.


An accelerometer can also be used to sense motion. For instance, an accelerometer in Nintendo’s WiiMote can be used to sense emulated forehands and backhands of a tennis racket, or rolls of a bowling ball.

가속도센서는 또한 움직임을 감지할 때도 쓰입니다.  예로 닌텐도위에서는 가속도센서가 측정한 값들이 테니스 라켓을 포핸드로 휘들르는지 백핸드로 치는지, 볼링볼을 굴리는것을 구현합니다.


Finally, an accelerometer can also be used to sense if a device is in a state of free fall. This feature is implemented in several hard drives: if a drop is sensed, the hard drive is quickly switched off to protect against data loss.

마지막으로 가속도센서는 또한 물체가 자유낙하하는 상황을 감지합니다.  이는 하드드라이브가 떨어지고 있는 상황을 감지하면 스위치를 끄게 함으로써 데이터를 잃게 되는 상황을 방지하는 장치에 이용되기도 합니다.


Now that you know what they do, let’s consider what characteristics you should be looking for when selecting your accelerometer:

그러면 가속도센서를 선택함에 있어 고려할 특성을 살펴보기로 합니다.

1. Range - The upper and lower limits of what the accelerometer can measure is also known as its range. In most cases, a smaller full-scale range means a more sensitive output; so you can get a more precise reading out of an accelerometer with a low full-scale range. 

측정범위 - 대개의 경우 측정범위가 작을수록 민감한 측정이 됩니다.

You want to select a sensing range that will best fit your project, if your project will only be subjected to accelerations between +2g and -2g, a ±250g-ranged accelerometer won’t give you much, if any, precision.

가속도가 -2g 에서 2g 사이로 예상될 경우에 -250g 에서 250g 사이를 측정할 수 있는 센서를 쓰면 정확한 측정이 불가합니다.

We have a good assortment of accelerometers, with maximum ranges stretching from ±1g to ±250g. Most of our accelerometers are set to a hard maximum/minimum range, however some of the fancier accelerometers feature selectable ranges.


2. Interface - This is another one of the more important specifications. Accelerometers will have either an analog, pulse-width modulated (PWM), or digital interface.

인터페이스 - 가속도센서는 측정값을 아날로그, PWM 신호, 또는 디지털신호중 하나로 출력합니다. 


a. Accelerometers with an analog output will produce a voltage that is directly proportional to the sensed acceleration. At 0g, the analog output will usually reside at about the middle of the supplied voltage (e.g. 1.65V for a 3.3V sensor). Generally this interface is the easiest to work with, as analog-to-digital converters (ADCs) are implemented in most microcontrollers.  

아날로그출력을 하는 가속도센서에서는 입력전압의 중간값을 (예로서 3.3V 입력에서는 1.65V) 0g로 하여 측정값을 비례로 전압을 출력합니다.  대개의 마이크로프로세서의 경우 ACD가 내장되어 있으므로 가장 쉬운 방법이 되겠습니다.  


b. Accelerometers with a PWM interface will produce a square wave with a fixed frequency, but the duty cycle of the pulse will vary with the sensed acceleration. These are pretty rare; we’ve only got one in our catalog.

PWM출력 센서는 드물지만, 고정된 주파수에서 측정가속도를 펄스의 듀티사이클로써 출력합니다. 


c. Digital accelerometers usually feature a serial interface be it SPI or I²C. Depending on your experience, these may be the most difficult to get integrated with your microcontroller. That said, digital accelerometers are popular because they usually have more features, and are less susceptible to noise than their analog counterparts.

디지털신호를 출력하는 경우 SPI 또는 I2C의 직렬신호 방식을 주로 씁니다.  각자의 경험에 따라 사용이 어려운 방식이 될 수 있으나 더 많은 기능과 아날로그 방식보다는 노이즈에 대한 신뢰도가 높아 많이 쓰입니다.



3. Number of axes measured - This one’s very straightforward: out of the three axes possible (x, y, and z), how many can the accelerometer sense? Three-axis accelerometers are usually the way to go; they are the most common and they are really no more expensive than equivalently sensitive one or two axis accelerometers.

측정 축의 수 - x, y, z 축 중 측정할 수 있는 축의 수를 말하며, 3축의 경우 1,2축과 가격의 차이가 별로 없어 대부분 3축을 씁니다.


4. Power Usage - If your project is battery powered, you might want to consider how much power the accelerometer will consume. The required current consumption will usually be in the 100s of µA range. Some sensors also feature sleep functionality to conserve energy when the accelerometer isn’t needed.

소비 전류량을 말하며 일부의 경우 슬립기능이 있습니다.



5. Bonus Features - Many more recently developed accelerometers may have a few nifty features, beyond just producing acceleration data. These newer accelerometers may include features like selectable measurement ranges, sleep control, 0-g detection, and tap sensing.

그외 측정범위 설정, 슬립기능 키고 끄기, 0g 탐지 등의 기능이 있기도 합니다.

 

Gyros (자이로센서)

Gyroscopes measure angular velocity, how fast something is spinning about an axis. 

자이로센서는 축이 얼마나 빠른 속도로 회전하는지를 측정합니다.


If you’re trying to monitor the orientation of an object in motion, an accelerometer may not give you enough information to know exactly how it’s oriented. Unlike accelerometers gyros are not affected by gravity, so they make a great complement to each other.

움직이는 물체에서 방향을 측정할때 가속도센서로는 어디를 향하고 있는지 측정하지 못합니다.  자이로센서는 가속도센서와는 달리 중력의 영향을 받지 않으므로 가속도센서와 같이 조합하여 쓰기에 좋습니다. 


You’ll usually see angular velocity represented in units of rotations per minute (RPM), or degrees per second (°/s). The three axes of rotation are either referenced as x, y, and z, or roll, pitch, and yaw.

각속도의 경우 RPM (1분간 회전수) 또는 °/s (1초당 회전각) 이 단위이며, x, y, z 축 또는 roll, pitch, and yaw로 3축을 표현합니다.


In the past, gyros have been used for space navigation, missile control, under-water guidance, and flight guidance. Now they are starting to be used alongside accelerometers for applications like motion-capture and vehicle navigation.

예전에는 우주항해, 미사일제어, 잠수함, 비행기 등에 자이로센서가 많이 쓰였으나 현재에는 가속도센서와 더불어 동작인식과 자동차 내비게이션에 쓰이기 시작하였습니다.  


A lot of what was considered when selecting an accelerometer still applies to selecting the perfect gyro:

1. Range - Make sure the maximum angular velocity you’re expecting to measure doesn’t exceed the maximum range of the gyro. But also, in order to get the best possible sensitivity, make sure your gyro’s range isn’t much greater than what you’re expecting.

측정범위 - 예상값이 측정범위 안에 들어가야 하며, 정확도를 위하여 측정범위가 예상값보다 너무 크지 않도록 함. 


2. Interface - There’s actually not much diversity in this section, 95% of the gyros we have feature an analog output. There are a few that have a digital interface - either SPI or I2C.

95%의 자이로는 아날로그 인터페이스 제공.  SPI 나 I2C 의 디지털출력은 적음.


3. Number of axes measured - Compared to accelerometers, gyros are a little behind the curve. Only recently have inexpensive, 3-axis gyros begun to appear on the market. Most of our gyros are either 1- or 2-axis. When selecting those, you need to pay attention to which of the three axes the gyro will measure; for example, some two axis gyros will measure pitch and roll, while others measure pitch and yaw.

가속도센서에 비하면 자이로센서는 3축이 저렴하게 선보인지 얼마 안되었음. 대부분 1 또는 2축 임.  자이로센서를 고를때 3축중 어느축에 대하여 측정하는지 주의 필요. 


4. Power Usage - If your project is battery powered, you might want to consider how much power the gyro will consume. The required current consumption will usually be in the 100s of µA range. Some sensors also feature sleep functionality to conserve energy when the gyro isn’t needed.

소비전류를 말하며 일부의 경우 슬립기능이 있습니다.


5. Bonus Features - Not much in this section is going to blow you away. Many gyros feature a temperature output, which is very useful when compensating for drift. 

혁신적인 추가기능은 별로 없으며 보정을 위한 온도측정값을 출력해 주는 자이로센서가 많다. 


IMUs

Gyroscopes and accelerometers are great, but alone they don’t give you quite enough information to be able to comfortably calculate things like orientation, position, and velocity. 

자이로센서나 가속도센서는 훌륭하지만 한가지 센서로서는 방향, 위치, 속도에 대한 모든 정보를 주지 않습니다.


To measure those and other variables many people combine the two sensors, to create an inertial measurement unit (IMU) which provides two to six degrees of freedom (DOF). IMUs are widely used in devices that require knowledge of their exact position, for example robotic arms, guided missiles, and tools used in the study of body motion.

이러한 이유로 두가지 센서를 조합하여 2~6 자유도를 제공하는 IMU라는 센서를 만들었으며 정확한 위치 정보를 필요로하는 로봇, 유도미사일, 바디모션 연구의 도구 등에서 쓰입니다.


SparkFun’s IMUs can really be broken down into two classes: simple IMU combo boards, which just mount an accelerometer and gyro onto a single PCB, and more complex units that interface a microcontroller with the sensors to produce a serial output. If you’ve glanced over the previous sections, you should know what kind of specifications to be looking for in IMUs: the number of axes (both for the accelerometer and gyro), the measuring range of the sensors, and the interface.

IMU에는 두가지 부위로 이루어져 있는데 가속도센서와 자이로센서 부위와 출력을 위한 부위입니다.  역시 축의 갯수 (가속도센서와 자이로센서 모두), 측정범위 및 인터페이스를 고려하여야 합니다.

[출처] 가속도 센서, 자이로 센서, IMU 선택 방법 (from www.sparkfun.com)|작성자 hcheong


Posted by 나무길 :

프로세스란?

2017. 3. 28. 19:51 from 리눅스

Process란 무엇인가에 대해 알아보겠습니다.

프로세스란 이름은 정말 많이 들어보셨을테고, 무엇인지에 대해서도 많이 아시기 때문에

여기서는 간단하게 한번 더 Remind하는 시간을 가지겠습니다.


프로세스를 많은 사람들이 실행 중인 프로그램이라고 알고 있습니다.

맞는 말입니다. 틀린 말이 아니죠. 프로세스는 사용 중인 파일, 데이터, 프로세서 상태, 메모리 영역 주소 공간, 스레드 정보, 전역 데이터가 저장 된 메모리 부분 등 수 많은 자원을 포함하는 개념입니다.

종종 스케줄링의 대상이 되는 작업(task)라고 불리기도 한답니다.


프로세스는 최소 하나의 스레드를 가지고 있습니다. UNIX 시스템에서는 하나의 프로세스는 하나의 스레드 만을 가지고 있었지만, 리눅스 시스템에서는 하나의 프로세스가 하나의 스레드만 가질 필요는 없습니다. 여러 스레드로 구성된 프로세스를 생성할 수 있다는 말이죠.

그럼 리눅스 커널에서는 프로세서에 task로 무엇을 할당을 하게 될까요? 프로세서에 할당되는 task는 프로세스가 아닌 스레드입니다. 리눅스에서는 스레드와 프로세스의 구분이 크지 않습니다. 

그저 스레드를 조금(?) 특별한 프로세스로 취급할 뿐이죠.


프로세스는 부모가 생성함으로써 그 삶을 시작하게 됩니다. 즉 혼자 스스로 창조 될 수 는 없습니다.

항상 부모가 존재하고, 그 부모에 의해 자식 프로세스가 생성 되는 것입니다.


여기까지가 간단한 프로세스에 대해 주저리주저리 떠들어 봤는데요, 다음부터는 프로세스에 대해 좀 더 구체적으로 한번 파고 들어가 보겠습니다. 


참고 : http://sonseungha.tistory.com/241

Posted by 나무길 :