MThardPWM
Event management for Uno, Nano, Mega
Generates a PWM signal with a 16-bit timer.
Include to add
#include <MTobjects.h> // See http://arduino.dansetrad.fr/en/MTobjects
I strongly advise to leave the comment, if another person wanted to try the program, they would have a download link directly. This is valid for all the libraries you use.
Useful comments
micro_second micro_seconds inpulse_width inpulses_width period_width periods_width per_cent
These comments are words that can be added anywhere and which are ignored by the compiler.
Constructor
MThardPWM(pin, periodMicrosecond = 20000 μs, inpulseMicrosecond = 10000 μs);
- pin (uint8_t): output pin; Uno/Nano: 9, 10 Mega: 2, 3, 5, 6, 7, 8, 11, 12, 13, 44, 45, 46
- inpulseMicrosecond (float): inpulse width in milliseconds
- periodMicrosecond (float): period in millisecondes, outputs (9,10), (2, 3, 5), (6, 7, 8), (11, 12, 13), (44, 45, 46) have the same frequency, eg change the frequency of the pin 7 also changes the frequency of pins 6 and 8 if they are used..
Useful functions
void setInpulse(float inpulseMicrosecond); void setDutyCycle(float dutyCycle); void setPeriod(float periodMicrosecond); void detach(void); void attach(void);
setInpulse: change the inpulse width
setInpulse: without parameter set inpulse width to 10ms
setDutyCycle: change the inpulse width with a duty cycle
setDutyCycle: without parameter set a 50% duty cycle 50%
setPeriod: change the period
setPeriod: without parameter set a 20ms period (50Hz)
detach: Disconnects the pin, it becomes "normal" as a starter (does not erase times programmed)
attach: Reconnect the pin, if it was detached
Bonus functions
float getInpulse(void); float getPeriod(void); float getDutyCycle(void); float getResolution(void);
getInpulse: return the inpulse width
getPeriod: return the period
getDutyCycle: return the duty cycle
getResolution: returns the resolution in μs (between 62.5ns and 64μs)
Examples