Pages: [1]   Go Down
Author Topic: Setting two pins to fast PWM  (Read 603 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm building a wavetable VCO - and I found this code to set pin 3 to fast PWM (for the audio output):

Code:
#define PWM_PIN       3
#define PWM_VALUE_DESTINATION     OCR2B
#define PWM_INTERRUPT TIMER2_OVF_vect

TCCR2A = _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS20);
TIMSK2 = _BV(TOIE2);

and then the interrupt timer does this..

Code:
PWM_VALUE_DESTINATION = outputvalue;
outputvalue = (((uint8_t)(osc.amplitude>>8)) * pgm_read_byte(sintable+((osc.phase>>16)%LUTsize)))>>8;

Alas though, I don't really understand this! And what I want to do is get a second PWM pin to do exactly the same (to create a second oscillator) -
I read that pin 11 can also be set to fast PWM..

Does anyone know the code to implement this?


Carl
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

in the end, I just put analogWrite(11, outputvalue) - it works, but it's really clumsy and a little too slow.. Surely some of you clever people out there know how to address pin 11 by it's memory address?

  smiley-wink
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2569
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Define:
Code:
#define PWM_PIN2       11
#define PWM_VALUE_DESTINATION2     OCR2A
and
Code:
PWM_VALUE_DESTINATION2 = outputvalue;
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just tried this but it's not working.. Still no sound on pin 11,,
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 27
Posts: 2569
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Add this
Code:
TCCR2A = _BV(COM2B1) | _BV(WGM20) | _BV(COM2A1);
And don't forget to set 11 as output - pinMode.
Logged

Pages: [1]   Go Up
Jump to: