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

    Default PIC Nixie Clock project

    Hey Group,

    I am designing an adapter board to allow a 20 pin pic (like a 16F690 or 16F1828, etc) to take the place of an MSP430 processor. Why?? You might ask.

    Well I bought one of these...Name:  clock.jpg
Views: 3372
Size:  59.1 KB

    from here... https://www.tindie.com/products/RobG...xie-clock-kit/ and want to modify the way it works. Unfortunately, for me, it is controlled by an TI MSP430 processor and coded in C.

    The clock is (I believe) an outstanding value as far as nixie clocks go. ($50 usd) which includes the NIXIE tubes and optional case.
    I have actually purchased 2 additional clocks, 3 total. One for my son to build. Then my daughter liked it so much that I told her if she would put it together then I would get her one for Christmas.

    Though the clock is quite a beautiful piece it is lacking in some features that I wanted.

    Self setting time from NTP time source.
    Able to blank the display during certain hours as the clock is in my bedroom and quite bright at night.
    Able to blank the display when not at home to extend life of the nixie's.
    Able to alternately display indoor/outdoor temperature.
    (Add your own feature here...you are the programmer)

    So I designed this... Name:  PCB.jpg
Views: 3141
Size:  36.4 KB

    Based on this schematic...Name:  Schematic.jpg
Views: 3867
Size:  79.0 KB

    Which includes one of these... Name:  ESP01.jpg
