Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

using a RTC in SF basic

MrDEB

Well-Known Member
I have a DS-1302 RTC module but how to use it?
I recall Jon Chandler made a vu meter clock but what he used for timing?
Am planning on a clock that has no hands, just LEDs but precision would be nice.
 
The DS-1302 is not a chip that will be easy to use in a standalone configuration. The time keeping function is based on a 32.768 kHz quartz crystal. The remining pins provide a serial interface to a micro controller. The choice of a microcontroller is largely irrelevant.

Googling SF basic, the #1 hit is a San Francisco Ski Injury Clinic. I'm guessing that your reference is to something else. Isn't AI marvelous?
 
Against my better judgement.....

First, I suggest using a DS3231 module instead of the DS-1302 module or DS-1307 modules. The accuracy of the DS3231 is much better than the DS-1302 or DS-1307. There is a DS-1307 Swordfish include module, which I have very slightly modified for the DS3231. There isn't a DS-1302 include module, so I suggest forgetting about the DS1302.

Next point - The DS3231, as are almost all RTC modules, uses the I2C interface. I2C interfaces are complex, and must be done in the correct way; there is ZERO room for random changes.

There are many steps to making a clock. You need a mechanism to set the time and date. You have to read separate registers for hours, minutes and seconds and then do the math to display the results. My code is going to take more explanation than I am willing to provide, with much of it dedicated to the display, which won't apply to what you're doing.

I've attached the DS3231 include module. I suggest downloading the DS3231 datasheet and taking a look at the task you're trying to do.
 

Attachments

  • ds3231.bas
    10.7 KB · Views: 111
There may be an easier way for you to accomplish this. The attached pdfs discuss what I did for the servo clock. The method used is basically counting seconds, and converting that count into hours and minutes. Maybe this will help.

This is based on Soft RTC - 4 Methods For A Precision PIC Time Clock from the Swordfish Basic website.

[Edit: The original A Clock For Geeks article has been restored and posted on Jon's Imaginarium for anyone interested.]
 

Attachments

  • A Clock for Geeks.pdf
    2.9 MB · Views: 118
  • clock controller.pdf
    40.8 KB · Views: 114
Last edited:
Swordfish Basic is not Arduino – it's for Microchip PIC18F-series micros.
 
Am planning on a clock that has no hands, just LEDs but precision would be nice
Just to clarify, you want to use individual LEDs in some kind of analog clockface arrangement? Not 7-segment displays.

If you're going to follow my suggestion and use the method I did for the servo clock, you must use a crystal – the internal oscillator will not be accurate enough.
 
Here is the first draft of the clock that I am contemplating. Started laying out the pcb. Getting the hour LEDs i the right placement. Discovered the protractor.
 

Attachments

  • weird clock.pdf
    206.7 KB · Views: 119
How about NOT LAYING OUT A PCB before you have a workable schematic? That just complicates things when changes are required.

I do suggest making a sketch of what you're trying to do – the layout of the LEDs. I see 72 LEDs so I suppose that's 60 for minutes and 12 for hours. What are the two 7 segment digits for?

The way you have the resistors for the LEDs, only ONE LED in a column can be illuminated at a time. I think you want the resistors in the "LED" (row lines) and none in the column lines.
 
by laying out a PCB I found I need to renumber the LEDs (DISPLAY NAME = YES DISPLAY PREFXEX = NO ) BUT LAYING OUT THE PCB THE DISPLAY PREFIX AND NAME ARE REVERSED.
I need to add a few buttons (ADJUST TIME UP, DOWN, START. Note only one LED to be enabled except the hour LEDs'
Am contemplating removing the transistors?
I drew out a sketch and designing as I go. Only reason I am designing the PCB is when I discover an issue I can correct as I go.
 
I've made my suggestions, asked questions which haven't been answered, and I don't know what all the shouting in the ALL-CAPS is about.

Good luck.
 
I assume the 7-segment digits are common-anode type from the way you have 5V as the common pin.
If so, you probably want to use PNP transistors instead of the 2N3904 NPN for Q1 and Q2 and swap the emitter-collector connections around (emitter to 5V, collector to digit common)
 
sorry about the shouting. I never learned how to properly learn how to type so I only use one finger and don't look at the screen.
The display is common anode (C462137). Will make suggested change thanks.
The green LEDs are the hours, the yellow (60) leds are minutes and the display is seconds.
Wll look at the row and colum resistors etc.
 
What happens if more than one LED is turned on in a column? The current is controlled by R5. So if two LEDs are on, each gets half the current and will be dimmer. If 8 LEDs are on, each gets ⅛ the current and will be very dim (if the LEDs are well-matched, otherwise some may hog all the current and others not illuminated at all).

I know in your Yankee thrift, using 9 resistors (one in each LED line) instead of one common one seems like a huge waste of a dime, but LEDs in parallel with a single resistor is never a smart idea.

SmartSelect_20240807_125042_Dropbox.jpg
 
The LEDs are to represent minutes. Plan on only one at a time, but yes maybe I should put the resistors on the cathodes.
While talking with my wife, it occurred to me the size of the PCB. The hour indicators are green led donuts (22mm w/12mm hole) which will need a larger board.
Plan is attaching a PCB fabricated, then a clear piece of plexiglass.
 
I had a thought this morning - what's the largest size clock you could practically make using 100mm x 100mm cheap boards. A 300mm (11.8") diameter clock is possible, using a total of 9 boards of 3 different designs. $15 of boards would be enough to build 2 clocks.

The sketch shows the arrangement, using 5mm LEDs for the minutes and 22mm LEDs for the hours. Four pie-shaped boards would be used for the corners, four rounded boards at the top, bottom and sides, and a central control board. The clock is slanted 15 degrees from vertical just to make the test layout easier to think about.

The corner boards have 8 5mm LEDs and one larger LED, while the other boards 7 5mm LEDs and 2 larger LEDs. This could work pretty well with your multiplexing scheme. Connections between boards could be made with right angle male and female headers. These are shown in red, not to scale.

Click on the file to see the image.
 

Attachments

  • PCB_test segment_2024-08-09.png
    723.6 KB · Views: 105
I don't suppose you've considered the current requirements of the large LEDs vs the small?
 

Latest threads

New Articles From Microcontroller Tips

Back
Top