C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
hw_pwm.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include "pico/stdlib.h"
15#include "hardware/pwm.h"
16#include "hardware/clocks.h"
17
22class PWM
23{
24private:
26 uint8_t slice;
28 uint step_ns;
30 uint period_us;
31
32public:
37 static uint32_t slice_mask;
38
43 static void StartTogether();
44
63 PWM(uint gpio_ch_A,
64 uint gpio_ch_B,
65 int step_ns, // min = PERIOD_us * 1000 / 64535 < step_ns < max = 256 * 8ns*(phase_correct+1) = ca 2us
66 int period_us, // period_us max = 64535 * step_ns*(phase_correct+1)
67 bool phase_correct = false,
68 bool ch_A_inverted = false,
69 bool ch_B_inverted = false);
70
76 void start(bool enabled);
77
84 void set_width_nb_of_step(uint gpio_pin, uint16_t level);
85
92 void set_duty_cycle(uint gpio_pin, float duty_cycle);
93
99 void set_irq(irq_handler_t handler);
100
105 void clear_irq();
106};
107
113{
114private:
116 uint8_t slice;
118 uint measure_duration_us;
120 uint resolution_ns;
121
122public:
123
132 PWMgatedMeasure(uint pin_gate,
133 uint resolution_ns,
134 uint measure_duration_us);
140 float measure_duty_cycle();
141
147 uint16_t count_cycles();
148};
149
void clear_irq()
clear the slice IRQ
Definition hw_pwm.cpp:67
PWM(uint gpio_ch_A, uint gpio_ch_B, int step_ns, int period_us, bool phase_correct=false, bool ch_A_inverted=false, bool ch_B_inverted=false)
Construct a new PWM object assuming free running sys_clk @125 MHz => sys_clk_period = 8 ns PERIOD = 8...
Definition hw_pwm.cpp:7
void set_width_nb_of_step(uint gpio_pin, uint16_t level)
Set the pulse width in terms number of step object.
Definition hw_pwm.cpp:47
void set_irq(irq_handler_t handler)
Set the irq handler, executed each time the PWM counter wrap to 0.
Definition hw_pwm.cpp:58
static void StartTogether()
All the defined PWM slices will be synchronised.
Definition hw_pwm.cpp:37
static uint32_t slice_mask
a class variable that hold the slice number for the PWM object
Definition hw_pwm.h:37
void set_duty_cycle(uint gpio_pin, float duty_cycle)
Set the pulse width in terms of duty cycle.
Definition hw_pwm.cpp:52
void start(bool enabled)
start and stop the current PWM slice
Definition hw_pwm.cpp:42
float measure_duty_cycle()
compute the time the channel B is HI over the time of observation
Definition hw_pwm.cpp:91
uint16_t count_cycles()
gives the number of step while the signal on channel B is HI
Definition hw_pwm.cpp:97
PWMgatedMeasure(uint pin_gate, uint resolution_ns, uint measure_duration_us)
Construct a new PWMgatedMeasure object.
Definition hw_pwm.cpp:72