6 Digit Countdown Timer (hh:mm:ss)

Radarman2

Member
Hi,
I'm 90% complete on this countdown timer (Code and Schematic attached).
All that's left for me to do is figure out how 11 switches (possibly 13) can work properly as inputs into PortA (7 pins as A.4 is out only). If you look at Main: you'll see I'm working on 2 port pins being used for each input. This is simply because any less will cause unreliable and confusing operation.

I have purposefully left off the +ve, earth, control signal and switch connections to make the schematic less busy looking.

Comments on a postcard to the usual address - bear in mind this is my first PICaxe project (after the obligatory flashing LED lol)

Code can countdown from 99:59:59 or any manually set value (only hrs and mins can be set). Once I have completed the switchgear assy the code and cct will be modified to also be a laptimer in format mm:ss:tenths (each lap can be driven in under a minute).
I'll also probably wire up PinA.4 to flashing LEDs that sit between each pair of displays.
Once I've got all of that done the final step will be to make it HUGE! This will more than likely be as a strip of LEDs to create 12" high numbers. PICaxe chips obviously can't sink that much current, so a Darlington pair 7 channel chip will be used per display digit.

CCT Description:
40x2 as the brains, each port displays on 2 x 7 segment displays via a BCD to 7 segment decoder chip.
PortB for seconds, PortC for minutes, PortD for hours.
Low nibble of each port for secs/mins/hours units. High nibble for secs/mins/hrs tens.
i.e. 21hrs:45mins:30secs:
Secs low nibble would be 0, high nibble 3.
Mins low nibble would be 5, high nibble 4.
Hrs low nibble would be 1, high nibble 2.

Code:
'************************************************************************
'** 6 digit countdown timer using picaxe 40X2 output ports B, C & D    **
'** to drive binary to BCD chips that then drive 7 segment displays.   **
'**                                                                    **
'**        Kev Coe 16th March 2011. for RAF leeming Kart Club          **
'************************************************************************
#no_data
#no_table
#picaxe40x2

let b0=0	'pinsB initialise to 0-----seconds variable
let b1=0	'pinsC initialise to 0-----minutes variable
let b2=0	'pinsD initialise to 0-----hours variable
let dirsA=%00010000	'all in except A.4 out
let dirsB=%11111111	'set all portB out
let dirsC=%11111111	'all all PortC out
let dirsD=%11111111	'all all POrtD out

let outpinsD=bintobcd b2
let outpinsC=bintobcd b1
let outpinsB=bintobcd b0

setint %10000000,%10000000, A

Main:
'Minutes increment
if pinsA=%00000011 and b1<=59 then
	do
		b1=b1+1
		let outpinsC=bintobcd b1
		pause 250
	loop while b1=>0 and b1<=59 and pinsA=%00000001
endif
'Minutes decrement
if pinsA=%00000101 and b1>0 and b1<=60 then
	do
		b1 = b1-1
		let outpinsC=bintobcd b1
		pause 250
	loop while b1>0 and b1<=59 and pinsA=%00000010
endif
'Hours increment
if pinsA=%00000110 and b2=>0 and b2<=98 then
	do
		b2=b2+1
		let outpinsD=bintobcd b2
		pause 250
	loop while b2=>0 and b2<=98 and pinsA=%00000101	
endif
'Hours decrement
if pinsA=%00001010 and b2>0 and b2<=99 then
	do
		b2=b2-1
		let outpinsD=bintobcd b2
		pause 250
	loop while b2>0 and b2<=99 and pinsA=%00000110	
endif
'Presets for 30m, 1hr, 1h30m, 2hrs 
if pinsA=%00100001 then
	b0=0
	b1=30
	b2=0
endif
if pinsA=%00100010 then
	b0=0
	b1=0
	b2=1
endif
if pinsA=%00100100 then
	b0=0
	b1=30
	b2=1
endif
if pinsA=%00101000 then
	b0=0
	b1=0
	b2=2
endif
if pinsA=%01000001 then
	b0=0
	b1=0
	b2=0
endif
if pinsA=%01000010 then		'Condition to start Countdown timer (CountSeconds).
	if b2=0 then
		if b1=0 then
			pause 1000
			goto CountSeconds
		endif
		if b1>0 then
			dec b1
			b0=59
			pause 1000
			goto CountSeconds
		endif
	endif
	if b2>0 then
		if b1=0 then
			dec b2
			b1=59
			b0=59
			pause 1000
			goto CountSeconds
		endif
		if b1>0 then
			dec b1
			b0=59
			pause 1000
			goto CountSeconds
		endif
	endif
endif
let outpinsB=bintobcd b0
let outpinsC=bintobcd b1
let outpinsD=bintobcd b2
goto main				'Loops until START button is pressed.

CountSeconds:		
if b0=0 and b1=>0 and b2=>0 then
	b0=59
