PWM Output question

Hi Guys,

I'm fully new here, this is my first post.
I really would like to learn Arduino, so I've bought a few Nano's, and built a synth module, based on the Ginko Grains :

Actually, my module is a bit different, because I have a CV filter/booster circuit on Pin5 and Pin6 to boost the levels for modular use.

My problem is that the Ginko codes using Pin11 as the output and I really don't know, how to change it to Pin5 or Pin6

Could you please take a look?

Code :

// Changing these will also requires rewriting audioOn()
// Output is on pin 11
#define PWM_PIN 11
#define PWM_VALUE OCR2A
#define LED_PIN 13
#define LED_PORT PORTB
#define LED_BIT 5
#define PWM_INTERRUPT TIMER2_OVF_vect

void audioOn() {
// Set up PWM to 31.25kHz, phase accurate
TCCR2A = _BV(COM2A1) | _BV(WGM20);
TCCR2B = _BV(CS20);
TIMSK2 = _BV(TOIE2);
}

You need to study the Atmel datasheet for the Atmega 328.

There are 3 different hardware Timers and each one is linked to a pair of I/O pins. Your code uses Timer2 and you will need to change it to use the Timer that is linked to pins 5 and 6.

...R

Hi Robin,

Thank you for the reply.
I've found out that pin 5-6 is controlled by Timer 0.

Means, I should change the code like this : (if I'm correct)

// Changing these will also requires rewriting audioOn()
// Output is on pin 5
#define PWM_PIN 5
#define PWM_VALUE OCR0A
#define LED_PIN 13
#define LED_PORT PORTB
#define LED_BIT 5
#define PWM_INTERRUPT TIMER0_OVF_vect

void audioOn() {
// Set up PWM to 31.25kHz, phase accurate
TCCR2A = _BV(COM2A1) | _BV(WGM20);
TCCR2B = _BV(CS20);
TIMSK0 = _BV(TOIE2);
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Robin2:
You need to study the Atmel datasheet for the Atmega 328.

There are 3 different hardware Timers and each one is linked to a pair of I/O pins. Your code uses Timer2 and you will need to change it to use the Timer that is linked to pins 5 and 6.

...R

And the bad news is all 3 timers are different (although similar).

timer0, 8 bit, pins 5 (OCR0A), 6 (OCR0B) (also used for millis(), micros(), delay())
timer1, 16 bit, pins 9 (OCR1A),10 (OCR1B)
timer2, 8 bit, pins 11 (OCR2A), 3 (OCR2B)

note that timer0 and timer2 are different in detail despite being both 8 bit, and that if you
reprogram timer0 then millis(), micros(), delay() no longer work as expected.