Shop OBEX P1 Docs P2 Docs Learn Events
trouble with encoder obex... — Parallax Forums

trouble with encoder obex...

kutalinelucaskutalinelucas Posts: 80
edited 2011-08-15 02:07 in Propeller 1
I've been trying to use the "Quadrature encoder" method from the parallax obex (http://obex.parallax.com/objects/24/), but even though it is very well documented, I'm having difficulties getting it working and was wondering if somebody could see where I'm going wrong...

I have a faulhaber motor (micromo 1624...s) with a built in 2-channel magnetic encoder with 10 pulses/revolution.

All I'm looking to do at the moment is turn the motor untill the encoder returns a set amount of pulses, but I've been working so long now I can't see the wood for the trees...
VAR
  word Ratio
  long Stack[9]
  long Pos[2]                                     'create buffer for 1 encoders + delta
  long Encoder_count
OBJ
  Encoder : "Quadrature Encoder"
PUB Init
  Encoder.Start(11, 1, 0, @POS)
PUB Main
  Ratio := 18000
PUB Toggle  |   Time
  Time := cnt
repeat WHILE (Encoder_count < 50)                                        
  Encoder_count := POS[0]
  waitcnt(Time += 20000 - Ratio)
  OUTA[10]~~                                            'motor1
  waitcnt(Time += Ratio)
  OUTA[10]~                                             'motor2
 
Encoder.Stop
OUTA[10]~
RETURN

POS[0] doesn't seem to leave zero, and i've tried different encoders to no avail...

Any ideas would be brilliant

Comments

  • kutalinelucaskutalinelucas Posts: 80
    edited 2011-08-14 15:05
    I've just noticed on the encoder data sheet that I have to put a transistor between the output and ground, so I think I'll have to order some bits to get it going...
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-14 15:16
    How about just testing if the encoder delivers incrementing values?

    Your program is still small but already includes a lot of variabilities which could cause the problem.

    The main strategy for problem solving is narrowing down the areas where the problem could be.

    So a first test-prg would only do
    CON
      _clkmode = xtal1+pll16x
      _clkfreq = 80_000_000
    
    
    VAR
      long Pos[2]                                     'create buffer for 1 encoders + delta
      long counter
    
    OBJ
      fdx     : "FullDuplexSerialPlus"
      Encoder : "Quadrature Encoder"
    
    
    PUB TestEncoder
      fdx.start(31,30,0,115200)
      Encoder.Start(11, 1, 0, @POS)
    
      counter := 0
      repeat
        fdx.dec(counter)
        fdx.tx(" ")
        fdx.dec(POS)
        fdx.tx(13)  'carriage return
        counter := counter + 1
        WaitCnt(ClkFreq / 2 + cnt)
    

    Did you do something similar to check if the encoder-object delivers positions?

    keep the questions coming
    best regards

    Stefan
  • kutalinelucaskutalinelucas Posts: 80
    edited 2011-08-14 17:21
    hey Stefan. This is my first day with spin and my program is already considerably larger than I think i'm ready for...this is one of 5 objects in 3 cogs! to be honest that test code you posted is above my head at the moment, I have however tested the encoders by playing with the conditional statement...and the only one which seems to trigger is IF(pos[0] == 0). I was buggering around with this for a few hours then finally tracked down a data sheet for these motors/encoders (I bought them surplus). The document shows that there should be a bjt transistor between each channel and ground, and a 10k resistor leading to vss...which kind of makes sence as there way no voltage drop across the encoder channels when the motor was spinning. DC circuit theory isn't really my forte so I would never have guessed it. I've ordered some transistors so I'm hoping I will get better results once I've sorted the switching out. Thanks for getting back to me.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-08-14 17:42
    faulhaberencoder.JPG
    I've just noticed on the encoder data sheet that I have to put a transistor between the output and ground, so I think I'll have to order some bits to get it going...

    I have some Faulhaber 16/3k minimotors. They have encoders, but they don't need external transistors.
    726 x 297 - 34K
  • kutalinelucaskutalinelucas Posts: 80
    edited 2011-08-14 18:03
    ahhh...the data sheet I found is almost identical, just laid out a little different. So would I just pull the vcc to +5v; ground to common; and the 2 enocder outputs directly to consecutive prop pins? I thought vcc needed to be connected to the collector of a transistor...

    I was buggering about with the prop program for quite sometime tonigh and i assumed the missing transistor was the problem because the motor PWM routine would only trigger if POS[0]== 0, so the encoder wasn't acatually switching...Either that or I'm not calling the method correctly
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-08-14 18:42
    Right.
    The/Their Vcc could go to 3V3, GND to Vss (Prop Gnd), and the ChannelA/Bs to Prop inputs.
    The encoder outs are pulled up (de rigeur common emitter switches) so everything is in readiness.

    If you run the motor slowly, you should be able to see the outputs change states with a voltmeter
  • kutalinelucaskutalinelucas Posts: 80
    edited 2011-08-15 02:07
    Thanks...I'll give that a try now
Sign In or Register to comment.