Counter using TIM2

Dependencies:   mbed

Fork of Nucleo_Hello_counter by paolo della vedova

Files at this revision

API Documentation at this revision

Comitter:
c128
Date:
Tue Sep 29 06:50:08 2015 +0000
Parent:
1:3d2fffa6e19f
Child:
3:5c895f9199d6
Commit message:
UPDATE

Changed in this revision

Encoder/CounterInit.cpp Show annotated file Show diff for this revision Revisions of this file
Encoder/CounterMspInitF4.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Encoder/CounterInit.cpp	Tue Sep 29 06:42:15 2015 +0000
+++ b/Encoder/CounterInit.cpp	Tue Sep 29 06:50:08 2015 +0000
@@ -4,7 +4,7 @@
 {
     timer.Instance = TIMx;
     timer.Init.Period = maxcount;
-    timer.Init.CounterMode = TIM_COUNTERMODE_UP;
+    timer.Init.CounterMode = TIM_COUNTERMODE_UP; //TIM_COUNTERMODE_CENTERALIGNED3 for up/down ...
     timer.Init.Prescaler = 0;
     timer.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
     timer.Init.RepetitionCounter = 0;
--- a/Encoder/CounterMspInitF4.cpp	Tue Sep 29 06:42:15 2015 +0000
+++ b/Encoder/CounterMspInitF4.cpp	Tue Sep 29 06:50:08 2015 +0000
@@ -8,6 +8,7 @@
  * Encoder A&B outputs connected directly to GPIOs.
  *
  */
+ // STM32 F4 HAL https://github.com/mbedmicro/mbed/blob/03fff9249b0ca5efb2e12506ce8fb3e6cc258d9d/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_tim.h
 
 #ifdef TARGET_STM32F4
 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
@@ -17,7 +18,7 @@
     if (htim->Instance == TIM1) { //PA8 PA9 = Nucleo D7 D8, poss PB0 PB1 usable too (complementary?)
         __TIM1_CLK_ENABLE();
         __GPIOA_CLK_ENABLE();
-        GPIO_InitStruct.Pin = GPIO_PIN_8;// | GPIO_PIN_9;
+        GPIO_InitStruct.Pin = GPIO_PIN_8;// | GPIO_PIN_9;   //test one pin for now without direction
         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
         GPIO_InitStruct.Pull = GPIO_PULLDOWN;
         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
--- a/main.cpp	Tue Sep 29 06:42:15 2015 +0000
+++ b/main.cpp	Tue Sep 29 06:50:08 2015 +0000
@@ -26,22 +26,9 @@
 
 int main()
 {
-    //examples
-    //EncoderInit(TIM_IC_InitTypeDef counterSet, TIM_HandleTypeDef timer, TIM_TypeDef *TIMx, uint32_t maxcount);
-    //counting on A-input only, 2 ticks per cycle, rolls over at 100
+
     CounterInit(counterSet1, timer1, TIM1, 0xffff);
-    
-    //counting on both A&B inputs, 4 ticks per cycle, full 32-bit count
-    //EncoderInit(encoder2, timer2, TIM2, 0xffffffff, TIM_ENCODERMODE_TI12);
-
-    //counting on B-input only, 2 ticks per cycle, full 16-bit count
-    //EncoderInit(encoder3, timer3, TIM3, 0xffff, TIM_ENCODERMODE_TI2);
-    
-    //counting on both A&B inputs, 4 ticks per cycle, full 16-bit count
-    //EncoderInit(encoder4, timer4, TIM4, 0xffff, TIM_ENCODERMODE_TI12);
-    
-    //TIM5 is used by mbed for systick
-    //EncoderInit(encoder2, timer2, TIM5, 0xffffffff, TIM_ENCODERMODE_TI12);
+   
     
     printf("STM HAL encoder demo\n\r");
     
@@ -49,10 +36,7 @@
         int16_t count1;
         
         count1=TIM1->CNT; //OK 401 411 TICKER 030
-        //count2=TIM2->CNT; //OK 401 411 N/A 030
-        //count3=TIM3->CNT; //OK 401 411 030
-        //count4=TIM4->CNT; //OK 401 NOK 411 N/A 030
-        //count5=TIM5->CNT; //TICKER 401 411 N/A 030
+
         printf("%d\r\n", count1);
         wait(1.0);
     }