I have a basic AVR setup with ATmega328P and a FreeRTOS kernel running on it. I want to toggle a GPIO pin set as output at high frequency between 30kHz-60kHz. The frequency of GPIO toggle is continuously determined by other RTOS tasks and function which is between 30kHz-60kHz.
I want to ask how to toggle the GPIO at such high frequencies that are constantly changing. I am using Atmel Studio 7. Please help.
If you plan to change the frequency at about let's say every 2 pulse then software MAY be a solution. If the frequency will stay for several 10th or 100ds of pulses, PWM is definitely the good way to do.
Of course you can manage PWM frequency and period on the go. You will need to read timer/counterX with PWM part of the datasheet. If you need always 50% duty cycle, §15.7.2 is the best way to configure. If you need both duty cycle and frequency the §15.7.3 is adapted.
Cover all the possible configuration would be to broad to write here but if you start implementation and experience issues you can ask new question.