Working on my first real sketch, so will try to keep this short. Feel free to ask more info if needed.
To power a flyback transformer I need to apply PWM -to- a PWM signal. The easiest way to describe this is that while a standard PWM signal is 'on' for some set time, then 'off' for the remainder of the period, I need to send a signal where the 'on' is actually a 14kHz square wave of 50% duty...then pulse this signal ~1 to 100% duty at ~500Hz.
No problem with the 14kHz PWM - I found the PWM.h library and set that up.
But what is the best way to chop that up with a second PWM at, say 500Hz?
With some amount of kludge, can I 'bit bang' it with DO - WHILE? Will WHILE read a variable outside the loop? Are there easier ways?
i=1;
do { //Pulse microsecond 'frames' of high freq signal?
//ie 14kHz carrier PWM'd at 500Hz = 2000 microseconds per 'frame' cycle
//at 50% duty would be 1000 micros high and 1000 micros low
pwmWrite( outpin, 128 ); //Turn on 14kHz carrier at 50% duty
delayMicroseconds(1000); //Delay to generate the 'HIGH' portion of the frame
pwmWrite( outpin, 0 ); //Turn 14kHz carrier off
delayMicroseconds(1000); //Delay to generate the 'LOW' portion of the frame
} while (i == 1); //...and keep doing loop while the state is '1' or 'ON'
delay(1000); //?Will this allow the above loop to repeat while waiting here for 1 second?
i=0; //i != 1, so break out of the while loop above?
//then continue doing other stuff below...
Any help greatly appreciated.
do ... while
here is an infinite loop.tone()
.