I'm new to Arduino microcontrollers. For my project, I'm programming an Arduino Mega2560 that will output a 13620Hz PWM signal with varying pulse widths from timer 1. The operation mode of the timer 1 is fast pwm mode with a clock prescalar of one. The pulse widths, in microseconds, is 5us, 4us, 3us, 2us, and 1us. I converted these pulse widths and the pwm frequency into clock cycles in decimal, and then, into clock cycles in hexadecimal. The calculations of the pulse widths and the pwm frequency are shown below:
Pulse Width (in us) / (1/f_timer) = Pulse Width in clock cycles (decimal)
PWM frequency = f_timer/(N*(TOP+1))
I assumed that f_timer equals the cpu frequency (16MHz) since the datasheet did not say what the frequency of f_timer was.
Also, I adapted the program to output a 60 Hz signal with a 8.33ms pulse width, but the pulse width, in ms, of the pwm signal and the frequency of the pwm signal was not correct.
Any help would be greatly appreciated. The program is attached to this post below.
Thanks in advance.
output_compare_test.ino (1.8 KB)