Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Serial Framing

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
rossfl

Bascom Member



Joined: 06 Jul 2008
Posts: 20

usa.gif
PostPosted: Wed Oct 01, 2014 4:12 pm    Post subject: Serial Framing Reply with quote

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.
Back to top
View user's profile
glena

Bascom Member



Joined: 25 Jul 2007
Posts: 284
Location: PA near Philly

usa.gif
PostPosted: Thu Oct 02, 2014 2:48 pm    Post subject: Reply with quote

rossfl,

Here is what I would do but this is just an example and not at all tested but it should give you a starting point...

-Glen


Code:

'=====[ Compiler Directives ]==================================================
$crystal = 16000000
$regfile = "m328def.dat"
$baud    = 1200
'------------------------------------------------------------------------------

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      as byte            ' this will hold the number of ms between each byte and 100 if there is no data for 100ms or longer

dim   myData(32)     as byte
dim   myDataindex    as byte
dim   newByte        as byte
dim   frameCount     as byte  ' holds the number of frames up to 100.  its reset to 0 if there is no data for 100ms or more.
dim   frameCountOld  as byte

'=====[ Setup Timer0 for Tick isr ]============================================
Config Timer0= Timer, Prescale= 1024, Compare A= Disconnect, Clear Timer= 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
Enable Timer0
'------------------------------------------------------------------------------

Enable Interrupts

' The main look starts here.................
do
   if ISCHARWAITING() = 1   then Gosub ProcessNewData
   if frameCount <> frameCountOld then Gosub 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 < 33 then
      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!  Smile
      '
   end if
   if frameCount > 100 then frameCount = 100
   frameCountOld= frameCount
return


'=====[ Timer ISR routine ]====================================================
TickCounter0_isr:
   Incr TickCount
   if TickCount > 100 then
      TickCount      = 100
      frameCount     = 0
      frameCountOld  = 0
   end if
Return
'------------------------------------------------------------------------------
 

_________________
http://bahbots.com


Last edited by glena on Fri Oct 03, 2014 4:30 pm; edited 1 time in total
Back to top
View user's profile AIM Address
rossfl

Bascom Member



Joined: 06 Jul 2008
Posts: 20

usa.gif
PostPosted: Fri Oct 03, 2014 4:01 am    Post subject: Reply with quote

Hi Glen:

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!
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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