Encoders

D396

Senior Member

eclectic

Moderator
Without me having read the datasheets,

1. How many segments painted on the wheel?

2. What is the proposed speed of rotation (rps)?

e
 

D396

Senior Member
2 segments but more can be painted.
I'm not sure but fast. It's for an RC car that I'm turning into a robot. It's a Traxxas slash with a CC Sidewinder SCT 3800Kv Motor.
 

D396

Senior Member
In my previous post I realized the 3800Kv means 3800 rpms per volt so with a 8.4V battery that equals around 32000 rpm.
 

eclectic

Moderator
In my previous post I realized the 3800Kv means 3800 rpms per volt so with a 8.4V battery that equals around 32000 rpm.
Hmmm?
At 32000 rpm,and a 2"/50mm wheel
that would give a real F1 a run for it's money!

Get your calculator out.

What's the wheel diameter?
What's the real top speed?

e
 

MartinM57

Moderator
It looks like a bit of a reality check is needed here - your 4" dia. wheels are going round at the same speed as the motor, which at 8.4v is 32,000 rpm.

Circumference = pi * d = ~12" = 1 foot

So in 1 minute, distance travelled = 32,000 feet
So in 1 hour, distance travelled = 60 * 32,000 = 1,920,000 feet == ~363mph.

I suspect there is a gearbox somewhere between the motor and the wheels :D
 

eclectic

Moderator
It looks like a bit of a reality check is needed here - your 4" dia. wheels are going round at the same speed as the motor, which at 8.4v is 32,000 rpm.

Circumference = pi * d = ~12" = 1 foot

So in 1 minute, distance travelled = 32,000 feet
So in 1 hour, distance travelled = 60 * 32,000 = 1,920,000 feet == ~363mph.

I suspect there is a gearbox somewhere between the motor and the wheels :D
That's why I sent post#5.
At 40mph(real) the figures are more reasonable.

e
 

D396

Senior Member
So was 3480 correct? If it was then it should be 58 rps which equals 17? ms between rotations.
Thanks for your help.
 

D396

Senior Member
Should be around 58Hz if it cycles once for every rotation. Also 40mph is best case it can go slower.
 

eclectic

Moderator
I've just skimmed the link from your post #1
It includes
"What resolution to pick? On the one hand, I don't want to overload the processor.
It's got plenty to do: gyro, compass, and ranger sensors have to be updated
in near real time at a fairly high rate, around 20-50Hz.
On top of the fact that a lot of computation will be happening to estimate heading,
position, bearing to waypoint, and so on."


