Propeller clock (POV)

raits999

Member
Hi everybody. This is my first post on this forum, and i have desided to share my unfinished project with you. Sorry for any misspelling as english is not my native language.
I got the idea from youtube when i was watching videos that others had made. Then i searched info for picaxe projects and found almost nothing. So i started figuring out how to do it, and i put together first prototype about in couple of hours and wrote first lines of code.. woilaa i had first stripe in fixed position, soon after that it displayed number and counted 0-999. Next thing was to build finished product from scrap. All parts except picaxe chip are recycled from old electronics boards.
Things used:
Picaxe 14m2
Ds1337
2x 555 timer
and smaller parts

Some Pics:
IMG_20120401_205248.jpgIMG_20120401_205211.jpg

Video:

And code:
Code:
#picaxe 14m2
#no_data
#terminal off
setfreq m32
let dirsb=%11111111
pullup on


symbol paus=2
symbol DS1337=%11010000
symbol startpause=b0
symbol sec=b1
symbol sec1=b2
symbol sec2=b3
symbol minute=b4
symbol minute1=b5
symbol minute2=b6
symbol hour=b7
symbol hour1=b8
symbol hour2=b9
symbol tempread=b10
symbol temp1=b11
symbol temp2=b12
symbol cloc_count=b13
symbol temp_count=b14
symbol irrecieve=b15
symbol temppin=c.0
symbol ledonpin=c.1
symbol middleledpin=c.2
symbol triggerpin=pinc.3
symbol outledpin=c.4

	
incclock:
	'if cloc_count=>2 then readtemperature:
	temp_count=0
	inc cloc_count

clockright:	
	if triggerpin=1 then clockright
	pause startpause
	high ledonpin
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	hi2cin $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	bcdtoascii sec,sec1,sec2
	sec1=sec1-48:sec2=sec2-48
	bcdtoascii minute,minute1,minute2
	minute1=minute1-48:minute2=minute2-48
	bcdtoascii hour,hour1,hour2
	hour1=hour1-48:hour2=hour2-48
	low ledonpin
	let dirsb=%11111111
	gosub clockdysplay
	irin [2],C.0,irrecieve
	if irrecieve= 16 then gosub minuteset
	if irrecieve= 18 then gosub hourset
	let startpause=startpause+1
	if startpause>100then clockleft
	goto clockright
	
clockleft:	
	if triggerpin=1 then clockleft
	pause startpause
	high ledonpin
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	hi2cin $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	bcdtoascii sec,sec1,sec2
	sec1=sec1-48:sec2=sec2-48
	bcdtoascii minute,minute1,minute2
	minute1=minute1-48:minute2=minute2-48
	bcdtoascii hour,hour1,hour2
	hour1=hour1-48:hour2=hour2-48
	low ledonpin
	let dirsb=%11111111
	gosub clockdysplay
	irin [2],C.0,irrecieve
	if irrecieve= 16 then gosub minuteset
	if irrecieve= 18 then gosub hourset
	let startpause=startpause-1
	if startpause<=2 then incclock
	goto clockleft
	
readtemperature:
	readtemp temppin,tempread

inctemp:
	if temp_count=>1 then clockright
	cloc_count=0
	inc temp_count

tempright:	
	if triggerpin=1 then tempright
	pause startpause
	pause 30		
	let temp1 =tempread//100 / 10       
   	let temp2 =tempread // 10
	gosub tempdisplay
	let startpause=startpause+2
	if startpause>150then templeft
	goto tempright
	
templeft:	
	if triggerpin=1 then templeft
	pause startpause
	pause 30		
	let temp1 =tempread//100 / 10       
   	let temp2 =tempread // 10
	gosub tempdisplay
	let startpause=startpause-2
	if startpause<4 then inctemp
	goto templeft	
	
minuteset:
	high ledonpin
	minute=minute+1
	if minute =10 then : minute = Minute+6
	elseif minute =26 then : minute = Minute+6
	elseif minute =42 then : minute = Minute+6
	elseif minute =58 then : minute = Minute+6
	elseif minute =74 then : minute = Minute+6
	elseif minute = 90 then : minute = 0
	endif
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	writei2c $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	irrecieve=0
	low ledonpin
	let dirsb=%11111111
	return
	

