chipKIT® Development Platform

Inspired by Arduino™

Interrupts on Uno32 not functioning using Encoder H lib

Created Thu, 09 Jan 2014 20:27:27 +0000 by Bartje64


Bartje64

Thu, 09 Jan 2014 20:27:27 +0000

Going from Arduino Uno to Chipkit Uno32 (for more I/O). I'm finding some issues. Hence I have a request for some help.

The Arduino Uno uses pin2 and 3 for the interrupt and the code ran fine with this.

On the Chipkit Uno32 I cannot get it to work and am lost as to why? I am trying to read an encoder, very simple.

On the Chipkit, if I use a combination of 5,6 or 6,7 or 8,9 for the pins, I get output on the Serial monitor. However these are not combinations of 2 interrupts. I cannot use this in my main code since it causes "misses" in the encoder position changes.

If I use 7,8 which are interrupts on the Chipkit, I get no output on the Serial monitor.

The code below is snippets out of my main code, just to keep it simple and short for testing. I'm hoping for some help so I can set this up correctly using pins 7,8 as interrupts on the Chipkit.

Thanks, Bart

//********** Chipkit or Arduino Mega 2560 ***********//
#include <Encoder.h>
//*****************************// 


//********** ChipkitUno32 ***********// 
Encoder myEnc(7, 8);      
//***********************************// 

//********** Chipkit or Arduino Mega 2560 ***********// 
long oldPosition  = 0;
long newPosition = 0;
int EncoderSensitivity = 10;
//***************************************************//


void setup(){

Serial.begin(9600);
}

void loop(){
  //********** Chipkit or Arduino Mega 2560 ***********//
  
  newPosition = myEnc.read();
  if (newPosition != oldPosition) { 

    if (newPosition >= (oldPosition + EncoderSensitivity)){
      Serial.println("ccw");

      oldPosition = newPosition;
    }
    if (newPosition <= (oldPosition - EncoderSensitivity)){
      Serial.println("cw");

      oldPosition = newPosition;
    }
  }
}

majenko

Thu, 09 Jan 2014 20:41:11 +0000

Where is this Encoder.h library?


Bartje64

Thu, 09 Jan 2014 21:31:57 +0000

Got it from here for the Arduino, also seems to works with the Chipkit Uno32. I don't know if the issue is with this library or not that i cannot use 7,8 on the Chipkit.

http://www.pjrc.com/teensy/td_libs_Encoder.html

Bart


majenko

Thu, 09 Jan 2014 21:43:32 +0000

Ok. Do you have pullup resistors attached to pins 7 and 8?


Bartje64

Thu, 09 Jan 2014 21:59:20 +0000

No I do not have pull-ups attached to 7 and 8. Should there be?


majenko

Thu, 09 Jan 2014 22:01:32 +0000

Yes. Those pins don't have internal pullups available, and the library normally relies on them.


Bartje64

Thu, 09 Jan 2014 23:30:19 +0000

Wow thanks for the info. Out of curiosity is there a comparison chart of sorts with Arduino, Chipkit that "identifies" these type of differences ? It seems that would make it a bit easier then pulling your hair out as to why it's not working.

I will try the pullups and see what happens, thanks again for the info.

Bart


Bartje64

Fri, 10 Jan 2014 01:58:38 +0000

Well...no dice. Installed pullups on 7 and 8, same result...grrrr tried pulldowns as well...nada..

Went back to the Arduino, now it's not working either. Toasted the encoder with the pull-ups. Applying a voltage to the output pins of the encoder is a no-no....


majenko

Fri, 10 Jan 2014 10:41:20 +0000

How can you toast an encoder by adding pullup resistors? Or is it some kind of strange active encoder with its own digital processing hardware built in? All the encoders I have seen have been simple mechanical switches, or at worst old ball mice with infra-red beams. I fail to see how a pullup resistor can do any damage at all to those, unless you have done something silly like used a 5Ω resistor to pull an infra-red LED up to 12V...


Bartje64

Fri, 10 Jan 2014 15:53:47 +0000

It's an optical encoder, no mechanical contacts inside. Did not think about it when I put the pull-ups on.......oops...

Still do not understand why it would work on these pin combos of 5,6 or 6,7 or 8,9 but not on 7,8 together. If it needed pull-ups they were not there on the 6,7 and 8,9 combos either yet it worked albeit to slow...

I don't know enough code nor can write my own library for using the Chipkit interupts with an encoder, so I've got to keep looking...

Specs on encoder Manufacturer: Oak / Grigsby Model: 91Q128-43-00110 2 channel full quadrature encoding 128 pulses per revolution - 512 total changes of state per revolution Compatible with TTL logic - VCC = 5V Output: 2-bit gray code – Channel A leading Channel B by 90 degrees in clockwise rotation Power consumption: 250 mW maximum


jmlynesjr

Fri, 10 Jan 2014 20:48:13 +0000

Look at http://github.com/jmlynesjr/chipKIT-Arduino-Examples for several examples. RotaryEncoderISR4.pde - Sparkfun Rotary Encoder Driver - Interrupt Version

James


Bartje64

Sun, 12 Jan 2014 01:12:04 +0000

James,

Thanks for the link. I made significant headway using the examples. Using analog 0 and 1 it is working.

Bart


jmlynesjr

Sun, 12 Jan 2014 21:39:10 +0000

Great! Glad it helped.

James