Created
November 7, 2017 15:55
-
-
Save stefandz/874dd5ffe3d953c0a3421db466efe96c to your computer and use it in GitHub Desktop.
Offset sinewave generation for testing PWM open drain circuitry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int num_pwm_pins = 4; | |
const int pwm_pins[ num_pwm_pins ] = { 9, 10, 11, 13 }; | |
uint8_t tick_count = 0; | |
void setup() { | |
for( uint8_t i=0; i<num_pwm_pins; i++ ){ | |
pinMode( pwm_pins[ i ], OUTPUT ); | |
} | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
for( uint8_t i=0; i<num_pwm_pins; i++ ){ | |
analogWrite( pwm_pins[ i ], (uint8_t)( 127.f * ( 1.f - cos( TWO_PI * (( (float)tick_count / 255.f) + ( (float)i / (float)num_pwm_pins )))))); | |
} | |
tick_count++; // we utilise overflow here deliberately | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment