Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PID mbed-rtos
Encoder.h
00001 00002 00003 #ifndef ENCODER_H_ 00004 #define ENCODER_H_ 00005 00006 #include <cstdlib> 00007 #include "mbed.h" 00008 00009 00010 /** 00011 * This class implements a driver to read the quadrature 00012 * encoder counter of the STM32 microcontroller. 00013 */ 00014 00015 00016 class Encoder { 00017 00018 public: 00019 00020 Encoder(PinName& hallsensor); 00021 virtual ~Encoder(); 00022 uint8_t reset(); // Reset pulse count to 49000, return 0 when not resetted or 1 when resetted 00023 uint32_t read(); // Return Pulses 196000 pulses per Rotation(Pedals) 00024 float readAngle(); // Return Angle in Radiants 00025 float readFrequency(); // Return Drehzahl der pedale in rad/s 00026 float readAcceleration(); // Return Acceleration of pedale in rad/s^2 00027 float readRPM(); // Return Drehzahl in RPM 00028 void ResetInterrupt(); 00029 operator short(); 00030 00031 00032 private: 00033 00034 TIM_TypeDef* TIM; 00035 InterruptIn HallSensor; 00036 PinName hallsensor; 00037 Ticker ticker; 00038 void calculateFrequency(); // Fucntion, which calculate the frequency every 5ms 00039 00040 const static float PI = 3.141592654; 00041 const static float dt = 0.005; // 5ms 00042 uint8_t resetOn; 00043 float frequency; 00044 float acceleration; 00045 00046 }; 00047 00048 #endif /* ENCODER_COUNTER_H_ */
Generated on Mon Aug 1 2022 09:49:43 by
