Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "PWM Generation"
- - Source Code compiled for: Arduino Nano
- - Source Code created on: 2024-02-15 01:05:34
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Run a half bridge switch mode power supply MOSFETs */
- /* at 125khz with pins 9 and 10 */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <TimerOne.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void blinkLED(void);
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t low_PIN_D9 = 9;
- const uint8_t high_PIN_D10 = 10;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- uint8_t low_PIN_D9_rawData = 0;
- uint8_t high_PIN_D10_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float low_PIN_D9_phyData = 0.0;
- float high_PIN_D10_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- TimerOne myTimer;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(low_PIN_D9, OUTPUT);
- pinMode(high_PIN_D10, OUTPUT);
- // Initialize myTimer to generate PWM frequency at 125kHz
- myTimer.initialize(8); // 125kHz = 1MHz / (8 * 2)
- myTimer.pwm(low_PIN_D9, low_PIN_D9_rawData);
- myTimer.pwm(high_PIN_D10, high_PIN_D10_rawData);
- attachInterrupt(digitalPinToInterrupt(low_PIN_D9), blinkLED, RISING);
- attachInterrupt(digitalPinToInterrupt(high_PIN_D10), blinkLED, FALLING);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- delay(100); // Wait for 100 ms
- }
- void updateOutputs()
- {
- // Update the PWM output on the pins
- myTimer.setPwmDuty(low_PIN_D9, low_PIN_D9_rawData);
- myTimer.setPwmDuty(high_PIN_D10, high_PIN_D10_rawData);
- }
- /***** INTERRUPT SERVICE ROUTINE *****/
- void blinkLED(void)
- {
- // Toggle the data on pins 9 and 10
- low_PIN_D9_rawData = !low_PIN_D9_rawData;
- high_PIN_D10_rawData = !high_PIN_D10_rawData;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement