I am using 18f27k40 chip, I have the LCD working (via I2C) so here is the setup.
I am working on a line follower that follows a rotary laser (commercial unit) If the receiver is dead center on the line I get a constant high, if to the left I get 50ms pulses at 8 Hz rep rate. If to the right of the line I get 100ms pulses at 4.4 Hz rep rate.
I need a discriminator type code that will provide high B.6 for right, High B.5 for left, high B.4 for “on the path” steady high, and a high B.3 for no pulses and is zero level( 0 pulses.)
.
My current logic flow would be:
Pulse rec'd > 10ms but < 40ms, send right cmnd B.6
Pulse rec'd > 10 ms but > 80 ms, but < 60 ms, then send left cmnd B.5
Signal is Steady High, send “On the Line” B.4
Steady low send “Shut Down Mtr” B.3 (This would be a signal we are way off course and cannot recover, so we are lost)
The current code is attached but I have stripped out my feeble attempts at discriminating the pulses because I never got even close. It was a confusing mashup illogical code of counters and loops.
I don't expect you to fix my code, just some code snippit that I can use and edit.
In the scope pictures, the lower waveforms are what the PIC will receive.
Paul
It is early for me. I didn't consider the other two cases . continuous and none.
Here is untested code using a modified PulseIn sub making it your own.
MAINCONTROL:doADC_VAL=ReadAD10(AN5)xspeed=ADC_VAL;Thiswillbeusedlaterforcorrectionrate;===========================OLDCODEREMOVED=========================='Pulse rec'd>10msbut<40ms,sendrightcmndB.6'Pulse rec'd>10msbut>80ms,but<60ms,thensendleftcmndB.5'Signal is Steady High, send “On the Line” B.4'Steadylowsend“ShutDownMtr”B.3(Thiswouldbeasignalwearewayoffcourseandcannotrecover,sowearelost)MyPulseIn(MyTimeResult)'pulse input A.2 (pin4) Select Case MyTimeResult Case 0 to 5 code1 '“ShutDownMtr”B.3Case5to20code2'send right cmnd B.6 Case 30 To 40 code3 'thensendleftcmndB.5CaseElsecode4'“On the Line” B.4 End Select loop ;and start over again;======================================================================;----- Subroutines ---------------------------------------------------'ThisisamodifiedpulseinforyourapplicationsubMyPulseIn(MyPulseTimeasWord)myPulseTime=0DoWhilePortA.2=OnWait1msmyPulseTime+=1IfmyPulseTime=0ThenExitDoIfmyPulseTime>=100ThenExitDo' so don'tgetstuckincontinuoustoneLoopendSubsubcode1endsubsubcode2endsubsubcode3endsubsubcode4endsub
Hope You can see what I was trying to do.
GL
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
DowhileGPIO.0=Off'Wait for next positive edge to start measuringLoopPulsein GPIO.0, TimeResult, msif TimeResult < 75 then code for 50else if TimeResult >150 then code for highelse code for 100end if
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Stan and Mike, that pulsein should really solve my problem. I was stuck and trying to kludge code with loop counters and even interrupts/timercounters which all was getting to much for this feeble mind.
After I fully understand "PulseIn" and some bench top testing I will be off and running using "case" or "if-then-else" statements to sort out "direction/stop/lost" of the line follower.
Last edit: Paul Haug 2019-05-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Stan, excellent point about Pulsein remaining high. I will do some testing and let you know. If it gets stuck I can always use Mikes suggested code as follows:..
'This is a modified pulsein for your application
sub MyPulseIn ( MyPulseTime as Word)
myPulseTime = 0
Do While PortA.2 = On
Wait 1 ms
myPulseTime += 1
If myPulseTime = 0 Then Exit Do
If myPulseTime >= 100 Then Exit Do ' so don't get stuck in continuous tone
Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can't get Pulsein to co-operate. See attached code listing.
If I remove the skip_around (line 106) the test LED stops blinking, sort of hangs in pulsein cmnd ?
Maybe something in my setup config line (25) is wrong ?
Any suggestions where I went wrong ?
Paul
EDIT: Using the latest compiler, downloaded yesterday. 0.98.05
your code has PulsePin=1 and PulsePin =off
; Following is for testing only, lights LED 7for PulseIn high
If PulsePin = 1 then
TestLED = 1
else
TestLED = 0
End if
;*******
;Testing pulsein cmnd stuff
;goto skipit ;debug test to allow PortB.7 to follow PulsePin
Do while PulsePin = off 'Wait for positive to start measuring
Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Stan,
Your note said > your code has PulsePin=1 and PulsePin =off
I must be an idiot, but I can't see anywhere I set PulsePin on or off. It is strictly an input pin I hope.
Reviewed the code line by line and with search, still can't see the problem. Could you please lead me out of my confusion, maybe point out the line numbers where I have gone astray. ?
This is on a hardware setup, see attachment if your curious. Unit on right is a presion pulse generato to simulate the line scanner reciever.
Paul,
We needed a way to wait for the pulse that may never be there.(which is your Motor off condition). So measuring the off time is the way. MyPulseInInv is a special case of PulseInInv.
When we have a pulse then we need to measure it. If it is longer than 100ms just return 101 ms so you know to go straight ahead. Again MyPulseIn is a special case.
Thanks Mike,
Pluged your code in and it works in the hardware. Needed some tweaking for the display as it was the recipical(?) of the pulse width. .. Chngd code to "print 100 - MyOffTime"
Late and I am tired so tomarrow I will study your code for the solution I need.
Many thanks for your support.
Paul
Last edit: Paul Haug 2019-05-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using 18f27k40 chip, I have the LCD working (via I2C) so here is the setup.
I am working on a line follower that follows a rotary laser (commercial unit) If the receiver is dead center on the line I get a constant high, if to the left I get 50ms pulses at 8 Hz rep rate. If to the right of the line I get 100ms pulses at 4.4 Hz rep rate.
I need a discriminator type code that will provide high B.6 for right, High B.5 for left, high B.4 for “on the path” steady high, and a high B.3 for no pulses and is zero level( 0 pulses.)
.
My current logic flow would be:
Pulse rec'd > 10ms but < 40ms, send right cmnd B.6
Pulse rec'd > 10 ms but > 80 ms, but < 60 ms, then send left cmnd B.5
Signal is Steady High, send “On the Line” B.4
Steady low send “Shut Down Mtr” B.3 (This would be a signal we are way off course and cannot recover, so we are lost)
The current code is attached but I have stripped out my feeble attempts at discriminating the pulses because I never got even close. It was a confusing mashup illogical code of counters and loops.
I don't expect you to fix my code, just some code snippit that I can use and edit.
In the scope pictures, the lower waveforms are what the PIC will receive.
Last edit: Paul Haug 2019-05-02
Paul,
PulseIn in a GCB keyword so you can't use it for a variable.
So GCB has a PulseIn command
This will give half of the time because it is only measuring the pulse.
There is also a PulseInv command.
Some If - Else If s should set your outputs
Is this enough?
BR
Mike
Paul
It is early for me. I didn't consider the other two cases . continuous and none.
Here is untested code using a modified PulseIn sub making it your own.
Hope You can see what I was trying to do.
GL
Mike
Thanks Mike, that should get me rolling afain. Forgot about "pulsein", so need to work with that and your other suggestions.
Paul
From help-
Dir GPIO.0 In
Dim TimeResult as WORD
Thanks Stan and Mike, that pulsein should really solve my problem. I was stuck and trying to kludge code with loop counters and even interrupts/timercounters which all was getting to much for this feeble mind.
After I fully understand "PulseIn" and some bench top testing I will be off and running using "case" or "if-then-else" statements to sort out "direction/stop/lost" of the line follower.
Last edit: Paul Haug 2019-05-03
re else if TimeResult >150 then code for high
I don't know what pulsein does if the pin is constantly high???
Stan, excellent point about Pulsein remaining high. I will do some testing and let you know. If it gets stuck I can always use Mikes suggested code as follows:..
'This is a modified pulsein for your application
sub MyPulseIn ( MyPulseTime as Word)
myPulseTime = 0
Do While PortA.2 = On
Wait 1 ms
myPulseTime += 1
If myPulseTime = 0 Then Exit Do
If myPulseTime >= 100 Then Exit Do ' so don't get stuck in continuous tone
Loop
I can't get Pulsein to co-operate. See attached code listing.
If I remove the skip_around (line 106) the test LED stops blinking, sort of hangs in pulsein cmnd ?
Maybe something in my setup config line (25) is wrong ?
Any suggestions where I went wrong ?
Paul
EDIT: Using the latest compiler, downloaded yesterday. 0.98.05
Last edit: Paul Haug 2019-05-03
your code has PulsePin=1 and PulsePin =off
; Following is for testing only, lights LED 7for PulseIn high
If PulsePin = 1 then
TestLED = 1
else
TestLED = 0
End if
;*******
;Testing pulsein cmnd stuff
;goto skipit ;debug test to allow PortB.7 to follow PulsePin
Do while PulsePin = off 'Wait for positive to start measuring
Loop
Stan,
Your note said > your code has PulsePin=1 and PulsePin =off
I must be an idiot, but I can't see anywhere I set PulsePin on or off. It is strictly an input pin I hope.
Reviewed the code line by line and with search, still can't see the problem. Could you please lead me out of my confusion, maybe point out the line numbers where I have gone astray. ?
This is on a hardware setup, see attachment if your curious. Unit on right is a presion pulse generato to simulate the line scanner reciever.
Last edit: Paul Haug 2019-05-03
Paul,
We needed a way to wait for the pulse that may never be there.(which is your Motor off condition). So measuring the off time is the way. MyPulseInInv is a special case of PulseInInv.
When we have a pulse then we need to measure it. If it is longer than 100ms just return 101 ms so you know to go straight ahead. Again MyPulseIn is a special case.
Check attached code. it compiles but not tested.
Br
Mike
Thanks Mike,
Pluged your code in and it works in the hardware. Needed some tweaking for the display as it was the recipical(?) of the pulse width. .. Chngd code to "print 100 - MyOffTime"
Late and I am tired so tomarrow I will study your code for the solution I need.
Many thanks for your support.
Paul
Last edit: Paul Haug 2019-05-04
AWWW Jeezzz, it just hit me, that is the OFFTIME, not the on time of the pulse.