binary clock query

LED Maestro

Senior Member
Hi,
I have built myself a binary clock to read seconds, minutes and hours from DS1307 into a pic 28x2. I am using 20 LED's (7 for the seconds, 7 for the minutes and 6 for the hours) which are multiplexed in 3 rows of 7 (minus 1 for the hours). I currently have a very long piece of code which is basically a never ending list of
if b0 = %00000001 then
high c.0, b.0
endif

if b0 = %00000010 then
high c.1, b.0
low c.0
endif

etc etc. this goes on for all 60 seconds!! My problem is i can't display all the time (hour, minutes and seconds) due to the extreme length of code multiplexing doesn't work as the flicker is visible and it makes the LEDs very dim. I am stuck with the repeating cycle of seconds which is great but I would like to read the whole time!
My question, is there a way to do what i am describing with a much shorter code. I have tried doing loops and increments but my knowledge isn't sufficient in these matters to make it work.
Any suggestions would be greatly apreciated.
Many thanks
 

oracacle

Senior Member
A circuit diagram would be helpful.

depending on how you have wire it, you could just, read the clock, run a BCD conversion and then let pins = sec, etc etc

use bcdtobin command to convert the value. i will see if i can come up with some code in the next few hours
 

LED Maestro

Senior Member
Thanks for the reply. I tried using a bcdtobin command without much success (Most likely due to inexperiance). I have done a quick, very quick, diagram of my circuit. See below. My diagram doesn't show current limiting resistors or the pic!
thanks

binary multiplexing.jpg
 
Last edited:

oracacle

Senior Member
as a quick note you have made thig harder by not keeping the anode (presume anodes) to the same bus. what stage is the circuit design at, also dont forget that you will be getting very close to the current limit of the picaxe with that many LEDs sinking current though a pin.

heres that simplest way to diplay time on a binary multplexed display,

Code:
symbol secs		= b0
symbol mins		= b1
symbol hour		= b2

let dirsb = %11111111
let dirsc = %00000111

main:

	i2cslave %11010000, i2cslow,i2cbyte					
	readi2c 0, (secs,mins,hour)

	let secs = bcdtobin secs
	let mins = bcdtobin mins
	let hour = bcdtobin hour


	let pinsb = hour
	;switch on secs
	let pinsc = %00000001
	let pinsb = mins
	;switch off secs, switch on mins
	let pinsc = %00000010
	let pinsb = secs
	;switch off mins, switch on hour
	let pinsc = %00000100
              goto main
as you can see all the LEDs on port b make it very easy, you can then use 3 pins on port c for connecting the transistors to sink LED current
 
Last edited:

LED Maestro

Senior Member
This is at current stage of design. thanks for the code. It works brilliantly in the sim so I will program my pic and see where we go. I understand your concern about the current limit but I have taken every precaution to try and limit it as best I can.
If I have anymore question then I will be back in no time, if you excuse the pun!
thanks again
 

oracacle

Senior Member
glad i could help, have you thought about how to set the time in first place

also you do relaise the program isnt for your current design, i had just finnished it when you posted your diagram
 

LED Maestro

Senior Member
I have already done that bit. I found that relativly straight forward compared to reading and displaying the time! My appologies for asking, it's late as you are no doubt aware, but at the moment i have my anodes connected to C.0, 1, 2, 5, 6, 7 and B.0. With your code, which pins do i connect them to now?
Again I appologise for asking a daft question
Thanks
 

oracacle

Senior Member
connect you anodes to b0 - b6.

i would not worry about late, it nearly 4am here and i normally work nights
 

LED Maestro

Senior Member
I am the same side of the pond, UK. I, however, don't work nights but I have been trying to get this working all evening. This was the first time I really looked at the clock and saw it was almost morning. But I thank you none the less for you invaluable help. I will post a link to a video on youtube when it is done.
Thanks
 

LED Maestro

Senior Member
Ok last question. My seconds seem to be lighting up my minutes at the same time but not the hours thankfully. Any suggestions?
thanks
 

oracacle

Senior Member
double check you code, make sure there are no typos, then if not it will be hardware issue.

try discounting the minutes and run it, see what happens, and again for the seconds. this will tell you roughly wher to look for the error
 

oracacle

Senior Member
how are you accessing portc?

did you use the let command if so, try using let pinsc = 1 for hour, let pinsc = 2 for mins, and let pinsc = 4 for secs.

if that fails, you could try swithc ing over so you use c.5- c.7 instead, if it still gives problems then there is an issue with you circuit somewhere - you will have to alter your code to match the new circuit
 

inglewoodpete

Senior Member
When debugging hardware, it is often useful to temporarily add delays between the digits in the loop so you can actually see what is happening. Extend the delay to 10 seconds or more if you need to use a multimeter to measure things.

As an aside, the i2cSlave command need only be used at the initialisation

