
Originally Posted by
krohtech
Oh, sorry I forgou to mention I am using an 18F PIC. Can I use the timer template -14?
You're talking about one of my favorite 'staples' whenever I build something...I call it a 'heartbeat'...
I have an LED connected to a specific pin...
I set up Timer 0 to run at a decent rate according to my main clock speed...i.e. once per second-ish, 4 times per second-ish, doesn't really matter, as long as I can see it blink.
Then every Timer 0 overflow, I increment a byte variable, last I set the LED to follow a certain bit of that variable.
So, say I use 'temp' as my variable.
myint:
temp = temp + 1
led = temp.0 'led will flash on/off every other time thru loop
resume
If the LED flashes too fast, I use temp.1, still too fast, maybe temp.2.
Or, conversely, if I use temp.4, and that flash is too slow, I'll use temp.3, or temp.2, whatever...until I find a flash rate that works for me.
DT's Fast interrupts and SSPWM code are great pieces of code...but I think they're big time overkill for what you want...
An example cut from one of my last programs:
Code:
'CONFIG statements semi-permanently set in PBP 18F4620 .INC file
resetplaceholder: '18f4620 code
DEFINE OSC 10
DEFINE NO_CLRWDT 1 'no extra clear watchdog timer instructions
DISABLE
CLEAR
led1 var porta.5
heartbeat var byte
startupholder:
goto skipsubs 'skip over all the commonly used subroutines
ON INTERRUPT GOTO INTHANDLER
DISABLE
INTHANDLER: if intcon.2 = 1 then 'timer 0 overflow interrupt handler
intcon.2 = 0
heartbeat = heartbeat + 1
led1 = heartbeat.0 'led flash about every ~1.6 seconds
' change heartbeat.0 to heartbeat.X where x = 0 - 7 to change heart beat flash rate
INTFINISH:
RESUME
DISABLE
'end of commonly used subroutines, skipsubs block for setting up registers, lcd, whatever else...
skipsubs:
t0con = $84
intcon = $e0
cmcon = 7
pie2 = $80
trisa = 0
porta = 0
led1 = 0
output led1
' change prescale value in $84 to change flash rate
ENABLE
mainloop:
' do something useless or useful here
goto mainloop
END
IF you're not using a '4620, then you'll have to figure out which registers need which values as far as interrupt and timer registers go.
I chose porta.5 because it was available. Change that to what you need also.
Bookmarks