Bug in my timekeeping code


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Bug in my timekeeping code

    I also see the same mistake in the 24 hour mode where you say if hour = 25 then hour = 1. 24 hour time starts from 00:00 to 23:59.

    BTW, Nice PCB. I have some RCA Numitrons with 9 pin sockets. I was thinking about using them for a clock but the lifetime of the tubes isn't very good so I built a couple of nixie clocks with VM1000 tubes. Attacked is a photo.

    Dave Purola,
    Attached Images Attached Images   
    Last edited by Dave; - 27th February 2014 at 12:29.
    Dave Purola,
    N8NTA
    EN82fn

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Bug in my timekeeping code

    I am wondering if it would be easier to keep only a TotalElapsedSeconds count and calculate HRS, MNS, and SDS as needed? I admit that I have not tried this, but it seems feasible. A word variable easily holds 13 hours (in seconds) and AM/PM or 24 hour clock flag provides convenient flags to indicate the 12 hour adjustment needed to avoid rollover (subtract 43200 at 46800). so:

    Just a little while after midnight (when the counter and flag resets to zero), TotalElapsedSeconds might be, say... 1146. In that case,

    HRS= 1146/ 3600 = 0
    MNS= 1146 - (HRS * 3600) / 60 = 19
    SCS= 1146- (HRS * 3600) - (MN * 60) = 06 - the time 00:19:06, is correct.

    Closer to noon, the total might be 43321.
    HRS= (43321/ 3600) = 12
    MNS= 43321- (HRS * 3600) / 60 = 02
    SCS= 43321- (HRS * 3600) - (MN * 60) = 01 - the time 12:02:01, is correct.

    At 1:00, the timer would be 46800 and subtracting 12 hours (43200 seconds) leaves TotalElapsedSeconds = 3600, or exactly 1:00:00 (or by adding 12, 13:00 in 24H mode). The caveat here is that the midnight adjustment and the 1:PM adjustment are not symmetric at 12 hours each - something of a kludge or, perhaps the time as 24:00:01 is of no issue to you? If not, then the time may rollover to 1:00:00 in even 12 hour cycles.

    To set the time, adding or subtracting 3600 adjusts the time by an hour, similarly adding or subtracting 60 changes the time a minute.

    I have considered this approach as a means of simplifying clock adjustments - say a user wants to subtract 10 minutes at only 5 minutes past the hour - in this way (I think) it may be simpler than fiddling with decrementing the hour separately.

  3. #3
    Join Date
    Nov 2008
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: Bug in my timekeeping code

    Quote Originally Posted by Dave View Post
    I also see the same mistake in the 24 hour mode where you say if hour = 25 then hour = 1. 24 hour time starts from 00:00 to 23:59.

    BTW, Nice PCB. I have some RCA Numitrons with 9 pin sockets. I was thinking about using them for a clock but the lifetime of the tubes isn't very good so I built a couple of nixie clocks with VM1000 tubes. Attacked is a photo.

    Dave Purola,
    Dave, nice looking clock as well. The boards came from a place called OSH Park. They run batches of boards so the average time is about two weeks but the quality and price is great. Purple boards seem to be their trademark. If you are worried about longevity of the numitrons you can use the TLC5916 or similar chips from TI. They are meant for driving LEDs and have an adjustable constant current feature. For some reason the minute digits were both dimmer than the hours and needed slightly different resistor values.

  4. #4
    Join Date
    Nov 2008
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: Bug in my timekeeping code

    Forgive my ignorance but I can not see why during the timekeep loop that the minutes increment to 01 if they are set to 00 from the previous loop

    Code:
    timekeep:							
    ss = ss + 1							
    if ss = 60 then
    	ss = 0 
     	mm = mm + 1
    endif
    if mm = 60 then 
    	mm = 0
    	hh = hh + 1
    endif
    if hh = 13 then hh = 1				
    v1 = hh DIG 1
    v2 = hh DIG 0
    
    v3 = mm DIG 1
    v4 = mm DIG 0
    
    if hh < 10 then
    lookup v1, [$00,$60,$57,$76,$6C,$3E,$3F,$70,$7F,$7E], v1
    else
    lookup v1, [$7B,$60,$57,$76,$6C,$3E,$3F,$70,$7F,$7E], v1
    endif
    
    lookup v2, [$7B,$60,$57,$76,$6C,$3E,$3F,$70,$7F,$7E], v2
    lookup v3, [$7B,$60,$57,$76,$6C,$3E,$3F,$70,$7F,$7E], v3
    lookup v4, [$7B,$60,$57,$76,$6C,$3E,$3F,$70,$7F,$7E], v4
    
    shiftout dat, clk, 0, [v2, v1]
    pulsout hstro, 10
    shiftout dat, clk, 0, [v4, v3]
    pulsout mstro, 10
    
    INTCON.2 = 0						'Clear interrupt flag
    resume startloop					'Go back to the do nothing loop
    Looking at this statement

    Code:
    ss = ss + 1							
    if ss = 60 then
    	ss = 0 
     	mm = mm + 1
    endif
    The minutes should be at 00 until 60 seconds have been counted. Why is it jumping to 01 instead?

  5. #5
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Bug in my timekeeping code

    The only other place I see you modifying the mm value is in the "setmm:" routine. You do not say if you are setting the clock (where the code in your OP sets mm = 1) or not.

Similar Threads

  1. FOR..NEXT Loop Bug?
    By MSapper in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th April 2011, 01:04
  2. Bug or something else
    By pedja089 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 7th February 2011, 14:58
  3. Did I find a bug or bug found me?
    By sayzer in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th September 2008, 09:58
  4. PBP bug ???
    By boban in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th March 2008, 16:30

Members who have read this thread : 0

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