Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Code using TIMER0 runs at different speeds

Status
Not open for further replies.

David / W9GF

New Member
I'm hoping this is just something stupid i've done to myself.

I have some code that calls a delay routine, the delay routine uses TIMER0(not in interrupt mode - but burning in a loop waiting for a period of time to expire).

I have some delays that wait for about 3 seconds.

When i compile & run these (in Release Mode) under MPLAB then send to the target (18F4550) the Delays are reasonably close to what i expect.

But when I completely remove MPLAB from the picture and send the .hex file (that has been compiled in Release mode) to the target with Junebug or PICKit2 then run the code on the target the delay's suddenly are 2 or 3 times as long.

What do i need to do (or not do) to make the code run the same without MPLab as it does with MPLAB?

Thanks,
David
 
Are the configuration bits (oscillator selection) embedded in the hex file? You might be running on internal oscillator instead of external crystal (if that is the case).
 
Jay,
Can you 'dumb that down' for me a bit - i'm in my 2nd week of PIC programming - where do i find that? Is it in the code or somewhere else?

Thanks,
David
 
I have had problems getting the release version of my code working with PK2 and MPLAB. If I compile and program the release version with PK2 as debugger it doesn't work. If I then program the same hex file with the stand alone PK2 software it works fine. This may have been fixed in the latest release (8.02), I haven't checked.

BTW, Delay(3000) will give a delay of 4.8 second which is roughly half way between the values. Why not load TMR0L with 100 to get a delay of (256-100)*0.2*32= 998 uS.

Mike.
 
Just checked and the problem still exist in the latest release. If you select the PK2 as programmer it works fine.

Mike.
 
I found a bug once with the W register and the 18F1320 in debug, posted it on the Microchip forum and the PICkit2 Developer sent me a fix in about an hour.
 
There was this in the initialization code:

OSCCONbits.IOFS = TRUE; // use internal oscillator 31.25khz internal clock

Looked like something dinking with the oscillator (this was in someone else's code i 'borrowed' :p)

So - I removed it and both of my LCD's continued to work fine - then i tried it with and without MPLAP connected (physically) and got about the same times for each.

I'll upload my .c source file and an 8 bit and a 4 bit hex file if you want to have a look see.

Good catch on the timer being out of whack Pommie - i should have looked closer at my timer0 spreadsheet!

It should be dead on .001 seconds now - if i calcu-mu-lated that stuff correctly (My spreadsheet is in the attached .zip also).

Looks good on my $6 Wally World digital watch. And both LCD's work fine - so i'm good to go i'm thinking.

Thanks to all for their input & help - a couple more of these and maybe i can pick up the training wheels 1/32" or so :p
 

Attachments

  • W9GF.Unicorn.LCD.14Apr08.zip
    23 KB · Views: 105
Status
Not open for further replies.

Latest threads

Back
Top