Code:
symbol secs = b0
symbol mins = b1
symbol hour = b2

Init:
	let dirsb = %11111111
	let dirsc = %00000111
	
	i2cslave %11010000, i2cslow,i2cbyte               

main:
   readi2c 0, (secs,mins,hour)

   let secs = bcdtobin secs
   let mins = bcdtobin mins
   let hour = bcdtobin hour

   let pinsb = hour
   ;switch on secs
   let pinsc = %00000001
   Pause 1000         'Temporary while debugging
   let pinsb = mins
   ;switch off secs, switch on mins
   let pinsc = %00000010
   Pause 1000         'Temporary while debugging
   let pinsb = secs
   ;switch off mins, switch on hour
   let pinsc = %00000100
   Pause 1000         'Temporary while debugging
goto main
 

LED Maestro

Senior Member
thanks for this. I will give this a go. As an update, I have programmed the seconds, minutes and hours individually to see if each bit of code works on its own and, guess what, each work on their own. My next step is to program 2 together and see what happens.
Thanks
 

LED Maestro

Senior Member
ok, tests concluded and I can't run the code with either seconds and minutes, seconds and hours or minutes and hours. Is there anyway to make the chip think they are separate from one another?
 

LED Maestro

Senior Member
quick idea. My board is based on multiplexing the LED's. Is there a way to 'switch off', so to speak, variables one after the other just as you do with C.0, 1 and 2?
 

oracacle

Senior Member
hmm that seem very odd, do you get the same results by using different variable, like b1, b5 and b9 for arguments sake.

i dont currently have the hardware to test anything here
 

LED Maestro

Senior Member
Funny you should mention. I have just created a control variable. I insert that after each other variable and hey presto! I got myself a working binary clock. I've put the code down for future referance.

Code:
#Picaxe 28x2

symbol secs	= b0
symbol mins	= b1
symbol hour	= b2
symbol control = b7

let dirsb = %01111111

	i2cslave %11010000, i2cslow,i2cbyte	
	
	let secs = bcdtobin secs
	let mins = bcdtobin mins
	let hour = bcdtobin hour				
	
main:
	
	readi2c 0, (secs,mins,hour)
	
      high c.0
	let pinsb = secs
	;switch on secs
	low c.0
	let pinsb = control
	
	goto minutes
	
      minutes:
	high c.1
	let pinsb = mins
	;switch off secs, switch on mins
	low c.1
	let pinsb = control
	
	goto hours
	
	hours:
	high c.2
	let pinsb = hour
	;switch off mins, switch on hour
	low c.2
	let pinsb = control
	
	goto main
thank you for all your help and as promised, I shall upload a video onto youtube and post the link here.
thanks again
 

oracacle

Senior Member
how do you find it displays as without running the bcdtobin every cycle would mean that you will be displaying the BCD from the RTC

i was also just looking at the program i wrote, i can see the issue will be cuased by the fact it call the next set of pin out for the time before switch over. could you test some other code for me

Code:
symbol secs		= b0
symbol mins		= b1
symbol hour		= b2

let dirsb = %11111111
let dirsc = %00000111

i2cslave %11010000, i2cslow,i2cbyte	

main:					
	readi2c 0, (secs,mins,hour)

	let secs = bcdtobin secs
	let mins = bcdtobin mins
	let hour = bcdtobin hour

	let pinsb = hour
	pulsout c.0,20	;pulse hour
	let pinsb = mins
	pulsout c.1,20	;pulse mins
	let pinsb = secs
	pulsout c.2,20	;pulse secs
	goto main
alter the pulsout ot the appropiate length and see if that chnages anything, it would hvae to be long enough to appear to the human eye but not too long to show the display is multiplexed
 

LED Maestro

Senior Member
of course. I would be happy to tst it for you. And yes I forgot to mention the pin switchover. I will get back to you shortly. I have only just noticed that the bcd conversion is outside the main code. I am puzzled but it seems to be working ok...
 

LED Maestro

Senior Member
Yep that code is working brilliantly too. I think I might keep that one on the chip as the other code gives a slight 'glitch' every minute or so.
 

LED Maestro

Senior Member
40 on the hours, 10 on the minutes and 20 on the seconds but this is down to brightness of the LED's. I found it can't go above 50, thats when the flicker sets in
 

LED Maestro

Senior Member
Thank you very much. I can't express my gratitude. Without your help, I doubt I would have been able to get this far so thank you!
Best wishes
 

LED Maestro

Senior Member
Yeah I am aware they give off radiation but they are actually a lot dimmer than it appears in the video. And I am only running it every now and again until I build my case for it.
 

LED Maestro

Senior Member
Inglewoodpete, it is currently %00010101:%00100101:%00001101!! So presumably it's %00010001:%00100101:%00001101 in Western Australia.
Thanks for the great post!!
 
Top