[sdiy] PIC Wavetable OSC Timing
Fredrik Carlqvist
ifrc at iar.se
Mon Jan 3 13:03:46 CET 2005
If you are using a PIC with a CCP unit, you can use that easier/better than
just a timer. The CCP method keeps the overhead to a minimum.
I would use the interrupt from CCP1 in compare mode with the side effect
enabled: to clear the timer. The only thing you will have to do is to write
the interrupt period time into the CCP registers (CCPR1L and CCPR1H). Every
time timer 1 reaches the value in the period registers, it will be
automatically reset and a CCP1IF interrupt will be generated. Inside the
interrupt service routine, you just read out the next wave value and output
it to the R-2R ladder and return.
In the main loop, you keep the period registers CCPR1L and CCPR1H updated.
Make sure that you never accidentally write zero into them (for example when
changing from 0xFF to 0x100 and writing the low byte first)! Polling the
UART for MIDI data, you will probably need a table to look up appropriate
interrupt intervals for different MIDI note numbers.
This works the same way on both PIC18 and PIC16 architectures. Using PIC16,
I would enable the CCP1IF interrupt only, and poll all other things, like
MIDI data in for example. Probably, you will have no choise but to write the
application in assembly, because the interrupt overhead of a C compiler
would probably limit the top frequency severely.
On PIC18, I would keep the CCP interrupt at high priority and any other
interrupts on low.
The following example sets up the CCP and TIMER1 units to form a DCO on a
PIC16:
// set up CCP oscillator (PIC16F818)
T1CON = 0x01; // enabled, no prescaler
CCP1CON = 0x0B; // special event trigger
CCP1IE = 1;
If you need more details, don't hesitate to ask!
Good luck!
Fredrik C
________________________________
From: owner-synth-diy at dropmix.xs4all.nl
[mailto:owner-synth-diy at dropmix.xs4all.nl] On Behalf Of William Berzinskas
Sent: den 29 december 2004 22:52
To: synth-diy at dropmix.xs4all.nl
Subject: [sdiy] PIC Wavetable OSC Timing
Hey everyone..
I've made a simple wavetable oscillator.. it's got an r-2r ladder and 64
position waves.. works pretty good for the basic stuff i've got.. got a
few waveforms in there.. nothing special, just the standard tri/saw/square
for testing..
can someone explain to me how to setup the timing to be controllable via
midi..
if i understand correctly, the midi note number would somehow set the reset
point on a timer.. the timer would interrupt at a specified freq, and
output the bits..
assuming i've got that lil theory-ish part right, how to implement it?
More information about the Synth-diy
mailing list