I'm using Arduino YUN PWM pins 9, 10, 11, and 13, and have it set up so all are using the same PWM frequency.
Everything is working fine, but now I NEED TWO MORE PWMs.
I have PWM pins 3, 5, 6 available.
My existing code is below, does anybody know how I can add the two needed PWM outputs using any of pins 3, 5, or 6 using the same frequency as the rest of the PWMs??
#define pwm_13 OCR4A
#define pwm_11 OCR1C
#define pwm_10 OCR1B
#define pwm_9 OCR1A
#define PWM_4A_PIN 13
#define PWM_1C_PIN 11
#define PWM_1B_PIN 10
#define PWM_1A_PIN 9
void Timer0init()
{
TIFR0 =0x00;
TCCR0A = 0;// set entire TCCR0A register to 0
TCCR0B = 0;// same for TCCR0B
TCNT0 = 0;//initialize counter value to 0
OCR0A = 125;
TCCR0A |= (1 << WGM01);
TCCR0B |= 0x03; //0x02; // (1 << CS01) | (1 << CS00);
TIMSK0 |= (1 << OCIE0A);
}
void initADC()
{
ADCSRA &=0xF8; //clear prescaler bits
ADCSRA |=0x05;
}
void initPWM()
{
TCCR1B = TCCR1B & 0b11111000 | 0x05;
TCCR4B = TCCR1B & 0b11110000 | 0x0B;
analogWrite(PWM_4A_PIN,128);
analogWrite(PWM_1C_PIN,128);
analogWrite(PWM_1B_PIN,128);
analogWrite(PWM_1A_PIN,128);
TCCR0A &= ~(_BV(COM0A1) | _BV(COM0A0));
TCCR1A |= _BV(COM1C1);
}
void setup()
{
Timer0init();
initADC();
initPWM();
...
}
void loop()
{
pwm_13=v1++;
pwm_11=v2++;
pwm_10=v3++;
pwm_9 =v4++;
}
TCCR1B
) with Arduino API (analogWrite()
). Why not use just Arduino (or just AVR)? – jfpoilpret Oct 18 '14 at 16:37