hourset:
	high ledonpin
	hour=hour+1
	if hour=10 then : hour = hour + 6
	elseif hour=26 then : hour = hour + 6
	elseif hour=36 then : hour = 0
	endif
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	writei2c $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	irrecieve=0
	low ledonpin
	let dirsb=%11111111
	return	
	
clockdysplay:
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	low middleledpin
	pause 1
	high middleledpin
	low outledpin
	if hour1=0 then skip
	on hour1 gosub nr0,nr1,nr2
skip:	
	on hour2 gosub nr0,nr1,nr2,nr3,nr4,nr5,nr6,nr7,nr8,nr9
	pause 1
	let pinsb=%11101101
	pause 1
	let pinsb=%11111111
	on minute1 gosub nr0,nr1,nr2,nr3,nr4,nr5
	on minute2 gosub nr0,nr1,nr2,nr3,nr4,nr5,nr6,nr7,nr8,nr9
	pause 1
	let pinsb=%11101101
	pause 1
	let pinsb=%11111111
	on sec1 gosub nr0,nr1,nr2,nr3,nr4,nr5
	on sec2 gosub nr0,nr1,nr2,nr3,nr4,nr5,nr6,nr7,nr8,nr9
	'pause 1
	high outledpin
	low middleledpin
	pause 1
	high middleledpin
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	return
	
tempdisplay:	
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	low middleledpin
	pause 1
	high middleledpin
	low outledpin
	pause 1
	gosub happy
	on temp1 gosub nr0,nr1,nr2,nr3,nr4,nr5,nr6,nr7,nr8,nr9
	on temp2 gosub nr0,nr1,nr2,nr3,nr4,nr5,nr6,nr7,nr8,nr9
	gosub tempc
	gosub happy
	pause 1
	high outledpin
	low middleledpin
	pause 1
	high middleledpin
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	return
	
colon:
	pause 1
	let pinsb=%11101101
	pause 1
	let pinsb=%11111111
	return	

happy:
	let pinsb=%11110011
	pause paus
	let pinsb=%11100101
	pause paus
	let pinsb=%11010010
	pause paus
	let pinsb=%11000010
	pause paus
	let pinsb=%11010010
	pause paus
	let pinsb=%11100101
	pause paus
	let pinsb=%11110011
	pause paus
	let pinsb=%11111111
	return


tempc:
	let pinsb=%11101111
	pause paus
	let pinsb=%11010111
	pause paus
	let pinsb=%11101111
	pause paus
	let pinsb=%11111111
	pause paus
	let pinsb=%11100001
	pause paus
	let pinsb=%11011110
	pause paus
	let pinsb=%11011110
	pause paus
	let pinsb=%11101101
	pause paus
	let pinsb=%11111111
	return

nr0:	
	let pinsb=%11100001
	pause paus
	let pinsb=%11011110
	pause paus
	let pinsb=%11011110
	pause paus
	let pinsb=%11100001
	pause paus
	let pinsb=%11111111
	return
nr1:	
	let pinsb=%11101110
	pause paus
	let pinsb=%11000000
	pause paus
	let pinsb=%11111110
	pause paus
	let pinsb=%11111111
	return
	
nr2:
	let pinsb=%11101100
	pause paus
	let pinsb=%11011010
	pause paus
	let pinsb=%11010110
	pause paus
	let pinsb=%11101110
	pause paus
	let pinsb=%11111111
	return
	
nr3:
	let pinsb=%11101101
	pause paus
	let pinsb=%11011110
	pause paus
	let pinsb=%11010110
	pause paus
	let pinsb=%11101001
	pause paus
	let pinsb=%11111111
	return
	
nr4:
	let pinsb=%11111011
	pause paus
	let pinsb=%11110011
	pause paus
	let pinsb=%11101011
	pause paus
	let pinsb=%11000000
	pause paus
	let pinsb=%11111111
	return	
	
nr5:
	let pinsb=%11001101
	pause paus
	let pinsb=%11010110
	pause paus
	let pinsb=%11010110
	pause paus
	let pinsb=%11011001
	pause paus
	let pinsb=%11111111
	return	
	
nr6:
	let pinsb=%11100001
	pause paus
	let pinsb=%11011010
	pause paus
	let pinsb=%11011010
	pause paus
	let pinsb=%11101101
	pause paus
	let pinsb=%11111111
	return
	
