ZX81 clock, but this one is different !

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: ZX81 clock, but this one is different !

Post by Andy Rea »

Well that was a nightmare...

decided as my code was growing to split the source up into modules... and added a few tweaks along the way, i think that was my downfall, i should have just split it and re-tested it before doing the tweaks.

my i2c bit banger is ugly as heck, it was nice and readable full of calls but was incredibly slow so i replaced most of the calls with macros. and then decided to use af' instead of a memory byte to store the current bus state, but decided that was too slow still so unrolled the macros too :shock:

when i am sending a byte it's pretty much as fast as it'll go, the DS1307 is only rated at 100Khz speed and my clock pusle is 18t-states, 100khz been 16.5t-states per half cycles. of course it takes much longer to prepare the next bit of data around 60 t-states but at around 80t-states per bit thats getting on for a therectical speed of 5KBs

Code: Select all

;DO_TX
;
;SEND A BYTE TO I2C BUS
;
;ON ENTRY A=BYTE TO SEND
;
;USES	BC,A
;

DO_TX:
		LD	B,8			;COUNTER FOR 8 BITS
		LD	C,A			;BYTE TO SEND IN C
		
NEXT_TX_BIT:
		SLA	C			;SHIFT BIT OT SEND INTO CF
		JR	C,TX_BIT_HIGH

TX_BIT_LOW:
		EX	AF,AF'
		AND 	%11101111
		OUT	(PORT08),A	;SDA LOW
		EX	AF,AF'
		JR	TX_DATA_SET
		
TX_BIT_HIGH:
		EX	AF,AF'
		OR	%00010000
		OUT	(PORT08),A	;SDA HIGH
		EX	AF,AF'
	
TX_DATA_SET:
		EX	AF,AF'		;USE ALTERNATIVE ACCUMULATOR
		OR	%00001000
		OUT	(PORT08),A	;SCL HIGH

;with macros there would have been an extra EX AF,AF'\ EX AF,AF' here....

		AND	%11110111
		OUT	(PORT08),A	;SCL LOW
		EX	AF,AF'		;BACK TO NORMAL ACCUMULATOR
		
		DJNZ	NEXT_TX_BIT	;MORE BITS ?
		
TX_ACK:
		;TX_ACK IS A REALLY BAD NAME FOR THIS SECTION...
		;DATA LINE IS FREE'D AND THE ACK BIT IF ANY
		;IS RECIEVED FROM THE SLAVE DEVICE
		;BUT IS CLOCKED FROM THE MASTER
		
		EX	AF,AF'		;USE ALTERNATE ACCUMULATOR		
		OR	%00010000
		OUT	(PORT08),A	;FREE SDA (HIGH)

;with macros there would have been an extra EX AF,AF'\ EX AF,AF' here....

		OR	%00001000
		OUT	(PORT08),A	;SCL HIGH
		EX	AF,AF'		;BACK TO NORMAL ACCUMULATOR
		IN	A,(PORT08)	;READ THE SDA LINE.
					
		;DO NOTHING WITH IT !
		
		EX	AF,AF'		;USE ALTERNATE ACCUMULATOR
		AND	%11110111
		OUT	(PORT08),A	;SCL LOW
		EX	AF,AF'		;BACK TO NORMAL ACCUMULATOR
		
		RET
recieveing a byte is a bit more problematic... and not as quick but the main thing is it works

Code: Select all

;DO_RX
;
;RECIEVE A BYTE FROM I2C BUS
;
;ON ENTRY IF A<>0 ACK WILL BE SENT
;ELSE NO ACK
;
;BYTE RETURNED IN A
;
;USES BC, A
;

DO_RX:
		PUSH	AF			;SAVE AF (A NONZERO will send ACK bit)
		LD	B,8			;COUNTER FOR 8 BITS


		EX	AF,AF'		;USE ALTERNATE ACCUMULATOR
		OR	%00010000
		OUT	(PORT08),A	;SDA FREE (HIGH)
		EX	AF,AF'		;BACK TO NORMAL ACCUMULATOR
					
