-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathSTM32PWMInput.h
More file actions
58 lines (45 loc) · 1.64 KB
/
STM32PWMInput.h
File metadata and controls
58 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include "Arduino.h"
#if defined(_STM32_DEF_)
class STM32PWMInput {
public:
/**
* StM32PWMInput constructor
*
* @param pin - the pin number to read the PWM signal from
* @param pwm_freq - the frequency of the PWM signal (default is 1kHz)
*
* This class is used to read PWM signals from a pin using the STM32 HAL library.
* IMPORTANT!
* This class can only be used with the pins that are assocaited with some timer,
* and only if they are associated to the channels 1 or 2. The timer can not be
* used for other purposes, like motor control.
*/
STM32PWMInput(int pin, uint32_t pwm_freq = 1000);
~STM32PWMInput();
int initialize();
/**
* Get the duty cycle of the PWM signal as a percentage.
*
* @return float - the duty cycle in percent
*/
float getDutyCyclePercent();
/**
* Get the duty cycle of the PWM signal in ticks.
*
* @return uint32_t - the duty cycle in ticks
*/
uint32_t getDutyCycleTicks();
/**
* Get the period of the PWM signal in ticks.
*
* @return uint32_t - the period in ticks
*/
uint32_t getPeriodTicks();
PinName _pin; // the pin to read the PWM signal from
uint32_t _pwm_freq; // the frequency of the PWM signal
protected:
TIM_HandleTypeDef timer; // the timer handle for the PWM input
bool useChannel2 = false; // whether to use channel 2 or not, default is channel 1
};
#endif