Posted: Wed Oct 01, 2014 4:12 pm Post subject: Serial Framing
I am working on a machine monitoring project and not sure how to solve it? An old multiplexer board is used to read one status byte from each of 32 machines. It switches in a loop continuously reading a byte from each machine and dwelling for 8 millisecond. it repeat the cycle continuously. The circuit stuffs data into a register and pumps it out the serial port at 1200 baud with proper byte framing (start bit, data, stop, etc). The problem to identify the start of the sequence, since each byte is not tagged with machine number. if I know the start, I count each byte and number them, but where is the beginning? I think I need a way to measure the dwell period and generate a start character? I know how to get data serial form the uart, but how can I reliably detect the dwell and frame the record with a start character? any tips or code suggestions would be a big help. I can't modify the original circuit, not allowed. thanks it appreciated.
const DWELLTIME =6' this time should be less then the 8ms but longer then the time between each normal byte received. const STABLEFRAMECOUNT =3' minimum number of good frames before we try using the data...
dim TickCount asbyte' this will hold the number of ms between each byte and 100 if there is no data for 100ms or longer
dim myData(32)asbyte dim myDataindex asbyte dim newByte asbyte dim frameCount asbyte' holds the number of frames up to 100. its reset to 0 if there is no data for 100ms or more. dim frameCountOld asbyte
'=====[ Setup Timer0 for Tick isr ]============================================ ConfigTimer0=Timer, Prescale=1024, Compare A= Disconnect, ClearTimer=1 ' crystal / Prescale / Hz Wanted = reload value ' 16000000 / 64 / 1000 = 250 (1ms steps)
OCR0A =250-1' subtract 1 as per AVR docs On OC0A TickCounter0_isr
EnableTimer0 '------------------------------------------------------------------------------
EnableInterrupts
' The main look starts here................. do ifISCHARWAITING()=1thenGosub ProcessNewData
if frameCount <> frameCountOld thenGosub ProcessNewFrame
loop
ProcessNewData:
newByte =inkey()' get the new data
if TickCount > DWELLTIME then
myDataIndex =1' reset the index incr frameCount ' start of new frame else incr myDataIndex
end if
if myDataIndex <33then
myData(myDataIndex)= newByte ' load the data into the next position end if
TickCount=0' reset the timer return
ProcessNewFrame: if frameCount => STABLEFRAMECOUNT then ' ' we have a new frame and its stable! Now do something with it! ' end if if frameCount >100then frameCount =100
frameCountOld= frameCount
return
'=====[ Timer ISR routine ]====================================================
TickCounter0_isr: Incr TickCount
if TickCount >100then
TickCount =100
frameCount =0
frameCountOld =0 end if Return '------------------------------------------------------------------------------
Wow thanks for this very detailed and clearly commented example. This pretty much nails it. I am waiting to connect to one of the multiplexers for testing. I will add to this example and let you know how it goes. thx a bunch this is a big help and greatly appreciated! thanks!
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum