PIC Nixie Clock project


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    My latest working version of the code is posted below.
    It incorporates Darrell Taylor's Instant Interrupts modified by Tabsoft in this thread...
    http://www.picbasic.co.uk/forum/showthread.php?t=19910

    It incorporates a check for USA Daylight Saving Time

    I currently have commented out the temperature sensor code as I have not decided how/or if I am going to implement a temperature display.

    enjoy
    dwight

    Code:
    '****************************************************************
    '*  Name    : Nixie_DST_InstantInt.BAS                          *
    '*  Author  : [Dwight Merkley, N7KBC]                           *
    '*  Notice  : Copyright (c) 2016                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 3/10/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : 16F1828                                           *
    '*          :                                                   *
    '****************************************************************
    #CONFIG
        __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
        __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
    #endconfig
    
    
    ;--   Copied from DT_INTS-14 as per instruction in DT_INTS-14  -------------
    ;--   The compiler will tell you which lines to un-comment                --
    ;--   Do Not un-comment these lines                                       --
    ;---------------------------------------------------------------------------
    ;wsave   VAR BYTE    $20     SYSTEM      ' location for W if in bank0
    wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
                                             ' if using $70, comment wsave1-3
    
    ' --- IF any of these three lines cause an error ?? ------------------------
    '       Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using -- 
    ;wsave1  VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    ;wsave2  VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    ;wsave3  VAR BYTE    $1A0    SYSTEM      ' location for W if in bank3
    ' --------------------------------------------------------------------------
    
    
    define  OSC 8
    OSCCON  = %01110000   'set internal osc to 8 mhz
    include "ALLDIGITAL.Pbp"
    include "DT_INTS-14.bas"            'Needs to be in same PBP folder as PBPW.EXE 
    include "ReEnterPBP.bas"            'Needs to be in same PBP folder as PBPW.EXE
    include "ElapTimer_5ms_Interrupt.pbp"   'Needs to be in same PBP folder as PBPW.EXE
    '==================================================
    
    H10  VAR PortC.0    'hours tens digit enable
    H1   var PortC.1    'hours ones digit enable
    M10  var PortC.2    'minutes tens digit enable
    M1   var PortC.3    'minutes ones digit enable
    symbol PORT_PIN = PORTC  'used to sequentially enable portC.0-3 nixie tubes
    
    res  var PortC.4    '0-9 digit reset
    clk  var PortC.6    '0-9 digit counter input
    ena  var PortC.7    'ENA on nixie decade counter
    
    led  var LATC.5     'pwm led backlight
    sw1  var portA.2     'input upper switch
    sw2  var portA.1     'input lower corner switch
    swflg1 var bit        'bit used to debounce switch pushes
    swflg2 var bit        'bit used to debounce switch pushes
    
    ts   var portB.4     'OneWire Temperature sensor
    rxE  var portB.5     'input rx data from esp8266 
    txE  var portB.7     'tx data to esp8266
    fet  var portB.6     'High Voltage shutdown
    
    tube var byte       'refrence tube 0-3 [hh h mm m]
    'hh   var byte         'variable holding hours 
    h12  var byte
    'mm   var byte         'variable holding minutes 
    'ss   var byte         'variable holding seconds
    d1   var byte
    d2   var byte
    d3   var byte
    d4   var byte
    s1   var byte
    s0   var byte
    
    dow var byte       'sun = 0, sat = 6
    mth var byte       'Jan = 01 ... Dec = 12
    date var byte      'numerical day of month
    dst var bit
    
    mode var byte    '12 to 24 hour conversion flag'
    num  var byte    'current digit's pulse count
    x    var byte      'general purpose variable
    y    var byte      'counter to track time between esp serial request output
    dgt  var byte
    temp     var byte   'temporary lcd display data
    IntCnt   var word
    IntFlag  var bit
    dispflag var bit  'flag to indicate if display should be off
    temptime var byte 'var to determine if time to check temperature
    
    'the following var's are used in the anti-cathode poisoning routine
    posx var byte
    numx     var byte
    cath     var byte
    index    var byte
    CatCnt  var word
    CC  var bit
    '-------------[variables and constants for temperature routine]--------------
    ''DS18B20_9bit  CON %00011111   ' set resolution on DS18B20 93.75ms, 0.5 C
    ''DQ            VAR   PortB.4   ' One-wire Data-Pin "DQ" on PortB.4
    ''Busy          VAR BIT         ' Busy Status-Bit
    ''Raw           VAR   WORD      ' RAW Temperature readings
    ''TempF         VAR WORD        ' Temp in deg F
    ''Cold_Bit      VAR Raw.BIT11   ' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    ''Sign          VAR BYTE[1]     ' +/- sign for temp display
    ''TempH         var word        ' var for highest temp
    ''TempL         var word        ' var for lowest temp
    ''SignH         var byte[1]
    ''SignL         var byte[1]
    ''C             VAR WORD     ' Celsius 
    ''F             VAR WORD     ' Fahrenheit
    
    ''INCLUDE  "Temp_Convert.pbp"
    '===================================================
        TRISA = %00000110     
        TRISB = %00100000     
        TRISC = %00000000
        WPUA  = %00000110     
    '====================================================
    espbaud con 84
    Hours = 99
    Minutes = 00
    Seconds = 00
    mode = 2    'modes
                '0=24 hour only display
                '1=12 hour only display
                '2=24 hour with alternating 12 hour
                '     for dummies who don't know 24 hour time
    swflg1=0    'flag used to debounce sw1 press
    swflg2=0    'flag used to debounce sw1 press
    CC = 0
    numx=0
    IntCnt = 1
    temp = 0
    
    '================================================
    
    ' Define and Create the Instant Interrupt for Timer1
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
    
        INT_CREATE            ; Creates the interrupt processor
    
        INT_ENABLE  TMR1_INT  ; Enable Timer 1 Interrupts  
    ENDASM
    
    Gosub ResetTime           ' Reset Time to  0d-00:00:00.000
    Gosub StartTimer          ' Start the Elapsed Timer
    Hours = 99
    txe=1     'high the serial output pin, needs to start high
    pause 1000
    ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
    Main:
        if swflg1 = 1 and sw1=1 then swflg1 = 0  '(sw debounce) clear swflg when switch released
        if swflg1 = 0 and sw1=0 then   'sw1 button detected
            swflg1 = 1      
            mode=mode+1
            if mode = 3 then mode = 0
        endif 
        
        if sw2=0 then gosub gettime  'sw2 button detected
    
        'an interrupt is generated every .005 sec 
        'so clear the IntFlag and cycle to the next nixie tube
        if  MSecsChanged = 1 then
            MSecsChanged = 0
            catcnt = catcnt + 1 
            gosub Tubes
        endif
        iF SecondsChanged = 1 then
           SecondsChanged = 0
           gosub NextSec
        endif
            'this next routine fires every 15 minutes between 4 and 7 seconds
            'it causes all digits in each nixie to be cycled to prevent
            'cathode poisioning
        if (Hours !=99 and Minutes//15=0) and (Seconds >4 and Seconds<11) then
           cc=1
        else
           cc=0
        endif
        if catcnt>19 and cc=1 then gosub CatClean
        if cc=0 then catcnt=0
        
        'this next routine blanks the display between 2200 and 0600 
        if (Hours>21) or (Hours<6) then 'turn display off between 2200 and 0600
            dispflag = 0
            led=1   'turn off the LED backlight
        else 
            dispflag = 1
        endif
        
        'this routine only runs on startup and waits for 30 sec
        'then it goes and reads the time from the ESP module
        if  Hours = 99 then
            d1=Seconds//10
            d2=Seconds/10
            d3=0
            d4=0
            dispflag = 1
            if Seconds=40 then gosub GetTime 
        endif
        
        'this routine sets the clock once a day at 0500
        if Hours=5 and Minutes=0 and Seconds=0 then gosub GetTime 
        
        if dispflag =1 then toggle led   'for backlight brigtness at 50% 
                     ' can use O-Scope to determine Main loop timing
    goto Main
    '=============================================================
    '          increment seconds and trickle down time
    '=============================================================
    NextSec:
        if cc=1 then SkipSec
        gosub dstcalc
        if  Hours > 12 then 
            h12=Hours - 12
            else 
            h12 = Hours
        endif
        
        d1=Minutes//10
        d2=Minutes/10
        d3=Hours//10
        d4=Hours/10
        s1=Seconds/10
        s0=Seconds//10
        
        if mode=1 then      '12 hr only mode
           d3=h12//10
           d4=h12/10
        endif
        
        if mode = 2 and (s0=0 or s0=5) then  '24 hr mode with 
           d3=h12//10                        '12 hr overlay at 0 & 5 sec
           d4=h12/10
        endif
    SkipSec:
    Return 
    '=================================================
    '--- Routine to cycle all digits on all tubes  ---
    '--- to prevent cathode poisoning (look it up) ---
    '=================================================
    CatClean:
        catcnt=0
        if Hours=99 then
            d1=Minutes//10
            d2=Minutes/10
            goto SkipClean
        endif
        numx=numx + 1
        if numx >9 then numx=0   
        
        for posx=0 to 3
            index = numx + posx
            lookup index,[1,6,2,7,5,0,4,9,8,3,1,6,2,7,5,0,4,9,8,3],cath        
            if posx = 0 then d1=cath
            if posx = 1 then d2=cath
            if posx = 2 then d3=cath
            if posx = 3 then d4=cath       
        next posx   
    SkipClean:
    return
    '=============================================================
    '          display next NIXIE digit
    '=============================================================
    Tubes:
        PORT_PIN.0[tube] = 0        'Turn OFF the current tube
        if dispflag = 0 then Skipdisp
        
        tube=tube + 1
        if tube > 3  then tube = 0
    
    Digit:
        high res                'reset the decade counter
    @   nop
        low res                 'release the reset
        
        lookup2 tube,[d4,d3,d2,d1],num
        
        for x = 1 to num            'pulse the clock for "num" counts
            high clk                
    @       nop
            low clk
        next x
        PORT_PIN.0[tube] = 1    'Turn ON the next tube
    
    SkipDisp:
    return
    '=============================================================
    '          Get TIME from ESP8266-01 NTP Time Server
    '=============================================================
    SerTmout:
        led=0
        pause 200
        led=1
        pause 200
        led=0
        pause 200
        led=1
        pause 200
    GetTime:
    @   INT_DISABLE  TMR1_INT  ; Disable Timer 1 Interrupts  
        PORT_PIN.0[tube] = 0   'Turn OFF the current tube
                ' Wait for >,CR,LF from ESP module
        serin2  rxe,espbaud,2000,SerTmout,[wait(">"),wait(13),wait(10)]
                ' ESP module expects "Time?" before it will give hhmmss
                ' to change this modify the ESP code
        serout2 txe,espbaud,["Time?"]
        serin2 rxe,espbaud,3000,SerTmout,_
            [dec1 dow,wait("/"),dec2 mth,wait("/"),dec2 date,wait("/"),_
             dec2 Hours,dec2 Minutes,dec2 Seconds]   
                
    gosub dstcalc       'check to see if DST is in effect
    if dst=1 then Hours = Hours + 1
    if Hours = 24 then Hours = 00
                
        ' set NIXIE tube positions for their 
        ' respective h h m m, d4,d3,d2,d1 
        d4=Hours/10
        d3=Hours//10
        d2=Minutes/10
        d1=Minutes//10
        s1=Seconds/10  ' s0 & s1 only gets used when displaying seconds
        s0=Seconds//10 ' untill time retreval from ESP module at 30 sec
    @   INT_ENABLE  TMR1_INT  ; Enable Timer 1 Interrupts 
    
    Return
    '=============================================================
    '           Read Temp Sensor and convert to deg F
    '=============================================================
    ''GetTemp:
    ''    PORT_PIN.0[tube] = 0   'Turn OFF the current tube
    ''    OWOUT  DQ,%001,[$CC, $4E, 0, 0, DS18B20_9bit]  'set resolution of sensor
    ''Start_Convert:
    ''    OWOUT  DQ,%001,[$CC, $44]           ' Skip ROM search & do temp conversion
    
    ''Wait_Convert:
    ''    OWIN   DQ,%100,[Busy]               ' Read busy-bit
    ''    IF     Busy = 0 THEN Wait_Convert   ' Still busy..?, Wait_Convert..!
    ''    OWOUT  DQ,%001,[$CC, $BE]           ' Skip ROM search & read scratchpad memory
    ''    OWIN   DQ,%010,[Raw.byte0, Raw.byte1]' Read two bytes / end comms
    
    ''    '--------------  Convert_Temp: -----------------------
    ''    Sign="+"
    ''    IF Cold_Bit = 1 THEN                'it's below zero Celsius
    ''      C=(ABS Raw>>4)*-10                'so shift the ABS value right and mult X -10
    ''      ELSE
    ''      C=(Raw>>4)*10                     'else shift value right and mult X 10
    ''    ENDIF
    
    ''@   CtoF _C, _F            ; Convert Celsius to Fahrenheit
    ''        'converted value will be X 10, ie. 756=75.6 deg F
    ''        'so devide by 10 to get whole degrees
    ''    IF f.15=1 THEN Sign="-"         'if converted value is below zero F then sign is "-"
    ''    TempF = (ABS f)/10              'take tha ABS value and /10
    ''    IF f//10 >4 THEN TempF=TempF+1  'check remainder, if >4 then round up
    ''    PIR1.0 = 0                  ' clear timer1 overflow flag 
    ''return                              'with TempF containing current temperature
    '================================================
    '---  DST Calc (dec1 dow,dec2 mth,dec2 date)  ---
    '================================================
    dstcalc:
    '    if dayschanged = 1 then
    '       dayschanged = 0
    '       dow = dow+1
    '       if dow >7 then dow=0
    '    endif
    dst = 1      'covers Apr, May, Jun, Jul, Aug, Sep, Oct
    If mth=01 then dst = 0  'Jan
    If mth=02 then dst = 0  'Feb
    If mth=12 then dst = 0  'Dec
    
    March:
    if mth=03 then                                       'March
        if  date <8 then
            dst=0
            elseif (date>7 and date<15) and dow=1 and hours<2 then
            dst=0 
            elseif (date=8  and dow>1) then
            dst=0
            elseif (date=9  and dow>2) then
            dst=0
            elseif (date=10 and dow>3) then
            dst=0
            elseif (date=11 and dow>4) then
            dst=0
            elseif (date=12 and dow>5) then
            dst=0
            elseif (date=13 and dow>6) then
            dst=0
        endif
    endif
    
    November:
    if  mth=11 then                                  'November                                      
        if  date >7 then
            dst=0
            elseif (date <8 and dow=1) and hours>1  then
            dst=0               
            elseif (date=2 and dow<3) then
            dst=0
            elseif (date=3 and dow<4) then
            dst=0
            elseif (date=4 and dow<5) then
            dst=0
            elseif (date=5 and dow<6) then
            dst=0
            elseif (date=6 and dow<7) then
            dst=0
        endif
    endif
          
    return
    
    '===========================================
    end
    
    
    '===========================================================
    '---  This is the code running on the ESP8266-01 module  ---
    '===========================================================
    '''memclear
    '''cls
    '''timesetup(-7,0)
    '''baudrate 9600
    '''serialtimeout 2000
    '''delay 1000
    '''button "Exit" [Exit]
    '''timer 100 [PicSer]
    '''wait
    ''''
    '''[PicSer]
    '''serialflush
    '''input picin
    '''picin = mid(picin,1,5)
    '''if picin == "Time?" then gosub [gettime]
    '''wait
    ''''
    '''[gettime]
    '''bla = time()
    '''dy = mid(bla,1,3)  'dow
    '''mh = mid(bla,5,3)  'month
    '''dd = mid(bla,9,2)  'date
    '''hh = mid(bla,12,2) 'hour
    '''mm = mid(bla,15,2) 'min
    '''ss = mid(bla,18,2) 'sec
    '''yr = mid(bla,21,4) 'year
    ''''
    '''if dy == "Sun" then dow = "1/"
    '''if dy == "Mon" then dow = "2/"
    '''if dy == "Tue" then dow = "3/"
    '''if dy == "Wed" then dow = "4/"
    '''if dy == "Thu" then dow = "5/"
    '''if dy == "Fri" then dow = "6/"
    '''if dy == "Sat" then dow = "7/"
    ''''
    '''if mh == "Jan" then mth = "01/"
    '''if mh == "Feb" then mth = "02/"
    '''if mh == "Mar" then mth = "03/"
    '''if mh == "Apr" then mth = "04/"
    '''if mh == "May" then mth = "05/"
    '''if mh == "Jun" then mth = "06/"
    '''if mh == "Jul" then mth = "07/"
    '''if mh == "Aug" then mth = "08/"
    '''if mh == "Sep" then mth = "09/"
    '''if mh == "Oct" then mth = "10/"
    '''if mh == "Nov" then mth = "11/"
    '''if mh == "Dec" then mth = "12/"
    ''''
    '''picout = dow & mth
    '''picout = picout & dd
    '''picout = picout & "/"
    '''picout = picout & hh
    '''picout = picout & mm
    '''picout = picout & ss
    ''''
    '''serialprintln picout
    '''return
    ''''
    '''[Exit] 
    '''end
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    I forgot to mention that the new enhanced code that needs to be loaded on the ESP module is located at the bottom of the above posted PIC listing. It is commented out so it doesn't interfere with the PIC code.
    This new ESP code provides more NTP time data to the PIC. It now sends day of week, month and day of month, along with the HH:MM:SS

    The pic code used the date information to determine if daylight saving time needs to be in effect.

    Due to drift in the internal osc in the 16f1828 you may want to check NTP time more than once a day.
    It seems to drift about 2 minutes in 24 hours so checking the time 2-3 times a day (or even once an hour) would insure your clock is more accurate.

    cheers
    dwight

    PS if you decide to build one of these please let me know before you order your boards from oshpark as I would be willing to upload a new board design that incorporates a couple of improvements. The boards work fine as is but I found that I overdesigned it to try and turn off the high voltage to blank the display and it is much easier to do that in software by just not turning on any digits.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    Well done Dwight!

    A very interesting project, combining old tech with the latest IoT.

    Ioannis

  4. #4
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    Thanks Ioannis!!

    It really is a good looking clock and nice to look at sitting on the book shelf.
    And the fact that it sets itself and I can modify the code to my hearts content is all the better.

    My wife commented that she missed it while I was developing the code.
    It really is, in my opinion, a good value for the $50 USD including the case.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

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


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    Dwight, I took your DST segment from the PIC code and incorporated it into the ESP8266-01. I am running the version 3.0 ESPBASIC on the ESP8266 and it works flawlessly. I have incorporated it into my version of the Nixie Clock build. I made a few and gave the kits to 2 of my kids for Xmas. Attached are the pics and ESP code.
    Attached Images Attached Images     
    Attached Files Attached Files
    Dave Purola,
    N8NTA
    EN82fn

  6. #6
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    That's awesome Dave!!

    I am glad you could use the code. It was fun (mental challenge) to figure out how to determine DST.
    Although I did notice that this past Nov my clock did not change to Std Time until the day after it should have (as I recall) I was busy at the time and did not (have not) investigated why. I still need to look into the code and see if I missed something by a day. It did get it right the next day so I did not get too concerned.

    I chose to do all the DST calcs in my PIC code as I am much more familiar with PIC BASIC. But the espBASIC has come a long way since then. I am still running version 1.65 on my esp module so I'll have to update the code to be compatible with the newer 3.xx versions.

    It is amazing how powerful the little esp-01 modules are!!

    73
    dwight
    N7KBC
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    Hi, Nice idea to get rid of the chip that you don’t want and replace with your own board
    If the ESP module getting the time, then the DT elapsed timer is really just cycling through the tubes?

    On EEVblog, a YouTube channel if you watch it, Dave is in the middle of a nixie project now I’ve been watching.

Similar Threads

  1. Color GLCD Project, Analog clock
    By DaveC3 in forum Code Examples
    Replies: 5
    Last Post: - 14th May 2011, 04:24
  2. pic16f887 clock project, need help
    By lockjawz in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 13th April 2011, 12:45
  3. Digital clock project
    By astouffer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th February 2009, 04:00
  4. Help with PIC project
    By davekav in forum General
    Replies: 3
    Last Post: - 18th April 2008, 00:15
  5. pic project help
    By dizzy1 in forum General
    Replies: 2
    Last Post: - 5th February 2006, 19:30

Members who have read this thread : 4

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