Go Down

Topic: more PWM outputs on arduino mega (Read 858 times) previous topic - next topic

DeFex

Feb 05, 2010, 04:45 am Last Edit: Feb 05, 2010, 02:43 pm by DeFex Reason: 1
Use more PWM outputs on arduino mega

I am using some borrowed code as part of a synthesizer, i understand how everything else works, but not the timer setup.

I am outputting to multiplying DACs i would like to use the PWM outputs to control the reference voltage on the DACS (for envelope shaper and LFO functions) this will give a lot better quality sound because the output waveform will always be using the whole 8 bits and its volume will be altered by a further 256 levels.

anyways so far i have one output working on timer 3B (pin3)

Timer 3 is running at 31.25 KHZ which is perfect, and  also generating the interrupts which are used for the waveform generation, any other timers would not have to generate interrupts, just be able to have an 8 bit value set from within the main loop or the timer 3 ISR.

I do not quite understand if "phase accurate" prevents the other PWM pins
of timer 3 from being used, but i have not had any luck getting output from any other pins at all. (except with ye olde analogwrite)
however i do not think i need to use phase accurate because i am no altering audio with it but slower moving control voltages.

I would appreciate it if someone has already been through this and could show me how to get 4, or preferably 8 PWM pins available for analog parts of the circuit, (prefferably all at the same speed so i dont have to recaluclate analog filters)

I could spend (probably a long time) trying to pull together all the information, but i am working on the sound and modulations of the actual synth, and thought i would ask here first. to see if someone can help with the nuts and bolts.


here is what is working on pin3(timer 3B, mega)

arduino 0017
Code: [Select]

//MEGA ONLY
#define PWM_PINt3B  3  //t3B = timert 3 b
//#define PWM_PINt??      
//#define PWM_PINt??      

#define PWM_VALUE_DESTINATION     OCR3C
// #define PWM_VALUE_DESTINATION2     ????? etc
#define PWM_INTERRUPT TIMER3_OVF_vect

void initializeTimer() {
// Set up PWM  with Clock/256

//this is what i havent got a clue about!
 TCCR3A = _BV(COM3C1) | _BV(WGM30);  
 TCCR3B = _BV(CS30);  
 TIMSK3 = _BV(TOIE3); //set the interrupt

 pinMode(PWM_PINt3b,OUTPUT);
// pinMode(PWM_PINt??,OUTPUT);
// pinMode(PWM_PINt??,OUTPUT);
 

}


Best regards
DeFex


Go Up