Project: PIC 4-Digit Single-Chip 24 Hour Clock

Discussion in 'The Completed Projects Collection' started by MMcLaren, Dec 5, 2012.

  1. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    I'd like to share a relatively simple "single chip" 4-digit LED Clock project that uses a PIC16F1828 microcontroller, a 32768 Hz crystal time base, a four digit LED display, and just a handful of other parts. This low parts count design is due in part to experiments with some very bright miniature multiplexed 4-digit displays which are available from Sparkfun in red, green, yellow, white (all $1.95), and blue ($2.50) colors.

    [​IMG]
    Hardware

    The circuit was built on a Radio Shack prototype board (sku 276-149) with a plastic laminated paper silk-screen glued onto the component side of the board. I used 30 guage Kynar wire and point-to-point wiring on the copper side of the board.

    The circuit does not include column/digit driver transistors and relies on the combined ~250 ohm RDS(ON) resistance of the PIC I/O pin high side and low side FET drivers for segment current limiting. The display is refreshed one segment at a time (1/32nd duty cycle) to provide even brightness across the entire display.

    [​IMG]

    Parts List
    Code ( (Unknown Language)):
    1. 1 ea. PIC16F1828-I/P (DIP package)
    2. 1 ea. 0.1-uf (100nf) ceramic capacitor
    3. 2 ea. 22-pf ceramic capacitors
    4. 1 ea. 32768 Hz (12pf) watch crystal
    5. 1 ea. 10 kOhm, 1/8th watt carbon film resistor
    6. 4 ea. 1N914 or 1N4148 silicon switching diode
    7. 1 ea. Sparkfun COM-09483 Red Common Anode 4-Digit Display
    8. 4 ea. generic momentary contact switch
    9. 1 ea. Soberton GT111P Piezo Speaker
    10.  
    11. Misc. sockets, connectors, prototype circuit board
    Software

    The HEX file in the ZIP file attachment can be used directly with a PICKIT2, PICKIT3, or similar device programmer to program the PIC16F1828. The program source file is also included in the ZIP file attachment. The program was written using the free/lite version of BoostC from Sourceboost and it uses 339 of the 4096 words of program memory available in the 16F1828.

    The program configures the 16F1828 to run from the internal oscillator at 8-MHz and the Timer 2 module is configured to generate 250-usec (500 cycle) periodic interrupts. The Timer 1 low power oscillator is enabled for the 32768 Hz crystal. The ISR (interrupt service routine) is responsible for refreshing one new segment of the display each interrupt and it also polls Timer 1 for one second time-base intervals for the RTC. All thirty two segments of the display are updated once every 8-msecs for a 125-Hz refresh rate (1/32nd duty cycle).

    Operation

    The <SET> switch is used to toggle between "set" and "run" modes. Press <SET> to enter "set" mode and the "hours" display group will flash at a 2-Hz rate. While in "set" mode the <Rt> arrow key is used to toggle between the "hours" and the "minutes" display groups and the <Up> and <Dn> arrow switches are used to increment (+) or decrement (-) the value of the current flashing display group. The "hours" display group will rollover from 23 to 0 (+) or 0 to 23 (-) and the "minutes" display group will rollover from 59 to 0 (+) or from 0 to 59 (-). The <Up> and <Dn> arrow switches will repeat when held down. Press <SET> again to exit "set" mode and enter "run" mode (display stops flashing). While in "run" mode, the <Up> arrow, the <Dn> arrow, and the <Rt> arrow switches are disabled. Those switches are still sampled and debounced in the interrupt service routine and you'll still hear a "new press" beep when you press one of them, but they're ignored and cleared by the logic in the program.

    Observations

    This is the first time I've used a 32768 Hz crystal and so far it seems reasonably accurate, gaining just under one second per day, which I believe is within the 30 ppm crystal spec. I suspect this could be improved by grounding the crystal case and trying slightly different capacitor values (or a ceramic trimmer capacitor). Anyway, the accuracy is acceptable, for now, and I'm really looking forward to experimenting with some of the interesting PIC low power sleep modes that utilize the low power 32768 Hz crystal oscillator.

    I hope someone finds this project useful.

    Cheerful regards and happy Holidays, Mike
     
    Last edited: Jan 31, 2016
    RRITESH KAKKAR, SPQR and absf like this.
  2. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    This looks to be the same schematic as the timer circuit you posted. I have a half designed PCB for it if it is. Is it?

    I'll probably put it into the projects forum and post a link on this post and in the other thread when I am done.
     
  3. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Yep, this is the same board and schematic used for the PIC 4-Digit 99 Minute Timer project. It's also the same board I used for the PIC 4-Digit DS18B20 Temperature Monitor project, but that project needed minor wiring changes to support the DS18B20 connection and to use decimal points on the seven segment display instead of the colon LEDs.

    If I were to design a general purpose PCB for these single-chip projects, I would probably include a jumper on the PCB to select either decimal point LEDs or Colon/A/B LEDs in order to better support a more diverse set of projects.

    Cheerful regards, Mike
     
    Last edited: Dec 6, 2012
  4. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    When I get to a point where I have a checklist schematic I'll post it and a .png file. You ever use PCB express?
     
  5. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Is that a board house or PCB software? I used a program called ExpressPCB many years ago.
     
  6. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    I use it for my artwork, heavily modified with GIMP. I was thinking the schematic software mainly. It is what I used in the PCB thread I made.
     
  7. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    Care to do a wire check for me? I'll also add the strap you were talking about if you define where it is.

    [​IMG]
     
    Last edited: Dec 8, 2012
  8. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Hi Bill,

    Gosh, that looks pretty nice. Connections and pin numbers check out, except for just a couple corrections, if you please;

    (1) Where's C1?
    (2) R1-R4 on your schematic should be diodes (cathode end on switches).
    (3) RB4-RB7 connections to the switches are reversed.

    You could leave the switch connections "as is" and make minor changes to the software, but then there would be people out there using two different switch configurations and managing two different versions of software for each project could be problematic.

    Here's a quick-n'-dirty diagram of the jumper to select the display of either "decimal points" or "colon, A, and B" LEDs.

    Cheerful regards, Mike, K8LH

    [​IMG]
     
  9. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    Is C1 the unlabeled 0.1µF on the power supply? I just missed it, thanks.

    The strap on the display is easy enough.

    Missed the bars on R1-4, it is one of the reasons I like regular schematics, less ambiguity. I assume small signal diodes will work (such as 1N4454 or 1N918).

    Can I get by with switching designations on the switches?

    I plan on making the layout as similar to yours as possible. It may not be practical, but it is a goal.

    I will PM you sometime in the future (lets make a deal). :D
     
  10. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    OK, the prints are updated. Are they OK now?
     
  11. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Now the RB4-RB7 connections to the display are reversed and the RB5 and RB6 connections to the discrete 'A' and 'B' LEDs are reversed. Also, you have duplicate 'D1' and 'D2' labels. All those should be an easy fix, yes?

    Looks great, Bill...
     
    Last edited: Dec 8, 2012
  12. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    Yes, back to slaving over a hot computer...

    :D
     
  13. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    OK, done. I will delete all the extra posts once the OK is given. I really don't like junking up threads like this. After this I will be working on the PCB layout proper, but even then I always touch up the final product to meet my personal specs. I really detest Express's pads for ICs, for example.

    I think the last drawing was a bit cleaner for the mods. I don't like stair steps on schematics either.
     
  14. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Gosh Bill, that looks great but the 'A' and 'B' LED connections are still wrong. If you wanted to pick nits, you could probably label the crystal 32.768 kHz instead of 32.767 KHz...
     
    Last edited: Dec 8, 2012
  15. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    Might as well get it right. These are minor, so I will post the plans again (same post) but assume it is right, and start work on the PCB layout. As I have said, when you say it is right I will delete (actually moderate, as in render invisable) posts #9 - 15. When I have something usable in the PCB layout I will start a new thread in the projects thread and link post # 7 to it, and link your other project to it as well. This is designed to be a universal board, usable as a bed for other similar projects. Feel free to suggest changes to designations or layout, I have M McLaren as the designer on the Express print. It is your design, you are in control.

    One of the reasons I am doing this is I want to learn PICs, before I program code I need to program the PIC itself with known working code, and this has uses beyond the obvious (as in a scoreboard, for example). It is very modular, and can be used for many other things, like a thermometer.

    Never was I so happy to get a jury summons. Even with Jury Duty I now have 3 days off where I thought I was stuck with 7 days a week (see Long hours at work). That and they had an unscheduled day for plant maintenance for 3rd shift. Whoppie!

    I have seriously missed having time to sink my teeth into a project.

    I will post this publically, private information can be done with a PM. I am thinking of making several boards, say 3 or 4. I will make the PCB plans as complete as I can. I have been polishing this technique for a while. When I have a 1st run (DIY) I'll send you a kit (either assembled, or ready to solder, your choice) and let you insert a programed PIC into it to verify operation. In return you send me a preprogramed PIC I can use as a test unit for my boards.

    What do you think?
     
  16. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Ok. Cool.

    That's not necessary. There's nothing proprietary about the design.

    Oh my. I hope things get better at work and with your health...

    I probably don't need a kit, Bill, but I'll see about getting you a programmed PIC.

    Now, instead of DIY printed circuit boards, have you considered the PCB services from Seeed or Itead? One of them has a service where you send your Gerbers and you get ten 5x5 cm (1.97"x1.97") boards for $10 plus shipping (about $13 total). People who use the service get boards back in 2-3 weeks that look like this one (from Raj Bhatt, one of our Forum members);

    [​IMG]

    Happy Holidays and cheerful regards, Mike, K8LH
     
    Last edited: Dec 9, 2012
  17. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    First the design. At the moment I'm creating a virtual kit, which is to say I'm drawing a few custom components (had to do the same thing with the schematic).

    I'll keep the board shop in mind though.
     
  18. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    OK, got all the parts drawn and have a preliminary layout, which I'll post for a little while. I figure you might be interested. For anyone that hasn't done this this was the easy part, now begins the real work. The board is 3.8" X 2.5".

    There is a minor problem in that I have no idea how to make Gerber files. This is proriatory software to support the organization that sells their boards. Tis OK, I don't mind making my own boards, but if someone know how to translate scaled drawing to Gerber I would be interested.

    This post will self destruct with the rest, and be reborn in a different thread (with the changes).

    [​IMG]
     
  19. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Whoa Bill... The footprint for the display and the piezo speaker are wrong. The push button switches don't look quite right either.

    When I used ExpressPCB many years ago, they were very good about providing patterns for parts that weren't in their library. If they're not that responsive now days and you have to make your own part patterns you should use dimensions from the part data sheets rather than guessing (grin).

    If it helps, here's the silkscreen layer with 0.1" grid from the (free) Diptrace PCB software I use. The dimensions of the Radio Shack 276-149 board are 2.844" by 1.844". BTW, Diptrace can generate Gerbers (here's how).

    Happy Holidays and cheerful regards, Mike

    [​IMG]
     
    Last edited: Dec 11, 2012
  20. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    The displays I ordered from Sparkfun, and hand measured them. If you look close the dimensions are very close to the same, mine are a shade narrower. There is an offset on my PCB, it is not necessary to match the holes since I will be drilling them from scratch. It will fit the same, I do need to verify my pins are what I think they are.

    I also forgot the jumper. Opps. :D

    The piezo is from a local source. There is another thread, independent of this one, that shows the component I am using.

    Remove seal after washing, What the????

    I am using block connectors similar to these...

    [​IMG]

    Since I am comfortable with PCB Express I will finish the design with it, then take on DIP trace to transfer it over.
     
    Last edited: Dec 11, 2012
Loading...