Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having problems with using Arduino Leonardo PWM outputs (I'm actually using YUN board).

I need 4 PWM outputs that generally have the same base frequency of around 10 to 20 Hz or so.

I'm using timer 1 (A-pin-9,B-pin-10,C-pin-11) and timer 4 (A-pin-13)

I get pins 9,10,and 13 PWM output working decent, but for some reason pin 11 PWM frequency is much much higher.

Pins 9,10,11 should be working off TIMER 1 which all use the same pre-scaler, so I dont know how 9 and 10 can have one frequency, and 11 have a different frequency.

Here is my code can anybody see anything wrong? thanks!

    #define PWM_4A_PIN  13 
    #define PWM_1C_PIN  11

    #define PWM_1B_PIN  10 
    #define PWM_1A_PIN  9 

    void setup() {
     TCCR1B = TCCR1B & 0b11111000 | 0x05;
     TCCR4B = TCCR1B & 0b11110000 | 0x09;
     analogWrite(PWM_4A_PIN,128);
     analogWrite(PWM_1C_PIN,128);
     analogWrite(PWM_1B_PIN,128);
     analogWrite(PWM_1A_PIN,128);
    }

    void loop() 
    {
    }
share|improve this question

Pins 9,10,11 should be working off TIMER 1 which all use the same pre-scaler, so I dont know how 9 and 10 can have one frequency, and 11 have a different frequency.

Unless D11 is configured as OC0A instead of OC1C, which means that it will work off timer 0.

TCCR0A &= ~(_BV(COM0A1) | _BV(COM0A0));
TCCR1A |= _BV(COM1C1) | _BV(COM1C0);
 ...
OCR1C = ...;
share|improve this answer
    
Thanks Inacio, I tried your code but the same result D11 has much higher freq than 9 and 10, its very strange! – rough neck Sep 9 '14 at 14:59
1  
Did you use analogWrite() on D11? That will reset it to OC0A. – Ignacio Vazquez-Abrams Sep 9 '14 at 15:04
    
if I replace analogWrite(11,128) with OCR1C=128, then no output at all – rough neck Sep 9 '14 at 15:16
1  
I need to keep changing the PWM duty cycle, so I cant use analogwrite for any pin, only OC1C, OC1A, OC1B fro then on? – rough neck Sep 9 '14 at 15:35
1  
analogWrite() does a lot of housekeeping behind the scenes, including preparing the pin for how it thinks it should work. One of these bits is setting D11 as OC0A. Another is setting the PWM frequency. Sometimes the Arduino libraries are handy, and sometimes they interfere. – Ignacio Vazquez-Abrams Sep 9 '14 at 15:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.