Menu

Getting TM1628 (as opposed to TM1637) LED Driver to work by modifying the tm1637_d.h

Help
2022-09-05
2022-09-13
  • Jeff Weinmann

    Jeff Weinmann - 2022-09-05

    Hello,

    I just got a hold of an LED Clock that is driven by the TM1628 LED driver chip.

    The clock board is VERY inaccurate. It looses about 15 to 20 seconds per day and find I have to adjust it after only a couple of weeks.

    My plan is to program a PIC to use GPS time for accuracy. The PIC to GPS code has already been figured out and all I have to do is drive the LED display.

    The cpu board that came with the clock is completely separate from the LED driver board. The two boards are connected by a convenient 5 pin ribbon cable with the following connections:

    VCC ------> 5V (3.3V min)
    GND------> GND
    STB -------> Strobe (main difference between TM1628 and TM1637)
    CLK -------> Clock
    DIO -------> Data

    It seems the only difference is the Strobe pin, being set to low before the write, then set back to high:

    void Write1638(unsigned char Data)
    {
      unsigned char i;
      for(i=0 ; i<8 ; i++)
      {
        DI = (Data & 0x01);
        CLK = 0;
        Data >>= 1;
        CLK = 1;
      }
    }
    
    void WriteCmd(unsigned char cmd)
    {
      STB = 0;
      Write1638(cmd);
      STB = 1;
    }
    

    Has anyone used the GCB and modified it for use with the STROBE PIN?

    Here is my attempt at adding the Strobe :

    #CHIP PIC18F16Q40
    #CONFIG LVP=ON
    #option explicit
    
    #include <tm1637_6d.h>
    
    #define TM1637_CLK PortB.5
    #define TM1637_DIO PortB.4
    
    #Define STROBE LATB.6
    Dir PortB.6 Out
    
    
    
    
    MainLoop:
    STROBE = 1
    Wait 3 sec
    
    STROBE = 0
    TMWrite6Dig (17, 16, 17, 16, 0,15,0) 'clear display
    STROBE = 1
    
    Wait 2 sec
    
    STROBE = 0
    TMWrite6Dig (17, 16, 17, 16, 10,0) '- -
    STROBE = 1
    
    goto MainLoop:
    

    Here is a note I found on the used of the STROBE pin:

    The strobe pin is used when sending data to the board – you set the strobe pin to LOW before you start sending data – one or more bytes – and then set the strobe pin back to HIGH.

    thanks

    Jeff

     

    Last edit: Jeff Weinmann 2022-09-05
    • Jeff Weinmann

      Jeff Weinmann - 2022-09-07

      Ok Another few days of staring at Datasheets and tinkering. I got the TM1628 to work, but it has a totally different mapping scheme the GCB and any existing library out there (Ardino) will not work.

      Here is my first pass at getting a functional program working. I may plan a pcb board of my own with a button to change the hour to +- daylight savings / Time zone adjustment. Right now its hard coded for Eastern Standard time so i will have to modify in a few weeks.

      It wasn't fun trying to get LEDs to light up. The project WAS fun once the pretty lights started flickering!

      The GPS module is what makes this thing 'tick'. Once a GPS fix is attained very accurate times can be extracted from the GPS reports.

      If anyone has a better method of converting UTC 24 hour time to Eastern (or any timezone) 12 hour time let me know. My brain cells ran out so I brute forced it.

      Thanks for reading !

      Jeff

       
      • Jeff Weinmann

        Jeff Weinmann - 2022-09-08

        For anyone who may find this useful:

        This code will save me a button for adjusting for Daylight Savings Time in my area.

        Most of the US observes Daylight Savings Time. It Starts Nov 6th and Ends March 13th. My UTC offset is -4 hours, so I convert this offset for my area, which is Eastern Standard Time. The conversion handles crossing over into the next day. So at 8pm my time Greenwich is at 12:am, or 00:00:00

        So I derive the UTC time from the GPS sentence, and check to see if the current month/day timespan is within DST. If it is, I subtract 1 hour from UTC, so now I'm 5 hours behind. This is the code that handles DST:

         'Get the time by finding 1st comma
             get_val("R","M","C",1)    
        
             Hour = Val(Mid(DataStr,1,2))
             Minute = Val(Mid(DataStr,3,2))
             Second = Val(Mid(DataStr,5,2))
        
             'Get Date.  Find the 9th comma in the string
             get_val("R","M","C",9)
        
             Day = Val(Mid(DataStr,1,2))
             Month = Val(Mid(DataStr,3,2))
             Year = Val(Mid(DataStr,5,2))
        
             Select Case Month
                Case 12
                  'December Fall back
                  If Hour > 0 then
                    Hour = Hour - 1
                  else
                    Hour = 23
                  end if
        
                Case 1
                  'January Fall back
                  If Hour > 0 then
                    Hour = Hour - 1
                  else
                    Hour = 23
                  end if
        
                Case 2
                  'February Fall back
                  If Hour > 0 then
                    Hour = Hour - 1
                  else
                    Hour = 23
                  end if
        
                Case 3
                  If Day < 13 then 'DST Ends on March 13
                    'Fall back
                    If Hour > 0 then
                      Hour = Hour - 1
                    else
                      Hour = 23
                    end if
                  end if
        
                case 11
                  if Day >= 6 then 'DST Starts on Nov 6
                    'Fall back
                    If Hour > 0 then
                      Hour = Hour - 1
                    else
                      Hour = 23
                    end if
                  end if
        
             end select
        
         
  • ToniG

    ToniG - 2022-09-10

    Hello Jeff, probably a bit late now you have the display lit up.
    I am almost finished a new TM1638_OEM_Lib cloned from TM1637_OEM_Lib. (still in alpha/beta)
    Its all working except for some of the subs with ComAnode display.
    The Fixed address mode of the TM1628 looks the same as TM1638.
    Anyway, I have attached a test program (its a simple clock), i just pulled a few subs from the TM1638 lib, it was quite easy as it has a very modular structure.
    cheers

    Toni.G

    Buffer send sub...

    Sub tmSndBuf (Optional In Dig_pos = TM_DispLen, Optional In Num_Digs = TM_DispLen, Optional In Dbuf() = TM_DispBuf)
    
    '' Common Cathode display, up to 8 digits - no segment transpose (Reg C0 bits 0-7 is digit 1)
      #Ifndef Com_Anode   ' Com_Cathode
          set TM1638_STB 0
              TM1638_WrVal (TMcmd2) ' Fixed address mode 44h
          set TM1638_STB 1
              Wait TMdly us
        For BufIndx = Dig_pos - (Num_Digs -1)  to  Dig_pos
          set TM1638_STB 0
              TM1638_WrVal (TMaddr +(BufIndx -1)*2)    ' Digit addr
              TM1638_WrVal (DBuf(BufIndx))             ' Digit data
          set TM1638_STB 1
              Wait TMdly us
        Next
            tmCtrlSnd
      #endif
    
    End Sub
    
     

    Last edit: ToniG 2022-09-10
    • Jeff Weinmann

      Jeff Weinmann - 2022-09-10

      Toni.G,

      Thanks for the code - I may check it out and test it when my PCB comes in. Right now my breadboard is serving up the time via GPS, and I don't want to mess with it while its working!

      Attached is the PCB that will replace my breadboard and make my old clock a real appliance lol.

      If it works as planned, I have 5 boards on order and can send you one for your project. I see the 1638 uses the STROBE line so I'm pretty sure you could use it in your projects.

      The board is based on the PIC18F16Q40 so far a VERY versatile chip. It also has a Northern software programmer chip and will be able to program the PIC via the micro USB connection.

      thanks again!

       
  • ToniG

    ToniG - 2022-09-12

    Are you reading buttons from 18F pins or TM key inputs?
    I have got some code working for TM1638 buttons & it should work for TM1628.

     
  • ToniG

    ToniG - 2022-09-13

    TM1638 Button Test code is nearly ready, will post a link.
    Its great when we find hackable products to improve or repurpose. So many have such cheap/customized parts making it not viable.
    Our local Tip-Shop won't sell anything electronic now, saying its e-waste, I argue it's not if someone can use it.

     
  • ToniG

    ToniG - 2022-09-13

    TM1638 Button code is here, you can try it when you get your new TM1638 board.
    The full TM1638_OEM library should be ready soon...

     

Log in to post a comment.