I am trying to stabilize the speed of a motor by reading an attached Hall detector and then feeding the right PWM.
It all works except for some strange behavior of the PulseIn command.
I made a setup with a second pic to provide PortA.5 with a fixed pulse (21 mS, 24Hz).
A logic analyzer on PortA.0 shows the content of the HSerprint commands.
#chip 12F1840,16
#define Sensor PORTA.5
dir Sensor In
dim SensorSpeed as Byte
'USART settings
#define USART_BAUD_RATE 2400
#define USART_TX_BLOCKING
SCKP = 1 ' Invert Tx Bit
Do
'wait for rising edge
Do while Sensor=off
Loop
PulseIn Sensor, SensorSpeed, ms
HSerPrint SensorSpeed
Loop
The LA shows that at the end of the positive pulse on channel 1 there is the serial print showing "21" on channel 0
After inserting a wait command the recorded pulse is much shorter:
#chip 12F1840,16
#define Sensor PORTA.5
dir Sensor In
dim SensorSpeed as Byte
'USART settings
#define USART_BAUD_RATE 2400
#define USART_TX_BLOCKING
SCKP = 1 ' Invert Tx Bit
Do
'wait for rising edge
Do while Sensor=off
Loop
PulseIn Sensor, SensorSpeed, ms
HSerPrint SensorSpeed
Wait 75mS
Loop
Frequency is the same, pulse width is still 21mS,
but GCB measures only 7mS pulse now, see attachment.
"I made a setup with a second pic to provide PortA.5 with a fixed pulse (21 mS, 24Hz)"
24Hz is 41.666666666667 ms
I'm vague about prob. pulsein is frequency independant in gcb..yes? are your pulsein values ok..like ms. just thoughts
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to stabilize the speed of a motor by reading an attached Hall detector and then feeding the right PWM.
It all works except for some strange behavior of the PulseIn command.
I made a setup with a second pic to provide PortA.5 with a fixed pulse (21 mS, 24Hz).
A logic analyzer on PortA.0 shows the content of the HSerprint commands.
The LA shows that at the end of the positive pulse on channel 1 there is the serial print showing "21" on channel 0
Last edit: JohanDenRidder 2018-01-28
After inserting a wait command the recorded pulse is much shorter:
Frequency is the same, pulse width is still 21mS,
but GCB measures only 7mS pulse now, see attachment.
Last edit: JohanDenRidder 2018-01-28
"I made a setup with a second pic to provide PortA.5 with a fixed pulse (21 mS, 24Hz)"
24Hz is 41.666666666667 ms
I'm vague about prob. pulsein is frequency independant in gcb..yes? are your pulsein values ok..like ms. just thoughts
Stan, please check the attached images. As you can see, the positive pulse is 21mS.
One cycle is 42mS, so just a little over 24Hz.
Last edit: JohanDenRidder 2018-01-28
Johan,
Your code for waiting for the rising edge doesn't check that the signal is low before rising.
So if the sensor is already on , it will go directly to pulseIn and only measure what is left of the pulse.
Oops, you are right.
I took this snippet from the help page without thinking for myself...
Thanks,
Johan