Hi! I need to generate a PWM signal with 50% duty cycle and a variable frequency using atmega32U4. I'm bit confused on how to achieve this. Is anyone able to direct me in the right direction? Which mode I should use? is there any tutorials that covers this particular scenario?
What Compiler do you use. I use mikroC Compiler. It has PWM_Init() function which is used like this.
Code:
PWM1_Init(1000); //1 KHz PWM
You can use ADC which gives value from 0 to 1023. You can map this value to required frequency range and when pot value changes just call the PWM_Init() function once by passing the new frequency value.
I recommend using CTC mode.
And if you use "toggle" for port function, then you automatically have 50% duty cycle and only one register to change frequency.
What Compiler do you use. I use mikroC Compiler. It has PWM_Init() function which is used like this.
Code:
PWM1_Init(1000); //1 KHz PWM
You can use ADC which gives value from 0 to 1023. You can map this value to required frequency range and when pot value changes just call the PWM_Init() function once by passing the new frequency value.
I recommend using CTC mode.
And if you use "toggle" for port function, then you automatically have 50% duty cycle and only one register to change frequency.