So my code here generates a PWM wave of 38Khz on Port B pin 7 of arduino Mega 2560 . For that I have used a prescaler of 8 and then set the ICR1 register value to 51 . I have also set the WGM10 ,WGM11, WGM12 and WGM13 bits to 1 , to enable fast PWM mode with Top reference value as ICR1 contents . Similarly , COM1A1 is set , to enable clear output on compare equal else high . CS11 is set to high to enable the prescaler 8 .
My code is as follows -
#include<avr/io.h>
#include <avr/iomxx0_1.h>
#include<util/delay.h>
void pwm_init()
{
// Configure PB.7 as output pin
DDRB |= (1<<PB7);
TCCR1A = (1<<WGM11) | (1<<WGM10) | (1<<COM1A1);
TCCR1B =(1<<WGM12) | (1<<WGM13) | (1<<CS11);
ICR1 = 51;
}
void pwm_generate()
{
OCR1A = (50 * 52)/100 ;
}
int main()
{
pwm_init();
pwm_generate();
}
What I require from the program is that , it should stop producing pwm pulses once a sufficient number of pulses are transmitted . For example - The program should output 7 pwm pulses of 38Khz and then it should give logic 0 as output for specified time period . And then after that specified period , it should produce 38 Khz pwm wave again of say, 5 pulses and then again logic 0 for certain duration . And so on ... How do i achieve this ?
PS- This program is actually being written to simulate a pwm wave required by the IR transmitters in TV remote . The PWM pulses represent the ON period and the Logic 0 conditions would represent the gap in between two successive train of PWM pulses.