Sure. You will have to set your timer to interrupt at some frequency. In your ISR, you will have to check an array of your 5 PWMs to see if it is time for each of them to toggle.
@MorganS - Well timer2 cannot be used because it has maximum prescalar value of 64 thus with 50 Hz frequency the OCR value goes beyond 255.
And using timer0 with prescalar of 256 or 1024 gives me ICR value in decimals but I am preferring to use integer values though I guess float or double would also work.
//set timer1 interrupt at 1Hz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = 15624;// = (1610^6) / (11024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12 and CS10 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();//allow interrupts
}//end setup
ISR(TIMER1_COMPA_vect){//timer1 interrupt 1Hz toggles pin 13 (LED)
//generates pulse wave of frequency 1Hz/2 = 0.5kHz (takes two cycles for full wave- toggle high then toggle low)
if (toggle1){
digitalWrite(13,HIGH);
toggle1 = 0;
}
else{
digitalWrite(13,LOW);
toggle1 = 1;
}
}
This is just a simple code to generate pulse wave with frequency of 1hz and duty ratio=50%
How do I adjust it to make 3 pulse waves with duty ratio 25%, 50% and 75%
50Hz is SLOW. 1Hz is positively glacial for an Arduino. Even the slow ones can do 16 million things in one second.
I would do this with simple millis() timing but since you are well on the path to making the timer work, let's keep going with that...
What is the smallest timing interval you need? If you never need to go smaller than 25% of 50Hz then you need your timer to interrupt you at periods of 25 milliseconds. Then count to three (from zero). At zero, turn them all on. At one, turn off the first one, at two, the second and at three they are all off.