Go Down

Topic: Setting two pins to fast PWM (Read 693 times) previous topic - next topic

tonysnail

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

Code: [Select]

#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: [Select]

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

tonysnail

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?

  ;)

Magician

Define:
Code: [Select]
#define PWM_PIN2       11
#define PWM_VALUE_DESTINATION2     OCR2A

and
Code: [Select]
PWM_VALUE_DESTINATION2 = outputvalue;

tonysnail

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

Magician

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

Go Up