
Counter using TIM2
Fork of Nucleo_Hello_counter by
main.cpp
- Committer:
- c128
- Date:
- 2015-09-29
- Revision:
- 3:5c895f9199d6
- Parent:
- 2:70f92ce7d983
- Child:
- 4:26948bebef6c
File content as of revision 3:5c895f9199d6:
/* * Using STM32's counter peripherals to interface rotary encoders. * Encoders are supported on F4xx's TIM1,2,3,4,5. TIM2 & TIM5 have 32bit count, others 16bit. * Beware mbed uses TIM5 for system timer, others for PWM. * Check your platform's PeripheralPins.c & PeripheralNames.h if you need both PWM & encoders. * * Edit HAL_TIM_Encoder_MspInitFx.cpp to suit your mcu & board's available pinouts & pullups/downs. * * Thanks to: * http://petoknm.wordpress.com/2015/01/05/rotary-encoder-and-stm32/ * * References: * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00122015.pdf * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00096844.pdf * http://www.st.com/web/en/resource/technical/document/application_note/DM00042534.pdf * http://www.st.com/web/en/resource/technical/document/datasheet/DM00102166.pdf * * David Lowe Jan 2015 */ #include "mbed.h" #include "counter.h" TIM_IC_InitTypeDef counterSet1; TIM_HandleTypeDef timer1; int main() { CounterInit(counterSet1, timer1, TIM1, 0xffff); printf("STM HAL encoder demo\n\r"); while(1) { int16_t count1; count1=TIM1->CNT; //OK 401 411 TICKER 030 printf("%d\r\n", count1); wait(1.0); } }