Hi everyone, I need some help. I have a short question: is there any possibility to change pwm frequency on Arduino Yun? And how can I do that?
I have already tried this one: PWM frequency library - Libraries - Arduino Forum but the Yun uses the Atmega32u4.
Can somebody give me a short example of some code which changes a frequenci to 100Hz, or a tutorial or library...
Thanks!
Plan B:
PWM at Linux side
echo "+ 0 27 1 3000" > /sys/kernel/debug/pwm-ar9331
blink system LED connect with GPIO 27 with 1 Hz frequency at around 1/2 duty cycle using timer 0
-
16 bit PWM
- maximum frequency 125 kHz
- super easy API
- support up to 29 GPIO pins
One bad news is incompatible with Yun since Yun is masked all the GPIO pin (design fraud?). but it is compatible with Yun shield.
Thank you for help. Well, I have a Yun board not a shield, so it can't help me.
I have learned something abouth the TCCRnB registers, editing the timers, which I think can help me. I just don't know where can I find which timer is connected with which output pin. Can you help me with that?
I want to use something like:
TCCR1B = TCCR1B & 0b11111000 | 0x05;
just not sure is it ok?
I need to do this for 4 output, the frequency should be somewhere around 100Hz.
To find what output is connected to the timer event you should read the Atmega 32u4 datasheet.
If you read the timer section you can find the PWM hardware configuration. At page 99 there is an explanation of the PWM modes of operation and you can find the formula to calculate the frequency for each mode.
You need to write the value that set the frequency in the OCRnx register and then you write the TCCRnx bits in order to tell to the hardware to use the OCRnx value instead of 0xFF.
Keep in mind that if I write OCRnx I mean that n is a number and x a letter. There are more than one timer and PWM output: the number identifies the timer and the letter the output.
If you look at the Atmega32u4 pinout you can find OCnx pins. These pins are PWM output.