on test and not completed based on nucleo_hello_encoder library

Dependencies:   mbed

Fork of Nucleo_Hello_Encoder by David Lowe

Committer:
c128
Date:
Tue Sep 29 06:56:28 2015 +0000
Revision:
3:5c895f9199d6
Parent:
2:70f92ce7d983
Child:
4:26948bebef6c
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gregeric 0:ee5cb967aa17 1 /*
gregeric 0:ee5cb967aa17 2 * Using STM32's counter peripherals to interface rotary encoders.
gregeric 0:ee5cb967aa17 3 * Encoders are supported on F4xx's TIM1,2,3,4,5. TIM2 & TIM5 have 32bit count, others 16bit.
gregeric 0:ee5cb967aa17 4 * Beware mbed uses TIM5 for system timer, others for PWM.
gregeric 0:ee5cb967aa17 5 * Check your platform's PeripheralPins.c & PeripheralNames.h if you need both PWM & encoders.
gregeric 0:ee5cb967aa17 6 *
gregeric 0:ee5cb967aa17 7 * Edit HAL_TIM_Encoder_MspInitFx.cpp to suit your mcu & board's available pinouts & pullups/downs.
gregeric 0:ee5cb967aa17 8 *
gregeric 0:ee5cb967aa17 9 * Thanks to:
gregeric 0:ee5cb967aa17 10 * http://petoknm.wordpress.com/2015/01/05/rotary-encoder-and-stm32/
gregeric 0:ee5cb967aa17 11 *
gregeric 0:ee5cb967aa17 12 * References:
gregeric 0:ee5cb967aa17 13 * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00122015.pdf
gregeric 0:ee5cb967aa17 14 * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00096844.pdf
gregeric 0:ee5cb967aa17 15 * http://www.st.com/web/en/resource/technical/document/application_note/DM00042534.pdf
gregeric 0:ee5cb967aa17 16 * http://www.st.com/web/en/resource/technical/document/datasheet/DM00102166.pdf
gregeric 0:ee5cb967aa17 17 *
gregeric 0:ee5cb967aa17 18 * David Lowe Jan 2015
gregeric 0:ee5cb967aa17 19 */
gregeric 0:ee5cb967aa17 20
gregeric 0:ee5cb967aa17 21 #include "mbed.h"
c128 1:3d2fffa6e19f 22 #include "counter.h"
gregeric 0:ee5cb967aa17 23
c128 1:3d2fffa6e19f 24 TIM_IC_InitTypeDef counterSet1;
c128 1:3d2fffa6e19f 25 TIM_HandleTypeDef timer1;
c128 3:5c895f9199d6 26
gregeric 0:ee5cb967aa17 27 int main()
gregeric 0:ee5cb967aa17 28 {
c128 2:70f92ce7d983 29
c128 1:3d2fffa6e19f 30 CounterInit(counterSet1, timer1, TIM1, 0xffff);
c128 2:70f92ce7d983 31
gregeric 0:ee5cb967aa17 32
gregeric 0:ee5cb967aa17 33 printf("STM HAL encoder demo\n\r");
gregeric 0:ee5cb967aa17 34
gregeric 0:ee5cb967aa17 35 while(1) {
c128 1:3d2fffa6e19f 36 int16_t count1;
gregeric 0:ee5cb967aa17 37
gregeric 0:ee5cb967aa17 38 count1=TIM1->CNT; //OK 401 411 TICKER 030
c128 2:70f92ce7d983 39
c128 1:3d2fffa6e19f 40 printf("%d\r\n", count1);
gregeric 0:ee5cb967aa17 41 wait(1.0);
gregeric 0:ee5cb967aa17 42 }
gregeric 0:ee5cb967aa17 43 }