NEXT_RX_BIT:
		SLA	C			;SHIFT A ZERO INTO BIT 0
						;WILL BE ALTERED LATER IF RECIEVED
						;BIT IS 1 

		EX	AF,AF'		;USE ALTERNATE ACCUMULATOR
		OR	%00001000
		OUT	(PORT08),A	;SCL HIGH
		EX	AF,AF'		;BACK TO NORMAL ACCUMULATOR

;I MIGHT TRY IT WITHOUT THIS WAITING TO SEE IF THE SLAVE DEVICE
;IS CLOCK STRECTING AND SEE IF IT STILL WORKS OK

CLK_STRETCH:
		IN	A,(PORT08)	;WAIT FOR THE OTHER
		AND	SCL_IN		;DEVICE WHICH MAY
		JR	Z,CLK_STRETCH	;BE CLOCK STRECTHING


		
READ_BIT:
		IN	A,(PORT08)	
		AND	SDA_IN		;ONLY TEST THE DATA BIT
		JR	Z,BIT_DONE	
		
BIT_ONE:
		SET	0,C			;RX BIT WAS ONE; BIT 0 OF C ALREADY CONTAINS 0
		
BIT_DONE:
		EX	AF,AF'		;USE ALTERNATE ACCUMULATOR
		AND	%11110111
		OUT	(PORT08),A	;SCL LOW
		EX	AF,AF'		;BACK TO NORMAL ACCUMULATOR
		
		DJNZ	NEXT_RX_BIT

BYTE_DONE:				;SEND AN ACK BIT ?
						;NO ACK TELLS SLAVE DEVICE THAT WAS THE 
						;LAST BYTE TO SEND
		POP	AF
		AND 	A		;REMEBER NON ZERO = DO ACK
		JR	Z,NO_ACK
		
		EX	AF,AF'		;USE ALTERNATE ACCUMULATOR
		AND %11101111
		OUT (PORT08),A		;SDA LOW (ACK BIT)
		EX AF,AF'			;BACK TO NORMAL ACCUMULATOR
		
		JR	DO_9TH		;JUMP TO 9TH CLOCK PULSE
		
NO_ACK:
		EX	AF,AF'		;USE ALTERNATE ACCUMULATOR
		OR	%00010000
		OUT	(PORT08),A	;SDA HIGH (IT'S PROBABLY ALREADY HIGH.)		
		EX	AF,AF'		;BACK TO NORMAL ACCUMULATOR
				
DO_9TH:
		EX	AF,AF'		;USE ALTERNATE ACCUMULATOR
		OR	%00001000
		OUT	(PORT08),A	;SCL HIGH
		AND	%11110111
		OUT	(PORT08),A	;SCL LOW
		OR	%00010000
		OUT	(PORT08),A	;SDA HIGH
		EX	AF,AF'		;BACK TO NORMAL ACCUMULATOR

		LD	A,C			;RECIEVED BYTE IN A
		RET
now to get busy thinking up ways of displaying the time, i only have 2 at the moment, standard where the second hand moves once a second, the minute hand once a minute and the hours hand once every 2 minutes, and smooth. where the second hand moves smoothly (6 steps a second) the minutes hand moves once every 10 seconds, and again the hour hand moves once evry 2 minutes. I was thinking of adding a marker for AM/PM indication say between 11 and 12 o'clock for AM and between 12 and 1 o'clock for PM, suppose i could do the running backwards thing too :lol: then i could get creative and have the seconds fill up on even minutes and thne un-fill on the next, maybe some kind of binary mode might be fun... lots of ideas now i'm thinking about it.

i hope to get some video on youtube over the weekend 8-)

Regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZX81 clock, but this one is different !

Post by sirmorris »

How did you cut the slots in the platters?
How much vibration is there?
Would you cut some for me if I post you a harddrive??!
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: ZX81 clock, but this one is different !

Post by Andy Rea »

