Dagozilla to RoboCup / EncoderDAGOZ

Files at this revision

API Documentation at this revision

Comitter:
irfantitok
Date:
Fri Jan 25 16:51:33 2019 +0000
Parent:
6:978bd0579f1b
Commit message:
Initial Commit

Changed in this revision

EncoderDAGOZ.cpp Show annotated file Show diff for this revision Revisions of this file
EncoderDAGOZ.h Show annotated file Show diff for this revision Revisions of this file
EncoderInit.cpp Show annotated file Show diff for this revision Revisions of this file
EncoderMspInitF7.cpp Show annotated file Show diff for this revision Revisions of this file
Nucleo_Encoder_16_bits.cpp Show diff for this revision Revisions of this file
Nucleo_Encoder_16_bits.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EncoderDAGOZ.cpp	Fri Jan 25 16:51:33 2019 +0000
@@ -0,0 +1,112 @@
+#include "EncoderDAGOZ.h"
+
+namespace mbed
+{   
+
+    EncoderDAGOZ::EncoderDAGOZ(TIM_TypeDef * _TIM)
+    {
+        TIM = _TIM;
+        // Initialisation of the TIM module as an encoder counter
+        EncoderInit(&encoder, &timer, _TIM, 0xffff, TIM_ENCODERMODE_TI12);
+
+        // Update (aka over- and underflow) interrupt enabled
+        TIM->DIER |= 0x0001;
+        // The initialisation process generates an update interrupt, so we'll have to clear the update flag before anything else
+        TIM->SR &= 0xfffe;
+        //generate update event
+        TIM->EGR = 1;
+        //enable counter
+        TIM->CR1 = 1;
+        
+    }
+    
+    EncoderDAGOZ::EncoderDAGOZ(TIM_TypeDef * _TIM, uint32_t _maxcount, uint32_t _encmode)
+    {
+        TIM = _TIM;
+        // Initialisation of the TIM module as an encoder counter
+        EncoderInit(&encoder, &timer, _TIM, _maxcount, _encmode);
+
+        // Update (aka over- and underflow) interrupt enabled
+        TIM->DIER |= 0x0001;
+        // The initialisation process generates an update interrupt, so we'll have to clear the update flag before anything else
+        TIM->SR &= 0xfffe;
+    }
+    
+    EncoderDAGOZ::EncoderDAGOZ(TIM_Encoder_InitTypeDef * _encoder, TIM_HandleTypeDef * _timer, TIM_TypeDef * _TIM, uint32_t _maxcount, uint32_t _encmode)
+    {
+        timer = *_timer;
+        encoder = *_encoder;
+        TIM = _TIM;
+        // Initialisation of the TIM module as an encoder counter
+        EncoderInit(&encoder, &timer, _TIM, _maxcount, _encmode);
+
+        // Update (aka over- and underflow) interrupt enabled
+        TIM->DIER |= 0x0001;
+        // The initialisation process generates an update interrupt, so we'll have to clear the update flag before anything else
+        TIM->SR &= 0xfffe;
+    }
+
+    
+    int32_t EncoderDAGOZ::GetCounter(bool reset)
+    {
+        int16_t count = TIM->CNT;
+        if(reset){
+            switch((uint32_t)TIM){
+                case TIM1_BASE :
+                    TIM1->CNT = 0;
+                break;
+                
+                case TIM2_BASE :
+                    TIM2->CNT = 0;
+                break;
+                
+                case TIM3_BASE :
+                    TIM3->CNT = 0;
+                break;
+                
+                case TIM4_BASE :
+                    TIM4->CNT = 0;
+                break;
+                
+                case TIM5_BASE :
+                    TIM5->CNT = 0;
+                break;
+                
+                case TIM8_BASE :
+                    TIM8->CNT = 0;
+                break;
+            }
+        }
+        else{
+            switch((uint32_t)TIM)
+            {
+                case TIM1_BASE :
+                    return (int32_t)count;
+                
+                case TIM2_BASE :
+                    return (int32_t)count;
+                
+                case TIM3_BASE :
+                    return (int32_t)count;
+                
+                case TIM4_BASE :
+                    return (int32_t)count;
+                
+                case TIM5_BASE :
+                    return (int32_t)count;
+                    
+                case TIM8_BASE :
+                    return (int32_t)count;
+            }
+        }
+        
+        return (int32_t)count;
+    }
+    
+    
+    TIM_HandleTypeDef* EncoderDAGOZ::GetTimer()
+    {
+        return &timer;    
+    }
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EncoderDAGOZ.h	Fri Jan 25 16:51:33 2019 +0000
@@ -0,0 +1,30 @@
+#ifndef ENCODER_H
+#define ENCODER_H
+#include "mbed.h"
+
+void EncoderInit(TIM_Encoder_InitTypeDef * encoder, TIM_HandleTypeDef * timer, TIM_TypeDef * TIMx, uint32_t maxcount, uint32_t encmode);
+
+namespace mbed{
+    
+    class EncoderDAGOZ {
+        
+        public :
+            EncoderDAGOZ(TIM_TypeDef * _TIM);
+            EncoderDAGOZ(TIM_TypeDef * _TIM, uint32_t _maxcount, uint32_t _encmode);
+            EncoderDAGOZ(TIM_Encoder_InitTypeDef * _encoder, TIM_HandleTypeDef * _timer, TIM_TypeDef * _TIM, uint32_t _maxcount, uint32_t _encmode);
+            int32_t GetCounter(bool reset);
+            TIM_HandleTypeDef* GetTimer();
+        
+        private :
+        
+        
+        protected :
+            TIM_Encoder_InitTypeDef encoder;
+            TIM_HandleTypeDef timer;
+            TIM_TypeDef * TIM;
+        
+    };
+
+}// namespace mbed
+
+#endif
\ No newline at end of file
--- a/EncoderInit.cpp	Fri Jan 25 07:58:34 2019 +0000
+++ b/EncoderInit.cpp	Fri Jan 25 16:51:33 2019 +0000
@@ -9,9 +9,6 @@
     timer->Init.Prescaler = 0;
     timer->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
     
-    //Kalo ngerusak hapus aja ini
-    //HAL_TIM_Base_Init(timer);
-
     encoder->EncoderMode = encmode;
 
     encoder->IC1Filter = 0x0F;
--- a/EncoderMspInitF7.cpp	Fri Jan 25 07:58:34 2019 +0000
+++ b/EncoderMspInitF7.cpp	Fri Jan 25 16:51:33 2019 +0000
@@ -42,6 +42,7 @@
         GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
         HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
     }