nr7:
	let pinsb=%11011111
	pause paus
	let pinsb=%11011000
	pause paus
	let pinsb=%11010111
	pause paus
	let pinsb=%11001111
	pause paus
	let pinsb=%11111111
	return
	
nr8:
	let pinsb=%11101001
	pause paus
	let pinsb=%11010110
	pause paus
	let pinsb=%11010110
	pause paus
	let pinsb=%11101001
	pause paus
	let pinsb=%11111111
	return
	
nr9:
	let pinsb=%11101101
	pause paus
	let pinsb=%11010110
	pause paus
	let pinsb=%11010110
	pause paus
	let pinsb=%11100001
	pause paus
	let pinsb=%11111111
	return
 
Last edited:

Hydroid

Senior Member
Very nice !
I'd seen PIC based ones on the Internet and figured it should be possible with PICAXE. I'll have to give it a go one of these days when my current 'to-do' list is whittled down a bit...
 

raits999

Member
Very nice !
I'd seen PIC based ones on the Internet and figured it should be possible with PICAXE. I'll have to give it a go one of these days when my current 'to-do' list is whittled down a bit...
That was the main reason to do this project, because everybody in this forum said picaxe is to slow and it cant be done. I just wanted to prove that it can be done.

And another proof:
 

westaust55

Moderator
@raits999,

Firstly, welcome to the PICAXE forum.

Secondly well done. :)


where you say:
everybody in this forum said picaxe is to slow and it cant be done. I just wanted to prove that it can be done.
Unsure who or when you found informaiton suggesting that it was not possible, however, until the relatively recent introduction of the M2 parts with clock speeds to 32 MHz (eg the 14M2 you have used) and the X2 parts with up to 64 MHz clock speeds, operating at such higher speeds was not possible on M parts (max of 8MHz) and needed an external resonator on X1 parts for up to 20 MHz.

Now for a few constructive comments for the PICAXE program code.

You appear to have a single i2c slave device, an DS1337 RTC chip. Therefore you only need to establish the i2c comms once at the start of the program rather than each time the
clockright: the clockleft: and the minuteset: routines are called. Not performing the i2c setup at each call of those code segments will save a small amount of time (bu not a lot at 32 MHz).

With the above, you would also need to remove the line after the i2c buss access in each section which reads:
hi2csetup off​

For the i2c comms setup, rather than using the older i2cslave command as:
i2cslave DS1337, i2cfast, i2cbyte​
You should be using the newer HI2CSETUP command.

likewise for the line
writei2c $00, (sec,minute,hour)​
use the HI2COUT command

you are already using the HI2CIN command in several locations in:
hi2cin $00, (sec,minute,hour)​


You do not need to reduce the clock speed to 4 MHz for the i2c bus comms. Just ensure that you use the correct suffix after the mode parameter. For example as taken from the PICAXE manual.

Effect of Increased Clock Speed:
Ensure you modify the speed keyword (i2cfast_8, i2cslow_8) at 8 MHz or
(i2cfast_16, i2cslow_16) at 16 MHz for correct operation.

Where you have code such as:
bcdtoascii sec,sec1,sec2
sec1=sec1-48:sec2=sec2-48​

Since you only want the "raw" binary numbers (without ASCII encoding), you could try with:
sec1 = sec / 16 : sec2 = sec AND $0F​
which may prove to be faster.
 

techElder

Well-known member
@raits999, very interesting hardware!

You've managed to combine through-hole devices and surface-mount on the same board.

Then you managed to position the components to get perfect balance (as indicated by how quiet the spinning is.) The rotor is balanced even to the point of shaving some of the copper cladding on the PCB.

I'm really interested in your hardware magnetic coupling of the signals going to the rotor electronics.

You've put a different spin on the clock by using a repurposed fan instead of a hard drive mechanism. Have you seen any effects of non-constant speed of the fan motor? I suppose the visible clock would drift some as it spins.

Impressive!
 

raits999

Member
@raits999,

Firstly, welcome to the PICAXE forum.

Secondly well done. :)


where you say:

Unsure who or when you found informaiton suggesting that it was not possible, however, until the relatively recent introduction of the M2 parts with clock speeds to 32 MHz (eg the 14M2 you have used) and the X2 parts with up to 64 MHz clock speeds, operating at such higher speeds was not possible on M parts (max of 8MHz) and needed an external resonator on X1 parts for up to 20 MHz.

