30 May 2007 dwhall   » (Master)

I ordered some motors from BG Micro at 3pm on Thursday last week. They arrived two days later at noon via the USPS! They are small MicroMo motors with Faulhaber gearboxes and, best of all, built-in magnetic quadrature shaft encoders.

I made the following measurements on just one of the motors using a crappy DMM:

  • No load current @ 5 V: 18 mA
  • Stall current @ 5 V: 180 mA
  • Angular vel @ 5 V: 84 RPM
  • Encoder output (low, high): 0.25 V, 4.87 V

Then today, I connected the encoder output (ChA only for testing) to pin PE4 on my Atmel ATmega103. I used that input so I could get edge-triggered interrupts. I wrote an interrupt handler in C that incr/decrements a 16-bit counter variable. The main program prints the counter variable to an LCD once every second. Here is the code (minus comments so it all fits):


#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>


#include "libmmb103.h"

volatile int16_t encoderCount;

void init(void) { encoderCount = 0; DDRE = DDRE & ~(_BV(PE4) | _BV(PE5)); EICR = EICR | _BV(ISC41); EIMSK = EIMSK | _BV(INT4); sei(); }

ISR(INT4_vect) { uint8_t chBA;

chBA = (PINE >> 4) & (uint8_t)0x03; if ((chBA == 1) || (chBA == 2)) { encoderCount++; } else { encoderCount--; }

EICR = EICR ^ _BV(ISC40); }

int main(void) { init(); mmb_init(BAUD19200, ADC_CK_DIV_16, PWM_CK_DIV_8, 2); mmb_lcdPrintStr("EncA:");

for (;;) { mmb_lcdSetLine(1); mmb_lcdPrintHex16((uint16_t)encoderCount); mmb_sleepms(500); } }

Latest blog entries     Older blog entries

X
Share this page