Using cog counter as a serial I/O
yisiguro
Posts: 52
Is there someone who tried using a cog counter as a shift register something like below ?
MOV FRQx, #1 ' can be any of power of 2 ADD PHSx, PHSx ... ADD PHSx, PHSx MOV somewhere, PHSx
Comments
" For Propeller Assembly, only readable as a source register (i.e., mov dest, source); read-modify-write not possible as a destination register."
-Phil
Maybe you could adapt it for async somehow? I'm not experienced enough to know how, or how to alter it to change speeds, but it could perhaps be a starting point.
Cheers,
Jesse
Actually, you can, but the destination read will come from the shadow register, which contains whatever was last written to that register.
To use cog counter as a serial input, it is to be assumed that the counter is updated only ONCE ( or always TWICE through receiving entire bit stream ) between previous instruction's Write cycle and Dest cycle of following "ADD PHSx,PHSx" instruction. This means sampling window is 2 sysclk wide.
"ADD PHSx,PHSx" causes updating shadow ram by previous value of itself plus incremented value of PHS.
That is, new value is sum of twice of ( i.e. left-shifted ) old value, and, if any, 1 ( or 2 ).
Some code added.
(edit)
Instead of using "ADD PHSx,PHSx" instruction, using "SHL FRQx,#1" can be more flexible ?
(but sampling window becomes wider and contiguous)
I've used that one and it works great.
Infact, here it is, copy-pasted straight from one of my own source files, so this should work
Source thread:
forum: https://forums.parallax.com/discussion/143514/fast-full-duplex-serial-1-cog-a-k-a-ffds1
Of note too is that while a link may be full duplex, very often the protocol is essentially half duplex anyway.
By the way, there's an experimental code to try detecting baudrate automatically.
I implemented my concept straight forward, so this code is not so optimised, I think.
Acceptable format is 8bit-nonparity.
Only lower 7 bit characters ( $00 thru $7F ) are detectable, so do not set MSB to high.
First character must be sent with trailing 68 bit or more idle state ( logic high ) in worst case ( i.e. on receiving NUL character).
In this code, both cog counters are used for measuring positive and negative pulse width precisely.