+ Reply to Thread
Results 1 to 9 of 9

Thread: Code using TIMER0 runs at different speeds

  1. #1
    David / W9GF Good David / W9GF Good
    Join Date
    Apr 2008
    Location
    Dallas, Texas
    Posts
    17

    Default Code using TIMER0 runs at different speeds

    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


  2. #2
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,705
    Blog Entries
    5

    Default

    Can you post the code?
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  3. #3
    David / W9GF Good David / W9GF Good
    Join Date
    Apr 2008
    Location
    Dallas, Texas
    Posts
    17

    Default Code is attached

    please see attached file.
    Attached Files

  4. #4
    Super Moderator Jay.slovak Good Jay.slovak Good Jay.slovak Good
    Join Date
    Jan 2005
    Location
    Slovakia
    Posts
    1,740

    Default

    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).

  5. #5
    David / W9GF Good David / W9GF Good
    Join Date
    Apr 2008
    Location
    Dallas, Texas
    Posts
    17

    Default

    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

  6. #6
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    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.

  7. #7
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

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

    Mike.

  8. #8
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,705
    Blog Entries
    5

    Default

    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.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  9. #9
    David / W9GF Good David / W9GF Good
    Join Date
    Apr 2008
    Location
    Dallas, Texas
    Posts
    17

    Default

    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
    Attached Files

+ Reply to Thread

Similar Threads

  1. MP Lab Program Help
    By bamafan54 in forum Micro Controllers
    Replies: 5
    Latest: 7th January 2009, 02:16 PM
  2. Timer0 Prescale
    By lord loh. in forum Micro Controllers
    Replies: 10
    Latest: 8th October 2008, 05:14 PM
  3. TIMER0 - Have I got this right?
    By UTMonkey in forum Micro Controllers
    Replies: 8
    Latest: 14th December 2007, 10:08 PM
  4. Tough assembly program for the PIC16F84
    By asmpic in forum Micro Controllers
    Replies: 34
    Latest: 3rd December 2004, 06:50 PM
  5. An error in pic16f84a, why?
    By Zener_Diode in forum Micro Controllers
    Replies: 6
    Latest: 11th April 2004, 02:55 AM

Tags for this Thread