endif
for b10 = 0 to 59 step 1
	let outpinsB=bintobcd b0
	let outpinsC=bintobcd b1
	let outpinsD=bintobcd b2
	if b0=0 and b1>0 then
		if b1 = 0 then
			b1=59
			b0=59
			if b2=0 then
				goto CountSeconds:
			endif
			if b1>0 then
				dec b1
			endif
			goto CountSeconds:	
		endif
		if b2>0 then
			dec b2
		endif
		goto CountSeconds:
	endif
	pause 1000
	dec b0
	if b0=0 and b1=0 and b2=0 then
		goto EndGame
	endif
next b10

EndGame:			'Indication when timer has reached zero.
do
	if pinsA=%01000001 then
		let b0=0
		let b1=0
		let b2=0
		let outpinsD=bintobcd b2
		let outpinsC=bintobcd b1
		let outpinsB=bintobcd b0
		goto main
	endif
	let outpinsB=bintobcd 56
	let outpinsC=bintobcd 34
	let outpinsD=bintobcd 12
	pause 500
	let outpinsB=bintobcd 0
	let outpinsC=bintobcd 0
	let outpinsD=bintobcd 0
	pause 500
loop while b0=0 and b1=0 and b2=0
Interrupt:			'Interrupt to pause timer
if pinsA=%10000000 then
	goto interrupt
endif 
setint %10000000,%10000000, A
return
 

Attachments

eclectic

Moderator
Quick reply.

Can you increase the
resolution and size of the schematic please?

It's too small to read properly.

e
 

Radarman2

Member
Sorry, latest image cut off rightmost display.
I'll get a beter res version tomorrow - clocks going forward has buggered my brain up a bit lol.
 

Radarman2

Member
Cheers Kiwi, I hadn't started looking through the forum yet and although I wasn't asking for help it really is appreciated.
I had started considering a type of ADC input, but my son's Ride on Thomas decided to stop working and a bit of component fault finding was needed.

Thought I should add here the testing attributes for the code:
00h00m59s
00h01m00s
00h59m59s
01h00m00s
01h01m00s
01h01m10s
02h00m00s
02h01m00s

Just to cover all evenytualities.
Code also tested with manual mins incremented to stop at 59 and decremented to syop at 0. Hrs incremented to stop at 99, decremented to 0.
Both sets of tests successful.
 

nbw

Senior Member
You could also use the MAX7219 with a small PICAXE if you wanted to - 3 lines can drive the MAX7219 which can in turn drive up to 8 multiplexed 7-segment displays. A great little IC.
 

everybodyelse

New Member
Timer modification

Hi. Great work!

I'm new to all this and I want to create a countdown timer circuit myself for a prop and if anyone can help I would much appreciate it.

I want to be able to switch the unit on, have it run a set sequence on 8 7-segment displays (days, hours, minutes, seconds) then count down from a random number. When 0 is reached it would go through another set sequence and return to a random number. There would also be 2 bargraphs, blinking 'seconds' leds, 3 alternating leds and an led that comes on when 0 is reached. Is this possible?

Any help from anyone here would be very welcome. I'm even willing to pay to get it done!

Best wishes,

Martin
 

hippy

Technical Support
Staff member
It should all be possible. To start I'd guess the first thing is to ask what your practical experience with PICAXE and electronics is and what's your budget ? You might find someone willing to do it all for you for money but you're more likely to get help towards doing it yourself.
 

everybodyelse

New Member
It should all be possible. To start I'd guess the first thing is to ask what your practical experience with PICAXE and electronics is and what's your budget ? You might find someone willing to do it all for you for money but you're more likely to get help towards doing it yourself.
I don't have any experience with PICAXE. As I said I'm quite new to all this so I'm just getting started. I used to do a bit of BASIC on the BBC Micro when I was younger. Is it the same language?

The circuit is the main concern because I've no experience! If anyone could help me with building the circuit that would be fantastic!
 

westaust55

Moderator
The fundamentals for programming the PICAXE using the BASIC language are similar.
There are FOR...NEXT looping structures, GOTO, GOSUB commands, variables etc.

There are also more advanced/modern looping structure commands such as DO...LOOP

But as the PIC chip which forms the basis of the PICAXE has inbuilt hardware such as IO ports, timers etc
there are commands such as PINS, HIGH, LOW to control pins, SERIN and SEROUT for serial comms via IO pins, etc.

You would do well to download the PICAXE manuals (3 parts) available from the link at the top of this forum pages and have a read through at least parts 1 and 2 to get a feel for the PICAXE "environment".
 

everybodyelse

New Member
I might have a crack at programming it myself but I really need someone to help with the circuit design.

I'll start a new thread with a description of the end result and pictures/video of what I need.

The thread will be called "TIMER PROP ELECTRONICS" and will be up later tonight.

If anyone could possibly help I would really appreciate it :)
 
Top