PSM Bit Bang Timming Help
hippy
Posts: 1,981
RxPasmLoop waitpne rxPasmPinMask,rxPasmPinMask waitpeq rxPasmPinMask,rxPasmPinMask mov rxPasmTimeout,rxPasmBitTime shr rxPasmTimeout,#1 add rxPasmTimeout,rxPasmBitTime add rxPasmTimeout,CNT sub rxPasmTimeout,#K ' <---- HERE mov rxPasmBitCnt,#8 RxPasmGetBit waitcnt rxPasmTimeout,rxPasmBitTime test rxPasmPinMask,INA WC shr rxPasmBitSeq,#1 muxnc rxPasmBitSeq,#$80 djnz rxPasmBitCnt,#RxPasmGetBit
mov txPasmTimeout,txPasmBitTime add txPasmTimeout,CNT add rxPasmTimeout,#K ' <---- HERE TxPasmSendBit shr txPasmBitSeq,#1 WC muxc OUTA,txPasmPinMask waitcnt txPasmTimeout,TxPasmBitTime djnz txPasmBitCnt,#TxPasmSendBit
These are is a bit-banged serial input and output routines ( idles low, start bit high ) ... How do I determine what the K's should be to get most accurate time from when INA pin goes high to when INA is next sampled and likewise to get the first bit length right in the tramsit.
Comments
This is the application for which I most often use Gear.
Looking at the code though, you've got no instructions that would require anything other than 4 clock cycles. So just count up the number of instructions and multiply by 4. (Initial guess would be 28 for the first k, and about 8 for the second k).
Other than that, I've never heard of PSM, but I did notice that you've got a bit-and-a-half delay on the receiver - which is a good thing to get you to the middle of the bit period.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Multiply by 4" ... D'oh ! Not multiply by 1, it's CNT++ every cycle, not per instruction.