Updating output pins at speed

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Updating output pins at speed

Post by FFMan »

Pursuing my ongoing obsession with clock projects i decided to try and recreate an oscilloscope clock that was executed so well here

http://www.dutchtronix.com/ScopeClockH3-1-Enhanced.htm

I was intending to use a 328n but I note that there is not an entire output port of 8 pins available (to drive an external DAC AD7302) as for speed i was going to address the register directly such as:-

register.portb=255

but as an entire port is not available I've ended up with some code as below that users a pin map in an array where the pins could be any values.

With this code I can achieve approx 6,500 adc updates per second. If i remove the loop, i can achieve approx 30,000 but of course it doesn't work.

I could move to a zx40 as a solution or even a 128a1 I have which has the benefit of higher clock speed also, but i wondered if there was a simpler solution ?

Code: Select all

'Sub to write the binary data to the correct pins
Sub ADC7302PutData(byVal byData as byte)

	dim byLoop as Byte
	
	for byLoop=0 to 7
	
		Call PutPin(by7302Data(byLoop+1),GetBit(byData,byLoop))
		'debug.print byLoop;" pin=";by7302Data(byLoop+1);" bit=";GetBit(byData,byLoop)
		
	next
	
end sub
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Updating output pins at speed

Post by dkinzer »

FFMan wrote:[...]i wondered if there was a simpler solution ?
An alternative that would likely be faster would be to have two parallel arrays - one with the PORTx address and one with a bit mask (exactly one bit set). Then, for each bit you can set or clear the bit in the PORTx as appropriate. Alternatively, for each bit you could clear the bit and then if it should be set, set it.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

i moved to a zx40 so could address entire io port in 1 command and speed is better but borderline for what i want to achieve.

i either need a tube with longer persistence or faster processor.

I note the original kits where done on PICS, not sure what speed what they ran at but is the code lower level ?

What would be the quickest zbasic platform at the moment ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

FFMan wrote:i moved to a zx40[...] and speed is better but borderline for what i want to achieve.
Is it a ZX-40 or a ZX-40n? The latter would be significantly faster.
FFMan wrote:What would be the quickest zbasic platform at the moment ?
All of the xmega devices run at 29.4MHz compared to 14.7MHz for the native mode ATmega-based devices. The number of cycles for a given code sequence would be similar for mega and xmega so you would get roughly twice the throughput with an xmega.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

it's a zx40n - i don't use the vm devices any more.

twice the speed is better - i'll see how it goes
kranenborg
Posts: 57
Joined: 27 July 2009, 14:20 PM
Location: Groningen, The Netherlands
Contact:

Re: Updating output pins at speed

Post by kranenborg »

FFMan wrote:Pursuing my ongoing obsession with clock projects ...

I was intending to use a 328n but I note that there is not an entire output port of 8 pins available (to drive an external DAC AD7302) as for speed i was going to address the register directly such as:-

register.portb=255

but as an entire port is not available ...
You actually can make a full 8-bit output port available for use with those operations on the ZX-328 and the likes, see: www.zbasic.net/forum/viewtopic.php?t=14 ... pc_t=59724


Regards,
Jurjen
rich
Posts: 81
Joined: 19 November 2015, 12:23 PM

Post by rich »

It would be faster if you did not use putPin.

Write directly to the registers with register.<name> for each slice of output register.

This would mean the pins would need be fixed but is that a problem.

Richard
Post Reply