Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

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

1 Answer 1

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
    
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
    
Here is the whole code as it is now#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; TCCR0A &= ~(_BV(COM0A1) | _BV(COM0A0)); TCCR3A |= _BV(COM1C1) | _BV(COM1C0); //TCCR0A=0; //TCCR1A=0xb01010101; pinMode(11,OUTPUT); OCR1C=128; analogWrite(PWM_4A_PIN,128); //analogWrite(PWM_1C_PIN,128); analogWrite(PWM_1B_PIN,128); analogWrite(PWM_1A_PIN,128); } void loop() { } –  rough neck Sep 9 '14 at 15:17
    
Call analogWrite() once to configure everything else, then perform the assignments in my answer. –  Ignacio Vazquez-Abrams Sep 9 '14 at 15:20

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.