All on an 08M? :-((

e
 

D396

Senior Member
No. I will just have the 08M read the encoders. The output will trigger and interrupt on my main processor (not picaxe) which will be use for navigation. The only thing the 08m will do is convert the encoder to digital pulses instead of analog readings.
 

eclectic

Moderator
No. I will just have the 08M read the encoders.
The output will trigger and interrupt on my main processor (not picaxe) which will be use for navigation.
The only thing the 08m will do is convert the encoder to digital pulses instead of analog readings.
In that case, something along these lines

Code:
#picaxe 08M
setfreq m8

main:
readadc 1, W1

if W1 <128 then
 Pulsout 2,10
 endif


If W1 >=128 then 
Pulsout 4,10
endif

goto main
Untested, as I don't have an encoder.

Or, perhaps buy the digital encoder version?
e
 

MartinM57

Moderator
No. I will just have the 08M read the encoders. The output will trigger and interrupt on my main processor (not picaxe) which will be use for navigation. The only thing the 08m will do is convert the encoder to digital pulses instead of analog readings.
So why not use a simple op-amp schmitt trigger (like the article does) to turn the wandering analogue signal into clean 1's and 0's? (so that, presumably you can do an edge trigger detection on the main processor?)
 

D396

Senior Member
Because I dont have the parts but i have an 08M. For the digital version it changes capacitance not on and off. Thanks E I will try that code later today.
 

eclectic

Moderator
Because I dont have the parts but i have an 08M. For the digital version it changes capacitance not on and off. Thanks E I will try that code later today.
Minor change.

Code:
#picaxe 08M
setfreq m8

main:

readadc 2, W1  ; Schmitt Tr input

if W3 <128 then
 Pulsout 1,10
 endif


If W3 >=128 then 
Pulsout 4,10
endif


stop
 

D396

Senior Member
Thanks shouldn't it be like this?
Code:
#picaxe 08M
setfreq m8

main:

readadc 2, W3  ; Schmitt Tr input

if W3 <128 then
 Pulsout 1,10
 endif


If W3 >=128 then 
Pulsout 4,10
endif

goto main
and what is the reason for pulseout instead of high and low
 

eclectic

Moderator
Thanks shouldn't it be like this?
Code:
#picaxe 08M
setfreq m8

main:

readadc 2, W3  ; Schmitt Tr input

if W3 <128 then
 Pulsout 1,10
 endif


If W3 >=128 then 
Pulsout 4,10
endif

goto main
and what is the reason for pulseout instead of high and low
You are correct.
I tripped over my copy and paste. :-(

Pulsout?
No reason really.
Try both and test.

e
 

MartinM57

Moderator
EC's code will give you lots of pulses on different pins depending on black or white being detected, even when the detected colour is constant. It also doesn't exhibit schmitt trigger dependencies.

In the absence of precise requirements ("just do what a schmitt trigger does"?) I would suggest

Code:
#PICAXE 08M
SYMBOL counter = b0
SYMBOL adcValue = b1
SYMBOL digitalValue = b2
SYMBOL currentState = b3
SYMBOL debounceCount = 10 ;or whatever

init:
currentState = 0 ;assume initial state of output is 0

main:
readadc 1, adcValue

;convert analogue value to digital value
if adcValue > 128 then
  digitalValue = 1
else
  digitalValue = 0
endif

;schmitt trigger cleverness
if digitalValue = currentState and counter > 0 then 
	DEC counter
endif
if digitalValue <> currentState then 
	INC counter
endif

;if the Input has shown the same value for long enough, switch it
if counter >= debounceCount then
      counter = 0
      if digitalValue = 1 then : high 2 : else : low 2: endif
endif

goto main
 
Last edited:

MartinM57

Moderator
The key test will be what happens when the sensor is dithering around the black/white border. In my code, you can adjust the value of debounceCount (up to 255 max) to "slug" the response and minimise false triggering

...and my code only outputs on one pin ;)
 

D396

Senior Member
While this is the code I came up with based of off eclectic's code. For some reason martin's didn't work. I had t adjust the ADC values of eclectic's and switch from pulse out to high and low. It works without a rotating wheel just moving back and forth in between white and black.
Code:
#picaxe 08M
setfreq m8

main:

readadc 1, W3  ; Schmitt Tr input

if W3 <245 then
 low 2
 endif


If W3 >=245 then 
high 2
endif

goto main
 

MartinM57

Moderator
Oops.

You should definitely need schmitt trigger behaviour so setting debounceCount to 0 is not the right thing to do...
...but there is an error in the code :embarassed:

Try
Code:
#PICAXE 08M
SYMBOL counter = b0
SYMBOL adcValue = b1
SYMBOL digitalValue = b2
SYMBOL currentState = b3
SYMBOL debounceCount = 10 ;or whatever

init:
currentState = 0 ;assume initial state of output is 0

main:
readadc 1, adcValue

;convert analogue value to digital value
if adcValue > 128 then
  digitalValue = 1
else
  digitalValue = 0
endif

;schmitt trigger cleverness
if digitalValue = currentState and counter > 0 then 
	DEC counter
endif
if digitalValue <> currentState then 
	INC counter
endif

;if the Input has shown the same value for long enough, switch it...
if counter >= debounceCount then
      counter = 0
      ;...to the current digital value
      if digitalValue = 1 then : high 2 : else : low 2: endif
      [B][I];...and remember the state for next time
      currentState = digitalValue[/I][/B]
endif

goto main
 

D396

Senior Member
early testing on the bot shows that martin's code works (Thanks) but it has to be at 8mhz and debounce = 2 but it works perfectly. Thanks.
 

D396

Senior Member
debounce has to be lower because at high speeds the rpm is so high that it ignores complete rotations.
 

MartinM57

Moderator
@D396

It troubled me through the night that I have advertised some debouncing code as schmitt trigger code :( ....
...the previous code was an analogue debouncing algorithm where the simple digital interpretation of the analogue input must change for a certain amount of time before the output is switched

However, a traditional schmitt trigger algorithm is that the digital output switches on above some analogue input threshold but does not switch off until the analogue input value is below some lower threshold.

Hence the new code (untested):
Code:
;Schmitt trigger code
#PICAXE 08M
SYMBOL adcValue = b0
SYMBOL currentState = b1
SYMBOL lowThreshold = 100 ;or whatever
SYMBOL highThreshold = 156 ;or whatever

init:
currentState = 0 ;assume initial state of output is 0

main:
readadc 1, adcValue

;schmitt trigger cleverness
if adcValue >= highThreshold and currentState = 0 then
  high 2
  currentState = 1
endif

if adcValue <= lowThreshold and currentState = 1 then
  low 2
  currentState = 0
endif

goto main
Would be interested in the practical results of using this in your bot...

I'm sure someone could combine the two sets of code to give debounced schmitt trigger detection, which is an interesting technique.

I shall sleep soundly tonight.
 

eclectic

Moderator
A genuine question:
could something like this work?
I can't test using an encoder, but I've
tried an AXE091 setup.

18M2 provides pwmout at ~64 Hz
08M inputs on pin2 (ST)
Outputs on
pin1 (copies)
Pin4 (opposite)

Tested on a cheaposcope.
(Not like Martin's Wizzoscope :)

Code:
;forum
;http://www.picaxeforum.co.uk/showthread.php?p=172330#post172330

#picaxe 08M
let dirs = %00010011

do
	pin1 = pin2
	pin4 = not pin2
loop

;pin2 ST input
;pins 1 and 4 outputs

;pin 1 follows input 2
; pin4 opposite



#rem
;64.5 Hz source
#picaxe 18M2

pwmout B.3, 129, 260  ; pwmout 7680 kHz
pause 10

setfreq k31

do : loop
e
 
Last edited:

MartinM57

Moderator
Nice idea to use the onboard ST digital inputs Ec.

KISS always applies.

Definitely worth a test in the bot with the "noisy" analogue detector outputs
 

D396

Senior Member
The schmitt trigger works. Thanks martin. Eclectic, I don't understand what your code is doing. Would you mind explaining it. Thanks for the help guys.
 

eclectic

Moderator
The schmitt trigger works. Thanks martin. Eclectic, I don't understand what your code is doing. Would you mind explaining it. Thanks for the help guys.
Have you tried it?
If so, does it work?

Quick exp:
1. While pin2 is high, Pin1 is high.
While pin2 is low, Pin1 is low.

2. Pin4 outputs the opposite of Pin2.

What sort of signal(s) does your
main processor require?

e
 

MartinM57

Moderator
The key thing in Ec's second code set is that the input pin being used is actually a schmitt trigger input (reads high at a certain threshold, doesn't read low until the input has gone below a lower threshold). Other than that, Ec's code just copies the input to the output (and an inverted version - just because it can :))

This electrical schmitt trigger effect is just what the opamp comparator in the referenced web page did.

My code is a software schmitt trigger using READADC to determine the input voltage and explicitly testing it against the high/low thresholds
 

D396

Senior Member
I didn't test it because I didn't know how to wire it. How should I? The main cpu requires a square wave.
 
Top