COOL!!!! You are moving right along.
Here is an idea. Setup a hardware timmer to change the display once per second.
COOL!!!! You are moving right along.
Here is an idea. Setup a hardware timmer to change the display once per second.
Last edited by mackrackit; - 19th March 2010 at 22:12.
Dave
Always wear safety glasses while programming.
Hi mackrackitHere is an idea. Setup a hardware timmer to change the display once per second.
Are we saying for example to use the trimmer pot on the PICkit1 to alter the display speed ADC? (ADCIN).
I'm seriously considering buying the the full program version by the way (I'm just trying to convince myself I'm clever enough to figure out how to use / make the most of it...lol).
Really enjoying it though (headaches aside ;-))
Dave
Last edited by LEDave; - 19th March 2010 at 23:12.
No, not trimmer... or timmer .... I really need to get a dictionary
Timer as in TMRO.
Many times we will at the beginning of a new project to make sure things are setup correctly we will do a simple "blinky" just like we tell the newbees to do. I will a lot of times leave it running as a "heart beat" type of thing. But if you do this using pauses to blink the LED the pauses will maybe get in the way.
So now comes a basic interrupt based on time.
This may or may not be correct for your chip so verify with the data sheet.
Code:INTCON.5 = 1 'ENABLE TMR0 OPTION_REG = %10000101 '16BIT 1:64 PRESCALE ON INTERRUPT GOTO TLOOP MAINLOOP: 'MAIN CODE GOES HERE GOTO MAINLOOP DISABLE TLOOP: INTCON.2=0:TOGGLE PORTD.4 RESUME: ENABLE
Dave
Always wear safety glasses while programming.
Hi mackrackit, everyone.
I've been doing a lot of reading trying to figure out what's actually going within your Timer / Interrupt program. So here's my interpretation (he typed as he makes a fool of himself again).....!
Setting the Interrupt_Control pin.5 = 1 simply enables the Timer0 interrupt.Code:INTCON.5 = 1 'ENABLE TMR0
First of all you set the Global Interrupt Enable bit.7 =1.Code:OPTION_REG = %10000101 '16BIT 1:64 PRESCALE
Then bits 0 = 1 & bit 2 = 1 sets the PRESCALE value 1/64 of the system clock.
4MHZ or the instruction clock 1MHZ (not 100% sure on that one) This divided down figure is then sent to the TIMER0 register (incremented count from the prescaler).
When the count goes from FF(HEX) +1 (255 decimal,it over-runs back to zero).
So (wild assumption here) when the count overflows passed 255 the INTERRUPT occurs and the program jumps to the Label TLOOP. The LED blinks, then INTCON.2 pin is the reset to 0 and it does it all again.
So basically to my (small) mind the LED would blink every 1/64th of 1MHZ.
Anywhere warm on this one?
Dave
Last edited by LEDave; - 22nd March 2010 at 17:20.
Warm...
That is not setting a pin, it is setting bit#5 of the register.Setting the Interrupt_Control pin.5 = 1 simply enables the Timer0 interrupt.
Correct.When the count goes from FF(HEX) +1 (255 decimal,it over-runs back to zero).
Now for the tricky part.
Running with a 4MHz OSC the chip is actually running at 1MHz.. Or cycles at 1 micro second (ticks).
If the prescaler is set for 1:1 then it will overflow every 256 micro seconds.
If the prescaler is set for 1:2 then it will overflow every 512 micro seconds.
If the prescaler is set for 1:256 then it will overflow every 65536 micro seconds.
Dave
Always wear safety glasses while programming.
Hi there.
As ever can I start with a question:
The TIMER program. My reading of it is that with a prescaler of 1:64 the LED
attached to PORTD.4 would blink (toggle) every 16384 microseconds (pretty quick) And that because this is driven by the internal clock runs independently of any code enclosed within 'MAIN'. For example, you could have an LED set within MAIN to say PORTD.3 which would blink every 2 seconds whilst the LED on PORTD.4 would to all intents and purposes show permanently on (like you said a heartbeat indicator that all's running well).
Am I reading this right?
David
Hi Dave,
Yes, the LED would toggle every 16384uS, in other words it would blink at rougly 30.5Hz, youll be hard pressed to see that. If you change the prescaler to 1:256 you'll get 4000000/4/256/256/2 = 7.62Hz.
The problem with PBP's way of handling interrupts is that it can not interrupt the command/statement that it is currently executing. Lets say for example that your main routine looks something like this:This would blink a LED connected to GPIO.0 at 1Hz and you would think that the TMR0 interrupts would blink the other LED at 7.62Hz, unfortunatley that's not the case....Code:Main: GPIO.0=1 Pause 500 GPIO.0=0 Pause 500 Goto Main
In the above code the interrupts generated by TMR0 would only get served between each statement. In other words, during the 0.5 second pauses the 7.62Hz blink would stop.
Basically, what PBP does, under the hood, is to add check after each statement, like:As you can see, if an interrupt occurs in the middle of a Pause it won't get serviced until the Pause statement has finished so if you're using PBP's ON INTERRUPT you need be aware of this. There are other ways to do it which doesn't suffer from the issue described above (Darrels Instant Interrupt routines obviously).Code:Main: GPIO.0=1 IF Interrupt goto TLOOP 'This is not the actual code it adds, it's just to illustrate the principle Pause 500 IF Interrupt goto TLOOP GPIO.0=0 IF Interrupt goto TLOPP Pause 500 IF Interrupt goto TLOOP Goto Main IF Interrupt goto TLOOP
Hope it helps.
/Henrik.
Bookmarks