Oh, sorry I forgou to mention I am using an 18F PIC. Can I use the timer template -14?
Oh, sorry I forgou to mention I am using an 18F PIC. Can I use the timer template -14?
Best Regards,
Kurt A. Kroh
KrohTech
“Goodbye and thanks for all the fish”
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:
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.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
I chose porta.5 because it was available. Change that to what you need also.
Last edited by skimask; - 9th February 2008 at 07:53. Reason: Removed runny colons....nya nya... :D
I'm thinking just the Blinky example is all you need.
DT_INTS-18 (Blinky Light)
http://darreltaylor.com/DT_INTS-18/blinky.html
Or, even better ...
DT_INTS-18 (Assembly Language Interrupts)
http://darreltaylor.com/DT_INTS-18/asm_ints.html
Same Blinky LED, without the Basic Language Interrupt overhead.
And no running Colon's
<br>
DT
Yes, this is the code I am using but I can't get it working in the same program as the multi SPWM. I am useing multi SPWM for my 8 pwm dimmers.
Also I have played with the prescaler to slow down the blink rate but have had no sucess. is there a formula for this like in the -14 version?
I will also make an attempt to digest Skymask's timer 0 overflow interrupt handler in the morning.
Thanks Darrel and Skymask. You are both very helpful.
Best Regards,
Kurt A. Kroh
KrohTech
“Goodbye and thanks for all the fish”
The original SPWM will not work with Instant Interrupts.
They both want complete control of the interrupts. (can't happen)
However, SPWM_INT will work with Instant Interrupts.
And yes, the version shown in the -14 section will work on the 18F's too.
DT_INTS-14 (SPWM_INT - Multiple Software PWM)
http://darreltaylor.com/DT_INTS-14/SPWM.html
SPWM_INT uses Timer1, so if you also want a Blinky light, you'll need to use a different Timer. (0, 2 or 3)
And if you want to use either of the SPWM versions, then you can't use skimask's code.
They are not compatible with ON INTERRUPT.
<br>
DT
And if you want my opinion (nobody really does, but that's beside the point), you'd do real good to learn how to use DT's Instant Interrupt's instead of relying on PBP's On Interrupt.
It's not only good coding with good applications, you just plain learn a lot in the process...and then you spend more money and more time on PICs and PBP and less time on...well, wait a minute...gotta eat sometime...right?
I have SPWM_INT working really well. I am doing 16 ch of PWM on a pic 18F2410 32 MHz. The pwm is running at 100Hz 8 bit resolution.
Here is where I am having trouble. I tried to add a blinky from the DT_INTS-18 example and change it to timer0 with no success. Darrel, can you point me in the correct direction?
Best Regards,
Kurt A. Kroh
KrohTech
“Goodbye and thanks for all the fish”
here is my current code, changed to 101 PWM resolution to reduce overhead
Code:'-----------------------------SPWM INT----------------------------- CLEAR INCLUDE "DT_INTS-18.bas" ; Base Interrupt System INCLUDE "SPWM_INT.bas" ; Software PWM module INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts LED2 VAR PORTA.5 DEFINE SPWM_FREQ 100 ; SPWM Frequency DEFINE SPWM_RES 101 ; SPWM Resolution DutyVars VAR BYTE[16] ; DutyCycle Variables DutyVar1 VAR DutyVars[0] ; group them in an array for easy access DutyVar2 VAR DutyVars[1] ; with FOR loops etc. DutyVar3 VAR DutyVars[2] DutyVar4 VAR DutyVars[3] DutyVar5 VAR DutyVars[4] DutyVar6 VAR DutyVars[5] DutyVar7 VAR DutyVars[6] DutyVar8 VAR DutyVars[7] DutyVar9 VAR DutyVars[8] DutyVar10 VAR DutyVars[9] DutyVar11 VAR DutyVars[10] DutyVar12 VAR DutyVars[11] DutyVar13 VAR DutyVars[12] DutyVar14 VAR DutyVars[13] DutyVar15 VAR DutyVars[14] DutyVar16 VAR DutyVars[15] ASM SPWM_LIST macro ; Define Pin's to use for SPWM SPWM_PIN PORTB, 0, _DutyVar1 ; and the associated DutyCycle variables SPWM_PIN PORTB, 1, _DutyVar2 ; Notice the underscore before variables SPWM_PIN PORTB, 2, _DutyVar3 SPWM_PIN PORTB, 3, _DutyVar4 SPWM_PIN PORTB, 4, _DutyVar5 SPWM_PIN PORTB, 5, _DutyVar6 SPWM_PIN PORTB, 6, _DutyVar7 SPWM_PIN PORTB, 7, _DutyVar8 SPWM_PIN PORTC, 0, _DutyVar9 SPWM_PIN PORTC, 1, _DutyVar10 SPWM_PIN PORTC, 2, _DutyVar11 SPWM_PIN PORTC, 3, _DutyVar12 SPWM_PIN PORTC, 4, _DutyVar13 SPWM_PIN PORTC, 5, _DutyVar14 SPWM_PIN PORTC, 6, _DutyVar15 SPWM_PIN PORTC, 7, _DutyVar16 endm SPWM_INIT SPWM_LIST ; Initialize the Pins ENDASM ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, SPWMhandler, ASM, yes INT_Handler TMR0_INT, _ToggleLED2, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM T0CON = %10010010 ; T0 = 16-bit, Prescaler 8 @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts @ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts '-----------------------------Main Program----------------------------- Main:
Best Regards,
Kurt A. Kroh
KrohTech
“Goodbye and thanks for all the fish”
I think the Cut&Paste didn't catch everything.
Can you post the Main: and Handler parts?
Thanks.
DT
Bookmarks