+    
     else if (htim->Instance == TIM2) { //PA_15 PB_3
         __TIM2_CLK_ENABLE();
         __GPIOA_CLK_ENABLE();
@@ -90,29 +91,6 @@
         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
         GPIO_InitStruct.Alternate = GPIO_AF3_TIM8;
         HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-    }
-    
-    else if (htim->Instance == TIM9) { // PE_5 PE_6
-        __TIM9_CLK_ENABLE();
-        __GPIOE_CLK_ENABLE();
-        GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6;
-        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-        GPIO_InitStruct.Alternate = GPIO_AF3_TIM9;
-        HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
-    }
-    
-    else if (htim->Instance == TIM12) { // PB_14 PB_15
-        __TIM12_CLK_ENABLE();
-        __GPIOB_CLK_ENABLE();
-        GPIO_InitStruct.Pin = GPIO_PIN_14 | GPIO_PIN_15;
-        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-        GPIO_InitStruct.Pull = GPIO_NOPULL;
-        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-        GPIO_InitStruct.Alternate = GPIO_AF9_TIM12;
-        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-    }
-    
+    }    
 }
 #endif
\ No newline at end of file
--- a/Nucleo_Encoder_16_bits.cpp	Fri Jan 25 07:58:34 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-#include "Nucleo_Encoder_16_bits.h"
-
-namespace mbed
-{   
-
-    Nucleo_Encoder_16_bits::Nucleo_Encoder_16_bits(TIM_TypeDef * _TIM)
-    {
-        TIM = _TIM;
-        // Initialisation of the TIM module as an encoder counter
-        EncoderInit(&encoder, &timer, _TIM, 0xffff, TIM_ENCODERMODE_TI12);
-
-        // Update (aka over- and underflow) interrupt enabled
-        TIM->DIER |= 0x0001;
-        // The initialisation process generates an update interrupt, so we'll have to clear the update flag before anything else
-        TIM->SR &= 0xfffe;
-    }
-    
-    Nucleo_Encoder_16_bits::Nucleo_Encoder_16_bits(TIM_TypeDef * _TIM, uint32_t _maxcount, uint32_t _encmode)
-    {
-        TIM = _TIM;
-        // Initialisation of the TIM module as an encoder counter
-        EncoderInit(&encoder, &timer, _TIM, _maxcount, _encmode);
-
-        // Update (aka over- and underflow) interrupt enabled
-        TIM->DIER |= 0x0001;
-        // The initialisation process generates an update interrupt, so we'll have to clear the update flag before anything else
-        TIM->SR &= 0xfffe;
-    }
-    
-    Nucleo_Encoder_16_bits::Nucleo_Encoder_16_bits(TIM_Encoder_InitTypeDef * _encoder, TIM_HandleTypeDef * _timer, TIM_TypeDef * _TIM, uint32_t _maxcount, uint32_t _encmode)
-    {
-        timer = *_timer;
-        encoder = *_encoder;
-        TIM = _TIM;
-        // Initialisation of the TIM module as an encoder counter
-        EncoderInit(&encoder, &timer, _TIM, _maxcount, _encmode);
-
-        // Update (aka over- and underflow) interrupt enabled
-        TIM->DIER |= 0x0001;
-        // The initialisation process generates an update interrupt, so we'll have to clear the update flag before anything else
-        TIM->SR &= 0xfffe;
-    }
-
-    
-    int32_t Nucleo_Encoder_16_bits::GetCounter(bool reset)
-    {
-        int16_t count = TIM->CNT;
-        if(reset){
-            switch((uint32_t)TIM){
-                case TIM1_BASE :
-                    TIM1->CNT = 0;
-                break;
-                
-                case TIM2_BASE :
-                    TIM2->CNT = 0;
-                break;
-                
-                case TIM3_BASE :
-                    TIM3->CNT = 0;
-                break;
-                
-                case TIM4_BASE :
-                    TIM4->CNT = 0;
-                break;
-                
-                case TIM5_BASE :
-                    TIM5->CNT = 0;
-                break;
-                
-                case TIM8_BASE :
-                    TIM8->CNT = 0;
-                break;
-                
-                case TIM9_BASE :
-                    TIM9->CNT = 0;
-                break;
-                
-                case TIM12_BASE :
-                    TIM12->CNT = 0;
-                break;
-                
-            }
-        }
-        else{
-            switch((uint32_t)TIM)
-            {
-                case TIM1_BASE :
-                    return (int32_t)count;
-                
-                case TIM2_BASE :
-                    return (int32_t)count;
-                
-                case TIM3_BASE :
-                    return (int32_t)count;
-                
-                case TIM4_BASE :
-                    return (int32_t)count;
-                
-                case TIM5_BASE :
-                    return (int32_t)count;
-                    
-                case TIM8_BASE :
-                    return (int32_t)count;
-                  
-                case TIM9_BASE :
-                    return (int32_t)count;
-                    
-                case TIM12_BASE :
-                    return (int32_t)count;
-                
-            }
-        }
-        
-        return (int32_t)count;
-    }
-    
-    
-    TIM_HandleTypeDef* Nucleo_Encoder_16_bits::GetTimer()
-    {
-        return &timer;    
-    }
-    
-}
\ No newline at end of file
--- a/Nucleo_Encoder_16_bits.h	Fri Jan 25 07:58:34 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-#ifndef ENCODER_H
-#define ENCODER_H
-#include "mbed.h"
-
-void EncoderInit(TIM_Encoder_InitTypeDef * encoder, TIM_HandleTypeDef * timer, TIM_TypeDef * TIMx, uint32_t maxcount, uint32_t encmode);
-
-namespace mbed{
-    
-    class Nucleo_Encoder_16_bits {
-        
-        public :
-            Nucleo_Encoder_16_bits(TIM_TypeDef * _TIM);
-            Nucleo_Encoder_16_bits(TIM_TypeDef * _TIM, uint32_t _maxcount, uint32_t _encmode);
-            Nucleo_Encoder_16_bits(TIM_Encoder_InitTypeDef * _encoder, TIM_HandleTypeDef * _timer, TIM_TypeDef * _TIM, uint32_t _maxcount, uint32_t _encmode);
-            int32_t GetCounter(bool reset);
-            TIM_HandleTypeDef* GetTimer();
-        
-        private :
-        
-        
-        protected :
-            TIM_Encoder_InitTypeDef encoder;
-            TIM_HandleTypeDef timer;
-            TIM_TypeDef * TIM;
-        
-    };
-
-}// namespace mbed
-
-#endif
\ No newline at end of file