i cut the platters with a dremmel, the vibration is very smal as long as you get the slots opposite each other, they counter balance each other :D

but one thing whne selecting a hard drive.... i found that after ripping out the heads and voice coil that after a while maybe 30 seconds or so the spindle motor shuts down, i presume because the on board electronics (ide drive) is thinking there is something wrong as it's not gettong any feedback from the now disconnected heads. my solution after farting about trying to short various test points without sucess, was quite simple, after mounting the opto to detect the rotations of the disk, i used that signal to reset the drive i think it's pin 1 on the ide connector (but you better check), so with it constantly been reset it runs forever assuming you don't overly load the spindle motor (by putting you fingers on :lol: )

i think the drivce i used was on old WD one,

it is quite noisy the air over the slots in the platter cause it i think, but once it is all built to a finished state the idea is to mount a cover of some sort, clear where the platters are with a short cylinder almost touching the platters and the rest enclosing everything else blacked out, so all you see is the platters, and with it enclosed hopefully the noise will be reduced.

yeah i can cut some platters for you, ii'd guess you could do it with a fine hacksaw blade as well, oh and de-burr the edges of your cut...

the LED's oh boy, for it to be visable in normal light conditions you need super duper bright ones, i have bought some prolight 3w rgb leds nominal current 300ma per element ! thats almost 1A and i have 4 of them, of course there not on 100% of the time, the uln2003 darlington arrays i use to fdrive the leds stay cool, they are only used for switching so power disipation in mimnmal in these devices, the current limiting resistors on the other hand get slightly warm, i should be using 1w resistors but haven't got any so i've doubled up on 1/3w resistors, oh and i need to alter the red resistors as white (all leds on) is slightly pink. )

Regards Andy

P.s. thinking of having a go at making one ?
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: ZX81 clock, but this one is different !

Post by Andy Rea »

Gosh i feel so stupid :oops:

i spent nearly an hours yesterday trying to track down a problem with my code, when in 'time set mode' the hours should first blink, and then when you press the set button again the minutes should blink, and finally when you press the set button again the new time is written to the RTC chip and normal running resumes.

However the hours was blinking, but then when the minutes where blinking the hours would blink also... i first thought i messed up my test for the cur_mode and re-wrote the test more than once...to no avail i was getting to the point of frustration so left it, this morning i have added some compile time conditional code so that i can test it more easily on EightyOne, and lo and behold 5 minutes i have found the problem, when blinking the minutes if the minutes are to be off (i.e not displayed) i am doing a conditional RET and never getting to displaying the hours ! :oops:

now i have to sort out the hours.... chip stores them as 1 to 12, not 0 to 11 as i first thought, this wouldn't be so much of a problem if i hadn't decided to add an AM/PM indicator that now changes at a displayed time of 11 o'clock :oops:

i'll get there eventually

think i'll write a simple game after this !

regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: ZX81 clock, but this one is different !

Post by Andy Rea »

a couple of videos for you...

normal ruinning mode, sorry about the flickering, it's the mismatch in camera shutter speed and refresh speed of the POV clock, much like when you try to video a tv and get black bars.

http://www.youtube.com/watch?v=VICIvcE9U_0

http://www.youtube.com/watch?v=NV5Zj8m4e18

Regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZX81 clock, but this one is different !

Post by sirmorris »

I'm scared the platters will shatter :?

What's the risk, d'you think? :lol:
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: ZX81 clock, but this one is different !

Post by Andy Rea »

well as long as they are not glass or ceramic platters (usually only found in higher spec drives) they will most likely be aluminium in which case they'll never shatter

if you do find yourself with a glass or ceramic platter i guess a fine diamond dust cutting wheel might do it if your very careful and keep it cool.

regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZX81 clock, but this one is different !

Post by sirmorris »

Did you cut the platters together in order to remove exactly the same amount of material from each?
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: ZX81 clock, but this one is different !

Post by Andy Rea »

Nope, but i did lay them one atop the other when cut to see if they were close enough :)

regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
Post Reply