reading four bit data
kingneb
Posts: 65
How do you program the SX to recieve 8 bits over a 4 bit line (ra channel)?
Post Edited (kingneb) : 10/13/2005 4:05:12 AM GMT
Post Edited (kingneb) : 10/13/2005 4:05:12 AM GMT
Comments
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
Available now... SX-Video OSD module $59.95 www.sxvm.com
"Save your money. Pay with cash."
·
Thanks
Check out this page http://www.allaboutcircuits.com/vol_4/chpt_12/4.html
Attached is a picture using only 3 outputs to create 8 outputs.
If your using SX/B you can use SHIFTOUT to set the shift register.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
Product web site: www.sxvm.com
Available now... SX-Video OSD module $59.95 www.sxvm.com
"Save your money. Pay with cash."
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (kingneb) : 10/13/2005 4:07:13 AM GMT
Posting clear questions and not changing your request in the middle of the thread will get you quicker answers ... and save me and others a lot of wasted typing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 10/13/2005 3:10:30 AM GMT
Instead of, "Lets say I have data coming from an external source, such as a Parallal port or dip switches," why not just say exactly what you want to hook up to the RA port and then see if people can help you. Waving your hands around the problem isn't making it any clearer for those trying to assist you. If you have a parallel port, then provide details such as :
What the device is that actually has the port in question. Is it a PC? An embedded processor?
What handshake mechanism there is to let the SX know that data is ready and that a nibble has been retrieved.
If it's not a parallel port, then don't mention parallel ports at all. If it's a DIP switch, then say it's a DIP switch. In that case, you still need to tell folks what sort of handshake or sync mechanism there is to let the SX know that data is ready.
If there is no mechanism, then all you are trying to do is read an 8 bit DIP switch with a 4 bit port. In that case you're going to need some external hardware to assist. Period. There is no magic to getting a four bit port to read an eight bit DIP swtich - it's just a matter of buffering the data and presenting it as a pair of nibbles, but you stil need an extra bit or two to load the buffer and switch between nibbles.
Thanks, PeterM
This may work. Tell the SX to capture the first nibble, wait a bit, then recieve the next. That way the computer parallel port is responsible for sending the second signal within the wait period. That way, if the second signal is the same, the comp will not change it. The microcontroller goes into a loop. When it is time to recieve another signal, a break code is given (lets say the number 2). After the parallel port puts 2 out, the loop is broken, a delay is given to give the computer time to change from the number 2 to the next nibble. Here is the general code, dont mind any errors, just approximation.
tris_b = 0
nib1 var byte
nib2 var byte
result var byte
start:
do 'signal microcontroller to begin recieving first nibble
pause 25
loop until ra = 2
pause 100 ' wait for PC to change signals from 2 to whatever
nib1 = ra
pause 100 ' wait for PC to change signals to nibble 2 value
nib2 = ra
'compute result
result = nib1 + nib2
rb = result
pause 100 ' give computer time to change from whatever to zero, this prevents an unwanted
'loop break if ra is still 2 (nibble 2 is 2)
goto start:
· theByte = RA················' get high·nibble
· SWAP theByte················' move to high position·
· PAUSE NibDelay··············' wait for low nibble
· temp = RA···················' read the low nible
· theByte = theByte | temp··· ' assemble with high
But as Peter pointed out, without some kind of specific notification from the external device that the nibble has changed you could end up with errors.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Perhaps you've seen worse descriptions, but that does not excuse you of helping the forum out with a better effort.
Believe me, the amount of other people's effort will bear a direct relationship to the amount you are putting in yourself.
As for me, I can't be bothered.
Good luck.
Peter (pjv)
You could send two data bits at a time, and use a third bit as clock, or a "data ready" bit. The SX would wait for the clock bit to go high. On the first transition to high, then data is ready. The SX would shift its result byte left twice, then read the two data bits and OR them into the result byte. Then wait for the clock bit to go low. Do this four times and the SX will then have a complete byte.
You might need a way to synchronize the start of each byte transmission, depending on your specific application. I've done something like this where I used time for synchronization - once the SX receives a clock, it expects the next three clocks to arrive within milliseconds, otherwise it resets.
David
Doing this has a set of problems because you need to be able to distinguish between the timing nibbles and the data nibbles which may be identical, the only method I can think of is having two timing nibbles, a stop nibble and a start nibble.
The stop nibble will be the·NOT of the last data nibble, the start nibble could be any value, but lets assume it is 0.
You will look for the transition of the last data nibble of the previous frame to the stop nibble by looking for the transition from a value to to its inverse, then you time the amount of time that passes till the nibble turns to 0 (let's call that value t), now the first data nibble of the frame could also be a 0, but that doesn't matter because you already got your time per nibble.
So you wait a value of t+t/2 from the end of the stop nibble, this places you in the middle of the first data nibble, you read that value into a buffer byte·then·SWAP it to the high nibble of·the buffer. Then you wait an additional time t, and now your in the middle of the second data nibble, you OR port a into your buffer, and now the data is in your buffer byte. At some time less than t/2 later you enter a tight loop looking for the next stop nibble and start the whole process over.
Now when the·communication first starts you may end up out of sync if the·first data nibble is the inverse of the start nibble or the second data nibble is the inverse of the first data nibble, but the first data sequence this isn't the case you will be synced and stay synced.· If you make the start nibble the same as the last data nibble of the previous frame (NOT(NOT(last data nibble)) you can reduce the likelyhood of syncing to the wrong portion of the data because your looking for a "nibble NOT(nibble) nibble" sequence which will occur only rarely when it isn't the real McCoy.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 10/13/2005 4:07:39 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A friend of mine was a street bum for halloween.