Now for a few constructive comments for the PICAXE program code.

You appear to have a single i2c slave device, an DS1337 RTC chip. Therefore you only need to establish the i2c comms once at the start of the program rather than each time the
clockright: the clockleft: and the minuteset: routines are called. Not performing the i2c setup at each call of those code segments will save a small amount of time (bu not a lot at 32 MHz).

With the above, you would also need to remove the line after the i2c buss access in each section which reads:
hi2csetup off​

For the i2c comms setup, rather than using the older i2cslave command as:
i2cslave DS1337, i2cfast, i2cbyte​
You should be using the newer HI2CSETUP command.

likewise for the line
writei2c $00, (sec,minute,hour)​
use the HI2COUT command

you are already using the HI2CIN command in several locations in:
hi2cin $00, (sec,minute,hour)​


You do not need to reduce the clock speed to 4 MHz for the i2c bus comms. Just ensure that you use the correct suffix after the mode parameter. For example as taken from the PICAXE manual.




Where you have code such as:
bcdtoascii sec,sec1,sec2
sec1=sec1-48:sec2=sec2-48​

Since you only want the "raw" binary numbers (without ASCII encoding), you could try with:
sec1 = sec / 16 : sec2 = sec AND $0F​
which may prove to be faster.
Thanks for helping hand, but unfortunately all code snippets did not work for me.
I´m using i2c lines for driving leds and when i remove hi2csetup off then led 4,5 stay on all the time, they don´t obey any of the commands anymore.

hi2csetup off
This will turn off i2c and return the i2c related pins to normal general purpose input and output use
Using i2cfast_4 does not work, i´m getting blank display.

sec1 = sec / 16 : sec2 = sec AND $0F
that line is great thanks.
 

raits999

Member
@raits999, very interesting hardware!

You've managed to combine through-hole devices and surface-mount on the same board.

Then you managed to position the components to get perfect balance (as indicated by how quiet the spinning is.) The rotor is balanced even to the point of shaving some of the copper cladding on the PCB.

I'm really interested in your hardware magnetic coupling of the signals going to the rotor electronics.

You've put a different spin on the clock by using a repurposed fan instead of a hard drive mechanism. Have you seen any effects of non-constant speed of the fan motor? I suppose the visible clock would drift some as it spins.

Impressive!
Thanks

For power transfer read here, for frequency generator i used simple 555 timer circuit.

