Zx 1280 - Reading value from I/O Ports
Zx 1280 - Reading value from I/O Ports
Hi,
I am using zx 1280 for a time critical medical device. I need to communicate with different MCUs connected to zx using the I/O ports (PORTA through PORT J). Since its a time sensitive system, I need read a set a six bytes from the I/O port (say PORTA) in a sequential fashion within 1 micro second. The MCU that sends these values is in synch with zx.
The problem that I am facing is, in order to read the value from a port I could find instructions that read a single bit (eg: get pin)
I need some function that can fetch a port value directly into a byte variable.
I tried the following statement, but I could nt ready the value
Option PortB "PPPPPPPP"
.
.
.
Dim var as byte = 0
byte = Register.PortB
.
.
.
This dint work out, but instead I did the following and it worked at the expense of extra time
for i = 0 to 7
if(getpin(porta(i))=1) then
call putpin(portf(i),1)
else
call putpin(portf(i),0)
next
byte = Register.PortF
This loop is consuming a lot of additional time. I have worked on several other controllers and even the simpler ones that belong to 8051 family have simple statements that let us read a byte from the port
Appreciate all your help !
Thank You.
I am using zx 1280 for a time critical medical device. I need to communicate with different MCUs connected to zx using the I/O ports (PORTA through PORT J). Since its a time sensitive system, I need read a set a six bytes from the I/O port (say PORTA) in a sequential fashion within 1 micro second. The MCU that sends these values is in synch with zx.
The problem that I am facing is, in order to read the value from a port I could find instructions that read a single bit (eg: get pin)
I need some function that can fetch a port value directly into a byte variable.
I tried the following statement, but I could nt ready the value
Option PortB "PPPPPPPP"
.
.
.
Dim var as byte = 0
byte = Register.PortB
.
.
.
This dint work out, but instead I did the following and it worked at the expense of extra time
for i = 0 to 7
if(getpin(porta(i))=1) then
call putpin(portf(i),1)
else
call putpin(portf(i),0)
next
byte = Register.PortF
This loop is consuming a lot of additional time. I have worked on several other controllers and even the simpler ones that belong to 8051 family have simple statements that let us read a byte from the port
Appreciate all your help !
Thank You.
Zx 1280 - Reading value from I/O Ports
> ... byte = Register.PortB
Try Register.PinB, but you'll not be able to meet your 6bytes/uS
criterion unless you use an external FIFO cache and the data is in
bursts that allow sufficient time to empty the FIFO and process that data.
Tom
Try Register.PinB, but you'll not be able to meet your 6bytes/uS
criterion unless you use an external FIFO cache and the data is in
bursts that allow sufficient time to empty the FIFO and process that data.
Tom
Tom
Re: Zx 1280 - Reading value from I/O Ports
You need to read the mega1280 datasheet to correctly use the port registers. See table 37 on page 84. For inputs you set the DDRx register (e.g. DDRB) to 0 and the PORTx register controls whether you tristate or use pullups. This is the same as using "Option Portx" as you have done.
To read the port value, use the PINx register as Tom recommends.
I think that it will be extremely difficult to get the timing you want with the ZX-1280 because of the extra work done by the virtual machine. In most applications this is not an issue, but in your time-sensitive application you are probably better off with a ZX-1280n where the ZBasic code is compiled to AVR machine code.
To read the port value, use the PINx register as Tom recommends.
I think that it will be extremely difficult to get the timing you want with the ZX-1280 because of the extra work done by the virtual machine. In most applications this is not an issue, but in your time-sensitive application you are probably better off with a ZX-1280n where the ZBasic code is compiled to AVR machine code.
Mike Perks
Zx 1280 - Reading value from I/O Ports
> ... probably better off with a ZX-1280n where the ZBasic code is
compiled to AVR machine code.
Still, it's likely to be difficult to get six reads with handshaking in
one uS, isn't it?
Tom
compiled to AVR machine code.
Still, it's likely to be difficult to get six reads with handshaking in
one uS, isn't it?
Tom
Tom
Re: Zx 1280 - Reading value from I/O Ports
At a clock speed of 14.7456 MHz, each instruction cycle takes 67.8ns. Therefore in 1 microsecond the AVR can execute just less than 15 cycles. This gives just enough time to read the 6 I/O registers and loop back to do it over.GTBecker wrote:Still, it's likely to be difficult to get six reads with handshaking in
one uS, isn't it?
So yes, this isn't enough time to do anything with the data. Even if the AVR runs at 20MHz, its maximum speed, there still isn't much time to do anything. Options are:
1. Decrease the frequency of I/O reads to something like 5us
2. Get a different microcontroller that is faster
3. Use some other kind of technology that can process data @ 6 Mbyte/sec or faster such as a FPGA.
Mike Perks
Re: Zx 1280 - Reading value from I/O Ports
Perhaps you can explain your problem in more detail so we can help with possible solutions. There is already a MCU sending 6 bytes of parallel data. Is this data simply redistributed to the other MCUs? So why not use some discrete logic or a CPLD for this? How often is the data changing? Is it really changing every microsecond?angad wrote:I am using zx 1280 for a time critical medical device. I need to communicate with different MCUs connected to zx using the I/O ports (PORTA through PORT J). Since its a time sensitive system, I need read a set a six bytes from the I/O port (say PORTA) in a sequential fashion within 1 micro second. The MCU that sends these values is in synch with zx.
Perhaps you could image how you would do this with a 8051 that had more I/O? Then we could extrapolate that to the mega1280 which does have all the I/O you need.
Mike Perks
RE
@ Tom and Mike
Thanks for the very prompt update !
Mike, I think you are right about DDRx registers. I checked the datasheet, shall implement this thing and get back if i find success.
Right now, I do not have the code, shall get back with code from my lab on monday !
The Zx continuously polls for values from the host on port b. When it receives all six values it just port this the corresponding MCUs. The data is differentiated by reading 3 bit status pins.
For now, I need to know if its possible to read the port value as a byte directly when DDR is configured
eg: Dim variable as byte = 0
variable = register.portB
I do not want to waste time by reading 8 pins of port B individually.
I too feel 1 us is a very short duration for 6 reading values.
Once again, thanks for the update, Appreciate it !
Regards,
Angad
Thanks for the very prompt update !
Mike, I think you are right about DDRx registers. I checked the datasheet, shall implement this thing and get back if i find success.
Right now, I do not have the code, shall get back with code from my lab on monday !
The Zx continuously polls for values from the host on port b. When it receives all six values it just port this the corresponding MCUs. The data is differentiated by reading 3 bit status pins.
For now, I need to know if its possible to read the port value as a byte directly when DDR is configured
eg: Dim variable as byte = 0
variable = register.portB
I do not want to waste time by reading 8 pins of port B individually.
I too feel 1 us is a very short duration for 6 reading values.
Once again, thanks for the update, Appreciate it !
Regards,
Angad
Re: RE
In your original post, you indicated that you were usingangad wrote:I think you are right about DDRx registers. I checked the datasheet, shall implement this thing and get back if i find success.
Code: Select all
Option PortB "PPPPPPPP"
Code: Select all
Register.DDRB = 0 ' set all Port B pins to inputs
Register.PORTB = &Hff ' enable pullup resistors on all Port B pins
- Don Kinzer
Zx 1280 - Reading value from I/O Ports
> ... variable = register.portB
I'm sure you've read these responses incorrectly three times now.
Not Register.PORTB. Register.PINB will read all eight pins simultaneously.
Tom
I'm sure you've read these responses incorrectly three times now.
Not Register.PORTB. Register.PINB will read all eight pins simultaneously.
Tom
Tom
Nor is it necessary. It can be done simply by reading the correct register. Assuming that the I/O pins are already set to be inputs (using either of the methods described in an earlier post) you simply useangad wrote:I feel its not worth reading each bit and then writing these 8 bits into a byte variable.
Code: Select all
portVal = Register.PinB
Last edited by dkinzer on 25 January 2009, 16:01 PM, edited 1 time in total.
- Don Kinzer