Digital TC Interrupter
Description from source code:
/*
Digital Tesla Coil Interrupter
Chester Lowrey 2008-10-11
Purpose:
To interrupt the main drive of a DRSSTC so as to limit the average power and create interesting spark effects.
Uses two independent timers, the slow timer interrupting the fast timer
Fast Timer Specs: Fixed ~100us on time - Variable 250us - 25ms(4khz - 40hz) Off Time
Slow Timer Specs: 5hz - 250HZ and 0 - 100% Duty Cycle
Potentiometers control the 3 main inputs
One: Fast timer Frequency - IE Off Time
Two: Slow Timer Duty Cycle
Three: Slow Timer Frequency
Four: Modulation - used to create some interesting effects
The Fourth potentiometer has a built in on/off switch and when off its effect on the output is disabled.
The main three data outputs are displayed on an 8X2 charicter LCD on port D
Why fixed on time? because I'm using an external hardware pulse width and period limiter anyway, so having two on time controls would be redundant.
To make it variable, on this line: FastTimerCompare = FastTimerPeriodTemp + 200; you would change 200 to a variable and use some math beforehand to get it into the correct range
Then you could have a nice readout of the on time too - I still like the extra protection of the external limiter incase something goes wrong...
Brief code explanation:
All the timing is done with hardware timers
Timer1 = Fast timer - interrupt generated on overflow
Timer1 has the prescaler disabled so the period is 400ns(at 10mhz HS crystal)
CCP1 is set to compare Timer1 - on compare the CCP1 pin goes low - when the CCP1 module is reset it goes high
Timer3 = Slow timer - interrupt generated on overflow
Timer3 has the prescaler set to 1:8(the max) for a period of 3.2us
ECCP1 is set to compare Timer3 - on compare an interrupt is generated.
WHAT THE MAIN LOOP DOES:
Read analog inputs
Read and debouce switches
If the modulation is enabled override some/all of the analog inputs
Calculate timer preset and compare values using temp variables - Temp variables are necessary becauset we dont want the interrupt getting the wrong data
Set the real variables to the temp variables
Display the current settings on the LCD - only done every 50 main loops
HOW THE INTERRUPT ROUTINE WORKS: - The order thigns are done is critical - I wish I could say I figured it all out in my head,
but it took alot of trial and error to get things set right - there are so many different ways it could be organized
- there may still be room for improvement
On Slow Timer overflow interrupt:
If duty cycle greater than 2% then : FastTimer is initialized, FastTimerCompare is reset, FastTimerCompare value is updated, FastTimer is preset
SlowTimerCompare value is updated, SlowTimer is preset
On Slow Timer compare interrupt:
Disable CCP1, Clear CCP1 output pin, Disable Fast Timer
On Fast Timer overflow interrupt:
FastTimerCompare is reset, FastTimerCompare value is updated, Fast Timer is preset
*/
PDF with Schematics + PCB layout: Digital TC Interrupter.pdf
Software for PIC18F458 Microcontroller: Interrupter.zip
folder containing relevant part datasheets
Last Updated: 2008-12-10