When i use still clock then it moves slightly left and right otherwise it`s not noticeable.
 

westaust55

Moderator
Thanks for helping hand, but unfortunately all code snippets did not work for me.
I´m using i2c lines for driving leds and when i remove hi2csetup off then led 4,5 stay on all the time, they don´t obey any of the commands anymore.



Using i2cfast_4 does not work, i´m getting blank display.

that line is great thanks.
Okay, missed the fact that you were using the i2c for driving LEDs as well.

For the line:
i2cslave DS1337, i2cfast, i2cbyte​

replace with
Hi2cSETUP i2cmaster, DS1337, i2cfast_32, i2cbyte​

Then remove the lines:
setfreq m4​
and
setfreq m32​
which wrap around the Hi2cin commands
 

raits999

Member
Okay, missed the fact that you were using the i2c for driving LEDs as well.

For the line:
i2cslave DS1337, i2cfast, i2cbyte​

replace with
Hi2cSETUP i2cmaster, DS1337, i2cfast_32, i2cbyte​

Then remove the lines:
setfreq m4​
and
setfreq m32​
which wrap around the Hi2cin commands
Sorry, my mistake. I did not read correctly, but those lines are quite irrelevant as i need more faster way moving between gosubs.
At the moment i do not have any pauses between gosubs and when i increase motor speed then caps between number are to big. More speed = smoother display.
 

shamu

Member
What a fantastic little project, ideal for my Science Club.
Is there a generic name for this type of device?
 

westaust55

Moderator
@raits999,

give the following code a try and see if it improves the speed.
Instead of using a subroutine for each digit or character being displayed, it keeps the data in TABLE memory and uses a pointer into the TABLE memory to fetch the necessary data for the LEDs.
In that manner each digit saves the time to jump to a subroutine and return but has an overhead to fetch the data from TABLE memory.

Code:
#picaxe 14m2
#no_data
#terminal off
TABLE (%11100001,%11011110,%11011110,%11100001,%11111111,%11101110,%11000000,%11111110) ; 0 and 1
TABLE (%11101100,%11011010,%11010110,%11101110,%11101101,%11011110,%11010110,%11101001) ; 2 and 3
TABLE (%11111011,%11110011,%11101011,%11000000,%11001101,%11010110,%11010110,%11011001) ; 4 and 5
TABLE (%11100001,%11011010,%11011010,%11101101,%11011111,%11011000,%11010111,%11001111) ; 6 and 7
TABLE (%11101001,%11010110,%11010110,%11101001,%11101101,%11010110,%11010110,%11100001) ; 8 and 9
TABLE (%11101111,%11010111,%11101111,%11111111,%11100001,%11011110,%11011110,%11101101) ; Temp C
TABLE (%11110011,%11100101,%11010010,%11000010,%11010010,%11100101,%11110011,%11111111) ; happy


setfreq m32
let dirsb=%11111111
pullup on


symbol paus=2
symbol DS1337=%11010000
symbol startpause=b0
symbol sec=b1
symbol sec1=b2
symbol sec2=b3
symbol minute=b4
symbol minute1=b5
symbol minute2=b6
symbol hour=b7
symbol hour1=b8
symbol hour2=b9
symbol tempread=b10
symbol temp1=b11
symbol temp2=b12
symbol cloc_count=b13
symbol temp_count=b14
symbol irrecieve=b15
SYMBOL tableindex = b16
SYMBOL tabledata = b17
SYMBOL Pointer = b18
symbol temppin=c.0
symbol ledonpin=c.1
symbol middleledpin=c.2
symbol triggerpin=pinc.3
symbol outledpin=c.4

	
incclock:
	'if cloc_count=>2 then readtemperature:
	temp_count=0
	inc cloc_count

clockright:	
	if triggerpin=1 then clockright
	pause startpause
	high ledonpin
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	hi2cin $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	sec1=sec/16:sec2=sec AND $0F
	minute1=minute/16:minute2=minute AND $0F
	hour1=hour / 16:hour2=hour AND $0F
	low ledonpin
	let dirsb=%11111111
	gosub clockdysplay
	irin [2],C.0,irrecieve
	if irrecieve= 16 then gosub minuteset
	if irrecieve= 18 then gosub hourset
	let startpause=startpause+1
	if startpause>100then clockleft
	goto clockright
	
clockleft:	
	if triggerpin=1 then clockleft
	pause startpause
	high ledonpin
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	hi2cin $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	sec1=sec / 16 :sec2=sec AND $0F
	minute1=minute / 16:minute2=minute AND $0F
	hour1=hour / 16:hour2=hour  AND $0F
	low ledonpin
	let dirsb=%11111111
	gosub clockdysplay
	irin [2],C.0,irrecieve
	if irrecieve= 16 then gosub minuteset
	if irrecieve= 18 then gosub hourset
	let startpause=startpause-1
	if startpause<=2 then incclock
	goto clockleft
	
readtemperature:
	readtemp temppin,tempread

inctemp:
	if temp_count=>1 then clockright
	cloc_count=0
	inc temp_count

tempright:	
	if triggerpin=1 then tempright
	pause startpause
	pause 30		
	let temp1 =tempread//100 / 10       
   	let temp2 =tempread // 10
	gosub tempdisplay
	let startpause=startpause+2
	if startpause>150then templeft
	goto tempright
	
templeft:	
	if triggerpin=1 then templeft
	pause startpause
	pause 30		
	let temp1 =tempread//100 / 10       
   	let temp2 =tempread // 10
	gosub tempdisplay
	let startpause=startpause-2
	if startpause<4 then inctemp
	goto templeft	
	
minuteset:
	high ledonpin
	minute=minute+1
	if minute =10 then : minute = Minute+6
	elseif minute =26 then : minute = Minute+6
	elseif minute =42 then : minute = Minute+6
	elseif minute =58 then : minute = Minute+6
	elseif minute =74 then : minute = Minute+6
	elseif minute = 90 then : minute = 0
	endif
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	writei2c $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	irrecieve=0
	low ledonpin
	let dirsb=%11111111
	return
	

hourset:
	high ledonpin
	hour=hour+1
	if hour=10 then : hour = hour + 6
	elseif hour=26 then : hour = hour + 6
	elseif hour=36 then : hour = 0
	endif
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	writei2c $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	irrecieve=0
	low ledonpin
	let dirsb=%11111111
	return	
	
clockdysplay:
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	low middleledpin
	pause 1
	high middleledpin
	low outledpin
	if hour1=0 then skip

	tableindex = hour1 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
skip:	
	tableindex = hour2 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	pause 1
	let pinsb=%11101101 ; colon
	pause 1
	let pinsb=%11111111
		
	tableindex = minute1 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	tableindex = minute2 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	pause 1
	let pinsb=%11101101 ; colon
	pause 1
	let pinsb=%11111111	
	
	tableindex = sec1 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	tableindex = sec2 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111


	'pause 1
	high outledpin
	low middleledpin
	pause 1
	high middleledpin
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	return
	
tempdisplay:	
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	low middleledpin
	pause 1
	high middleledpin
	low outledpin
	pause 1
	
happy1:	
	tableindex = 48
	FOR pointer = 0 to 8
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	
temperature:	
	tableindex = temp1 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	tableindex = temp2 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111

tempC:	
	tableindex = 40
	FOR pointer = 0 to 7
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
happy2:
	tableindex = 48
	FOR pointer = 0 to 8
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
			
	pause 1
	high outledpin
	low middleledpin
	pause 1
	high middleledpin
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	return
No guarantee that it will be faster, but at least it will have been tried and saves 388 bytes of program space.
 

raits999

Member
@raits999,

give the following code a try and see if it improves the speed.
Instead of using a subroutine for each digit or character being displayed, it keeps the data in TABLE memory and uses a pointer into the TABLE memory to fetch the necessary data for the LEDs.
In that manner each digit saves the time to jump to a subroutine and return but has an overhead to fetch the data from TABLE memory.

Code:
#picaxe 14m2
#no_data
#terminal off
TABLE (%11100001,%11011110,%11011110,%11100001,%11111111,%11101110,%11000000,%11111110) ; 0 and 1
TABLE (%11101100,%11011010,%11010110,%11101110,%11101101,%11011110,%11010110,%11101001) ; 2 and 3
TABLE (%11111011,%11110011,%11101011,%11000000,%11001101,%11010110,%11010110,%11011001) ; 4 and 5
TABLE (%11100001,%11011010,%11011010,%11101101,%11011111,%11011000,%11010111,%11001111) ; 6 and 7
TABLE (%11101001,%11010110,%11010110,%11101001,%11101101,%11010110,%11010110,%11100001) ; 8 and 9
TABLE (%11101111,%11010111,%11101111,%11111111,%11100001,%11011110,%11011110,%11101101) ; Temp C
TABLE (%11110011,%11100101,%11010010,%11000010,%11010010,%11100101,%11110011,%11111111) ; happy


setfreq m32
let dirsb=%11111111
pullup on


symbol paus=2
symbol DS1337=%11010000
symbol startpause=b0
symbol sec=b1
symbol sec1=b2
symbol sec2=b3
symbol minute=b4
symbol minute1=b5
symbol minute2=b6
symbol hour=b7
symbol hour1=b8
symbol hour2=b9
symbol tempread=b10
symbol temp1=b11
symbol temp2=b12
symbol cloc_count=b13
symbol temp_count=b14
symbol irrecieve=b15
SYMBOL tableindex = b16
SYMBOL tabledata = b17
SYMBOL Pointer = b18
symbol temppin=c.0
symbol ledonpin=c.1
symbol middleledpin=c.2
symbol triggerpin=pinc.3
symbol outledpin=c.4

	
incclock:
	'if cloc_count=>2 then readtemperature:
	temp_count=0
	inc cloc_count

clockright:	
	if triggerpin=1 then clockright
	pause startpause
	high ledonpin
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	hi2cin $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	sec1=sec/16:sec2=sec AND $0F
	minute1=minute/16:minute2=minute AND $0F
	hour1=hour / 16:hour2=hour AND $0F
	low ledonpin
	let dirsb=%11111111
	gosub clockdysplay
	irin [2],C.0,irrecieve
	if irrecieve= 16 then gosub minuteset
	if irrecieve= 18 then gosub hourset
	let startpause=startpause+1
	if startpause>100then clockleft
	goto clockright
	
clockleft:	
	if triggerpin=1 then clockleft
	pause startpause
	high ledonpin
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	hi2cin $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	sec1=sec / 16 :sec2=sec AND $0F
	minute1=minute / 16:minute2=minute AND $0F
	hour1=hour / 16:hour2=hour  AND $0F
	low ledonpin
	let dirsb=%11111111
	gosub clockdysplay
	irin [2],C.0,irrecieve
	if irrecieve= 16 then gosub minuteset
	if irrecieve= 18 then gosub hourset
	let startpause=startpause-1
	if startpause<=2 then incclock
	goto clockleft
	
readtemperature:
	readtemp temppin,tempread

inctemp:
	if temp_count=>1 then clockright
	cloc_count=0
	inc temp_count

tempright:	
	if triggerpin=1 then tempright
	pause startpause
	pause 30		
	let temp1 =tempread//100 / 10       
   	let temp2 =tempread // 10
	gosub tempdisplay
	let startpause=startpause+2
	if startpause>150then templeft
	goto tempright
	
templeft:	
	if triggerpin=1 then templeft
	pause startpause
	pause 30		
	let temp1 =tempread//100 / 10       
   	let temp2 =tempread // 10
	gosub tempdisplay
	let startpause=startpause-2
	if startpause<4 then inctemp
	goto templeft	
	
minuteset:
	high ledonpin
	minute=minute+1
	if minute =10 then : minute = Minute+6
	elseif minute =26 then : minute = Minute+6
	elseif minute =42 then : minute = Minute+6
	elseif minute =58 then : minute = Minute+6
	elseif minute =74 then : minute = Minute+6
	elseif minute = 90 then : minute = 0
	endif
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	writei2c $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	irrecieve=0
	low ledonpin
	let dirsb=%11111111
	return
	

hourset:
	high ledonpin
	hour=hour+1
	if hour=10 then : hour = hour + 6
	elseif hour=26 then : hour = hour + 6
	elseif hour=36 then : hour = 0
	endif
	i2cslave DS1337, i2cfast, i2cbyte
	setfreq m4
	writei2c $00, (sec,minute,hour)
	setfreq m32
	hi2csetup off
	irrecieve=0
	low ledonpin
	let dirsb=%11111111
	return	
	
clockdysplay:
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	low middleledpin
	pause 1
	high middleledpin
	low outledpin
	if hour1=0 then skip

	tableindex = hour1 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
skip:	
	tableindex = hour2 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	pause 1
	let pinsb=%11101101 ; colon
	pause 1
	let pinsb=%11111111
		
	tableindex = minute1 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	tableindex = minute2 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	pause 1
	let pinsb=%11101101 ; colon
	pause 1
	let pinsb=%11111111	
	
	tableindex = sec1 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	tableindex = sec2 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111


	'pause 1
	high outledpin
	low middleledpin
	pause 1
	high middleledpin
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	return
	
tempdisplay:	
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	low middleledpin
	pause 1
	high middleledpin
	low outledpin
	pause 1
	
happy1:	
	tableindex = 48
	FOR pointer = 0 to 8
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	
temperature:	
	tableindex = temp1 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
	
	tableindex = temp2 * 4
	FOR pointer = 0 to 3
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111

tempC:	
	tableindex = 40
	FOR pointer = 0 to 7
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
	pause paus
	LET pinsb=%11111111
happy2:
	tableindex = 48
	FOR pointer = 0 to 8
	  READTABLE tableindex, tabledata
	  pinsb = tabledata
	  INC tableindex
	  PAUSE paus
	NEXT pointer
			
	pause 1
	high outledpin
	low middleledpin
	pause 1
	high middleledpin
	let pinsb=%00000000
	pause 1
	let pinsb=%00111111
	return
No guarantee that it will be faster, but at least it will have been tried and saves 388 bytes of program space.

Thanks. I will try it when i have more time.
 

ginge1

New Member
This is really nice work. Congratulations, and thanks for sharing the code. I would love to make this. Do you have a schematic wiring diagram to go with this, or maybe just a few words of text describing which pins on the picaxe link to the LEDs, clock chip, I.R receiver, and index photodiode
 
Top