RTC & timer1 help required.


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2006
    Posts
    32

    Question RTC & timer1 help required.

    Hi guys,

    Im working on a high power LED lighting unit and using a RTC (PC8583) proto board kindly lent to me by Malc_c and basically this is what im trying to do (bear with me!):

    Pic used: 18F2455 as use USB functionality (not related to the current problem)

    In controlling the LED's I am having them fade in and out (ie dawn to dusk) and in the program, I take the time I have set for the fade in duration and depending upon the start and end intensity of the LED's I calculate the delay in seconds and milliseconds for the delay inbetween adding 1 to the PWM value, so that over the space of eg. 2 hours , it pauses for 37.69 seconds between each PWM increase based on a PWM end value of 191 starting at 0.
    So as you can see to get good time keeping so that the fade keeps as close as possible to the set fade in time I use milliseconds.

    I have set a timer1 interupt (using DT's excellent instant interupt includes etc) and set it to prescale 1:1 (ie T1CON %00000001) and all I have in the interupt is a simple counter that adds ticks, and when they reach >180 it resets to 0 and adds one to a counter.
    Now this is where the problem lies, as displaying the counter that is incremented in the timer when it goes over 180 on an LCD above the seconds from the RTC it 'seems' to keep in time with the seconds, but over time you can see that the increase goes out of sync with the RTC seconds, and ive fiddled with the 180 either way and can see the differences, but just cant seem to lock it in so its bang on with the RTC seconds counter on the LCD

    Anyone know why it might be going out of sync as I thought that things were pretty constant regarding timing (using a 4Mhz xtal btw)

    Can post code bits if needed, just thought id put a 'small'? lol post asking if anyone could throw some light onto my problem if possible.

    Many thanks.

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    It's hard to say what's happening without seeing the code.

    Keep in mind that crystals do not keep perfect time. They have a rated accuracy - usually in ppm (parts per million). They are also prone to changing frequency with temperature and time.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3
    Join Date
    Dec 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Yeah I had thought about the crystals etc, and decided I didn't need to be quite so picky on the timing etc, so decided to simply round up or down the results which keeps the times within acceptable timing etc, as was speaking to Malc_c and realised I was been too an@l LOL!!!

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts