Hi everyone, I'm looking for some help with this code loop. I have gone back to the original code given to me by Kent to see if I can iron out the problem myself (Fat Chance !)
Do While Rx_Input On
wait 12 us
Count = Count + 1
Loop
If count >= 100 Then
Set LED On
delay_10mS
Else
Set LED OFF
End If
count = 0
goto Main
Sub delay_10mS
Wait 10 ms
End Sub
What is happening is that the it is bouncing on the switching point and what it needs is bandwidth between the Switch On and switch Off.
I have tried to include a second IF statement in place of the ELSE which went something like IF count < 90 then Switch Off but with little success,
Ideally I feel this second IF should work giving my the desired bandwidth between 100 being On and 90 being Off but in reality it doesn't work.
Once again any help would be really appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The source is just "one" channel taken from a RC receiver, correct? (i.e. chan1 or chan2, etc.).
The two IF statements should do it, not sure what is going on there. Here is a proposal to try out, and should provide a more positive on/off output? There is no reason to have a 10ms delay in the if statement? The idea is to use the original IF/Else statement, and instead using a digital out set LED off statement, use a digital input with a pull down resistor (10K).
dir LED In
Main:
Do While Rx_Input On
wait 12 us
Count = Count + 1
Loop
If count >= 100 Then
dir LED Out
Set LED ON
Else
dir LED In 'Hi Z LED pin, and pull to ground with use of 10k pull down resistor
End If
count = 0
goto Main
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi once again Kent, thank you for your input which is really appreciated. Firstly, I think the reason why it is troublesome using the two IF Statments is that the switching point is logically Off until the count of 100 or more is reached, if it is at 100 then drops back to 99 it will turn the switching point off. this is what I think is causing the Switch to 'jitter. Secondly, 10 mS second delay gives a more stable output as the Pulse duty cycle is increased to approximately 9:1 . Without it the LEd putput switches On and Off rapidly. I have not tested your solution as yet, but I will do when I get home tonight and get back to you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Doh! The count is getting cleared every time the pulse goes low on the input. Let's try dumping the counter into a newcounter, to just save the valid high pulses.
dir LED In
count = 0
Main:
Do While Rx_Input On
wait 12 us
count = count + 1
Loop
If count > 10 Then newcount = count 'Ignore low periods/noise
count = 0
If newcount >= 100 Then
dir LED Out
Set LED ON
Else
dir LED In 'Use 10k pulldown on this pin
End If
goto Main
To add hysteresis, you would have two different set points, for the two IF statements. This should work with the new counter method above, try this before the pulldown method.
If newcount >= 100 Set LED On
If newcount <= 85 Set LED Off
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By using the values of 88 as On and 85 as Off gives a switching point of 1,650uS and 1,580uS respectively. And, without the 10mS WAIT Statement in the equation ! EXCELLENT. Thanks once again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone, I'm looking for some help with this code loop. I have gone back to the original code given to me by Kent to see if I can iron out the problem myself (Fat Chance !)
Do While Rx_Input On
wait 12 us
Count = Count + 1
Loop
If count >= 100 Then
Set LED On
delay_10mS
Else
Set LED OFF
End If
count = 0
goto Main
Sub delay_10mS
Wait 10 ms
End Sub
What is happening is that the it is bouncing on the switching point and what it needs is bandwidth between the Switch On and switch Off.
I have tried to include a second IF statement in place of the ELSE which went something like IF count < 90 then Switch Off but with little success,
Ideally I feel this second IF should work giving my the desired bandwidth between 100 being On and 90 being Off but in reality it doesn't work.
Once again any help would be really appreciated.
The source is just "one" channel taken from a RC receiver, correct? (i.e. chan1 or chan2, etc.).
The two IF statements should do it, not sure what is going on there. Here is a proposal to try out, and should provide a more positive on/off output? There is no reason to have a 10ms delay in the if statement? The idea is to use the original IF/Else statement, and instead using a digital out set LED off statement, use a digital input with a pull down resistor (10K).
Hi once again Kent, thank you for your input which is really appreciated. Firstly, I think the reason why it is troublesome using the two IF Statments is that the switching point is logically Off until the count of 100 or more is reached, if it is at 100 then drops back to 99 it will turn the switching point off. this is what I think is causing the Switch to 'jitter. Secondly, 10 mS second delay gives a more stable output as the Pulse duty cycle is increased to approximately 9:1 . Without it the LEd putput switches On and Off rapidly. I have not tested your solution as yet, but I will do when I get home tonight and get back to you.
Doh! The count is getting cleared every time the pulse goes low on the input. Let's try dumping the counter into a newcounter, to just save the valid high pulses.
To add hysteresis, you would have two different set points, for the two IF statements. This should work with the new counter method above, try this before the pulldown method.
Ha, my signature sloppy, forgetful coding, where is the edit button :)? Of course I meant:
Hi again. That works a treat !
By using the values of 88 as On and 85 as Off gives a switching point of 1,650uS and 1,580uS respectively. And, without the 10mS WAIT Statement in the equation ! EXCELLENT. Thanks once again.