Views: 2753
Size:  11.3 KB

    The adapter PCB has a spot for a ds18b20 to provide indoor room temperature.
    There is a couple of extra I/O pins to allow you to remotely recieve outdoor temperature if desired.
    Will be able to get NTP time via the ESP wifi module and auto set the clock and keep accurate time.
    Will have a web interface, also via the ESP, to allow you to choose hours of display on/off and easily change other parameters.
    Includes a PICKIT programming header to allow firmware updates easily.

    And will be coded in our favorite PBP BASIC so it will be easy to customize.
    The little 1.5" x 1.5" board is an adapter that will plug into the socket for the MSP430 and fit nicely inside the case.

    So if you are interested in joining in and having some fun and ending up with a nice little nixie clock... well... stay tuned. Or better yet get your clock on order! (be sure to get the optional case) assuming you want it.

    I am not associated with the maker of the tindie clock kit just a satisfied customer.

    I'd be happy to share my code and you can order your own adapter board from oshpark (3 for $12)

    Here is another link to someones webpage reviewing the clock kit... http://maniacallabs.com/2015/03/11/m...-clock-by-rob/

    I have not yet received the adapter PCB from Oshpark, so at this time it's untested. I'll post back here when I get it and assuming no errors, etc. Here is the link to the adapter board... https://oshpark.com/shared_projects/VGYjILPE

    What do you all think??
    Last edited by Heckler; - 3rd January 2016 at 19:13.
    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

    Hey Group (again),

    I have a pretty decent beta version of the code up and running.
    My clock will now...
    > auto set the time via wifi from the esp module (ntp time source) on initial power up
    and every day at 0500
    > blanks the display between 2200 and 0600
    > cycle through all nixie digits to prevent cathode poisioning (every 15 minutes for 5 sec)
    probably overkill but it looks cool
    > you can choose 12 hr, 24 hr or a mode where the hours alternate between 12/24 hr
    for those who can't read 24 hr time but want to learn
    > can display room temperature (but I haven't actually added this to the code yet)

    here are some pics...
    Name:  2016-02-14 17.08.21.jpg
Views: 2655
Size:  104.9 KB

    Name:  2016-02-14 17.08.47.jpg
Views: 2676
Size:  82.3 KB

    Name:  2016-02-14 17.09.48.jpg
Views: 2680
Size:  79.8 KB

    Name:  2016-02-14 17.10.06.jpg
Views: 2685
Size:  157.2 KB

    Name:  2016-02-14 17.06.23.jpg
Views: 2632
Size:  224.7 KB

    Name:  2016-02-14 17.10.56.jpg
Views: 2714
Size:  216.7 KB

    here is my beta version of the code...
    It runs on an 16F1828 or 16F1829 and with minor mods will run on an 16f690
    Code:
    '****************************************************************
    '*  Name    : MSP to PIC Nixie clock.BAS                        *              *
    '*  Author  : [Dwight Merkley]                                  *
    '*  Notice  : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 1/2/2016                                          *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    #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
    
    DEFINE OSC 8
    include "ALLDIGITAL.Pbp"
    '==================================================
    
    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
    swflg 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
    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
    position var byte
    numx     var byte
    cath     var byte
    index    var byte
    '-------------[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     
      OSCCON  = %01110000   'set internal osc to 8 mhz
    '====================================================
    espbaud con 84
    hh = 99
    mm = 00
    ss = 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
    
    IntCnt = 0
    temp = 0
    
    ' -----[ Timer setup ]------------------------------
    disable interrupt
    On Interrupt goto MyInt    'define where interrupts should go
    INTCON     = %11000000     'now enable GIE,PEIE,x,x,GPIE,x,x,x
    T1CON =  %00110101 'Enable Timer1 with 1:8 prescaler
    PIE1  =  %00000001 'Enable Timer1 overflow interrupt
    PIE2  =  %00000000
    PIR1.0=0 'clear the timer1 interupt flag
    txe=1     'high the serial output pin, needs to start high
    
    '***************************************************
    '========            MAIN                ===========
    '***************************************************
    Enable Interrupt
    
    Main:
    if swflg = 1 and sw1=1 then swflg = 0  '(sw debounce) clear swflg when switch released
    
    if swflg = 0 and sw1=0 then 
        swflg = 1
        if mode = 0 then
            mode = 1  'switch to 12 hr mode
            goto SkipSw
        endif
        if mode = 1 then
            mode = 2  'switch to 24 hrr mode with 12 hr flash
            goto SkipSw
        endif
        if mode = 2 then 
            mode = 0  'switch to 24 hr mode
        endif
    endif 
    SkipSw:    
    
    'an interrupt is generated every .005 sec 
    'so clear the IntFlag and cycle to the next nixie tube
    if  IntFlag=1 then
        IntFlag=0
        IntCnt = IntCnt + 1
        gosub Tubes
    endif
    
    if  IntCnt > 199 then gosub NextSec 'time to increment seconds
    
    'this next routine fires every 15 minutes between 55 and 58 seconds
    'it causes all digits in each nixie to be cycled to prevent
    'cathode poisioning
    if mm//15=0 and (ss >54 and ss<58) then
        if intcnt//10 = 0 then gosub NixieBurn
    endif
    
    'this routine blanks the display between 2200 and 0600 
    if (hh>21) or (hh<6) then 'turn display off between 2200 and 0600
        dispflag = 0
    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 hh = 99 then
        d1=s0
        d2=s1
        dispflag = 1
        if ss=30 then gosub GetTime
    endif
    
    'this routine sets the clock once a day at 0500
    if hh=5 and mm=0 and ss=0 then gosub GetTime 
    
    toggle led   'for backlight brigtness at 50% 
                 ' use O-Scope to determine Main loop timing
    goto Main
    
    '***************************************************
    '  interrupt every 5 msec
    '***************************************************
    disable interrupt
    MyInt:
        IntFlag=1    ' INT has fired so set this flag for Main code usage
        '>H & L size determine INT timing, INT every .005 seconds
        TMR1H = $FB  ' reset timer1h   
        TMR1L = $1F  ' reset timer1l   
        PIR1.0 = 0   ' clear timer1 overflow flag 
    resume    'to Main
    enable interrupt
    '=============================================================
    '          increment seconds and trickle down time
    '=============================================================
    NextSec:
    intCnt = 0
    ss = ss +1
    if  ss = 60 then 
        ss = 00
        mm = mm + 1
    endif
    if  mm = 60 then
        mm = 0
        hh = hh + 1
    endif
    if  hh = 24 then
        hh = 0 
    endif
    
    if hh>12 then 
        h12=hh-12
        else 
        h12=hh
    endif
            
    d1=mm//10
    d2=mm/10
    d3=hh//10
    d4=hh/10
    s1=ss/10
    s0=ss//10
    if mode=1 then      '12 hr only mode
        d3=h12//10
        d4=h12/10
    endif
    
    'this routine causes the display to alternate between 24 and 12 hr display 
    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
    
    return
    '=================================================
    '--- Routine to cycle all digits on all tubes  ---
    '--- to prevent cathode poisoning (look it up) ---
    '=================================================
    NixieBurn:
    numx=numx+1
    if numx=10 then numx=0    
    for position=0 to 3
        index=numx+position
        if index>9 then
           index=index-10
        endif
        lookup2 index,[1,6,2,7,5,0,4,9,8,3],cath        
        if position = 0 then d1=cath
        if position = 1 then d2=cath
        if position = 2 then d3=cath
        if position = 3 then d4=cath       
    next position    
    return
    '=============================================================
    '          display next NIXIE digit
    '=============================================================
    Tubes:
    PORT_PIN.0[tube] = 0        'Turn OFF the current tube
    if dispflag = 0 then 
        led = 1
        return                  'display is off so skip tubes
    endif
    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
    return
    '=============================================================
    '          Get TIME from ESP8266-01 NTP Time Server
    '=============================================================
    Disable Interrupt
    SerTmout:
        led=0
        pause 200
        led=1
        pause 200
        led=0
        pause 200
        led=1
        pause 200
    GetTime:
        PORT_PIN.0[tube] = 0   'Turn OFF the current tube
                ' Wait for >,CR,LF from ESP module
        serin2  rxe,espbaud,3000,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,[dec2 hh,dec2 mm, dec2 ss]
                ' set NIXIE tube positions for their 
                ' respective h h m m, d4,d3,d2,d1 
        d4=hh/10
        d3=hh//10
        d2=mm/10
        d1=mm//10
        s1=ss/10  ' s0 & s1 only gets used when displaying seconds
        s0=ss//10 ' untill time retreval from ESP module at 30 sec
    Return
    Enable Interrupt
    '=============================================================
    '           Read Temp Sensor and convert to deg F
    '=============================================================
    disable interrupt
    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
    enable interrupt
    
    '===========================================
    end
    and here is the code that runs on the ESP8266-01 module

    Code:
    memclear
    cls
    timesetup(-7,0)
    baudrate 9600
    serialtimeout 2000
    delay 1000
    button "Exit " [Exit]
    [Main]
    timer 100 [PicSer]
    wait
    '
    [PicSer]
    serialflush
    input picIN
    picIN = mid(picIN,1,5)
    if picIN == "Time?" then gosub [gettime]
    wait
    '
    [gettime]
    bla = time()
    hh = mid(bla,12,2) 'hour
    mm = mid(bla,15,2) 'min
    ss = mid(bla,18,2) 'sec
    '
    picOUT = hh & mm
    picOUT = picOUT & ss
    serialprint picOUT
    '
    return
    '
    [Exit] 
    end
    this has been fun and a real challenge
    IF anyone would like to build one let me know and I'd be glad to help you out with parts procurement, etc for the little adapter board.
    Last edited by Heckler; - 15th February 2016 at 01:07.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    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.

  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

    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.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    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

  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

    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.

  7. #7
    Join Date
    Mar 2020
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    Quote Originally Posted by Heckler View Post
    IF anyone would like to build one let me know and I'd be glad to help you out with parts procurement, etc for the little adapter board.
    I know this is an old-ish thread, so being a little late to the game I'm hoping I can re-ignite the conversation here.

    I came across this thread whilst searching for some way to automate the time setting of this clock. Great Job! This is a very interesting addition to this already really great Nixie clock.

    Dwight, I'd be interested in the offer of support for helping to procure parts and the newer board design if that's still something you're willing to help with?

    TIA
    Dave

  8. #8
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    I have complete Nixie clock project, written in Picbasic pro, you can find it on instructables "Mid century modern nixie clock". I've updated it to DS3231, added alarm and some other functions (updated code not yet uploaded to instructables), so if anyone can help with hooking ESP to it, I'd be very glad.

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


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    Hi Curious One,

    WOW! that clock on Instructables is an absolute work of art! I'm jealous.

    So what do you need help with as far as connecting an ESP8266??

    If you look at the beginning of this thread you will find the schematic and code for both the esp module and the PIC.
    (Although today, I would highly recommend you use ANNEX RDS as the language for the esp module so you would need to change my espBASIC code.)
    I'd be happy to help you with that code when you are ready.

    It really is just as simple as setting up a serial comm channel between the PIC and the esp module.

    I'd suggest, if you haven't already, that you join the ANNEX RDS group found here...
    https://sites.google.com/site/annexwifi/home
    where you will find a load of information on the ANNEX operating system. (it is very similar to the older espBASIC but much more advanced and development is very active)

    how can I help?

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

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


    Did you find this post helpful? Yes | No

    Default Re: PIC Nixie Clock project

    MrTeaTime,

    Do you have the same nixie clock as shown in the original post in this thread?
    If so then it is an easy conversion.

    So the boards are available to order on OSHPARK here...
    https://oshpark.com/shared_projects/7fvrYPyd

    you would only need a few extra parts to complete the project.

    what can I help you with?

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

Similar Threads

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

Members who have read this thread : 2

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