Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Timeout for a bitwait

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Yokablasta

Bascom Member



Joined: 13 Dec 2017
Posts: 19

PostPosted: Tue Jan 22, 2019 12:21 pm    Post subject: Timeout for a bitwait Reply with quote

Hello all,
I've got a product that reads incoming serial messages from some 1980's hardware. Some users decided that they wanted to use longer cable lengths between my reader and the device, which is causing issues, because of the capacitance added by the additional cable length. This is causing clock pulses not to get read by my device. Right now, the routine that gets called is this:



Code:
programmerserialtransmit:
If progstate <> 1 Then
Set Nready
For Temp_b = 1 To 8
    Bitwait Nclk_in , Set                                   'can't use shift out; with the READY construction                                      'Wait for rising clock
    Data_out = Not progchannel.7
    Bitwait Nclk_in , Reset
    If Temp_b = 7 Then
       Reset Nready
    End If
    Shift Progchannel , Left , 1
Next
End If
Return



When the clock signal gets beaten down by the excessive cable length, my unit halts when it hits the first bitwait Nclk. I'm trying to figure out what the best way is to insert a "timeout" where if more than 10ms have elapsed, then it just exits the programmerserialtransmit label. Does anybody have experience with this sort of issue?

(BASCOM-AVR version : 2.0.8.1 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Tue Jan 22, 2019 5:57 pm    Post subject: Reply with quote

Create your own Bitwait and let it count up a variable while it waits, if the variable rolls over a certain limit (your 10ms), set a flag.
Use no delay within the count-up loop, simply use a variable big enough, the used up processor cycles will do your delay.
Include a check of the flag in every custom Bitwait and into the 1to8-loop.
Get rid of For/Next and use a Do/Loop or While/Wend, as you can include the flag as break condition there, don't forget to count up b yourself.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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