chipKIT® Development Platform

Inspired by Arduino™

Uno32 and Interrupts

Created Mon, 15 Apr 2013 14:32:29 +0000 by mortto


mortto

Mon, 15 Apr 2013 14:32:29 +0000

I know this question was raised a few time in the forum, but somehow it didnt help me fix my problem... I guess because I didnt understand the code that the people ware discussing very well.

So I hope you guys show some patience with me :)

Here is my problem:

I am trying to read an rotation encode from a device. It sends 5V digital signal in pulses at a rate of 3Khz per channel at maximum speed. There are 2 channels, 90° shift in order to get the orientation direction.

I tried to read the encoder with a Arduino (interrupt based code) and it works fine at low speed, but as soon as the encoder speeds up.. the Arduino starts loosing signals. Thats why I wanted to use the Uno32, since the higher speed should fix that problem.. but it seems that the Arduino code doesnt work on Uno32. It compiles fine, no problems at all.. it just doesnt do anything.

So here is my request :) Can anyone show me a simple interrupt example for an Uno32? Simple as this... when 1 of the interrupt pins goes high, the Uno should execute a simple function like LED on.

I am sure the basic Arduino commands work all fine.. it seems just like the interrupts dont work as they do on Arduino.

The other solution was to get an quadrature encoder IC that does the work and go back to Arduino, but a) farnell doesnt have many of them.. in fact I found only 1, and its looks like overkill for my little task here... and b) I would like to use more Uno32 anyway... so I guess it not wrong to try and realise this small project there.


majenko

Mon, 15 Apr 2013 15:31:41 +0000

Have you taken into account the UNO32 has the interrupts on different pins?

External Interrupts: Pin 38 (INT0), Pin 2 (INT1), Pin 7 (INT2), Pin 8 (INT3), Pin 35 (INT4)

The interrupt code should operate just the same on the chipKIT as it does on the arduino.


mortto

Mon, 15 Apr 2013 15:58:09 +0000

I did.. I used Pin2 and Pin8 for all my tests.

Here is my example Code that I used on Arduino:

void setup() { pinMode(13, OUTPUT); pinMode(18, INPUT); attachInterrupt(5, LedOn, HIGH); digitalWrite(13, LOW); }

void loop() {

}

void LedOn() { digitalWrite(13, HIGH); }

even if I modify the code for Pin8 and Int3, nothing happens. Code compiles fine tho.


majenko

Mon, 15 Apr 2013 16:06:31 +0000

HIGH is not a valid edge for an interrupt.

Interrupts can only be RISING, FALLING or CHANGE. They are all "edge" triggered, not level triggered.

The following code works fine for pin 2:

void setup() 
{
  pinMode(13, OUTPUT);
  pinMode(2, INPUT);
  attachInterrupt(1, LedOn, RISING);
  digitalWrite(13, LOW);
}

void loop()
{
}

void LedOn() 
{
  digitalWrite(13, HIGH);
}

mortto

Mon, 15 Apr 2013 16:15:24 +0000

man... I did try that, I swear I did try RISING and FALLING and CHANGE.. even tho I have read that CHANGE may not work for some reason... how ever.. it NEVER worked for me.

I have no idea why it does now -.-

How ever.. I own you a beer!! Your ebay shop doesnt offer much that I could use, but a R3 Shild for Arduino can never be wrong :)

Thanks alot man!!

ps: there must be a problem with the shipping costs ... maybe you can fix that? :)


majenko

Mon, 15 Apr 2013 16:17:59 +0000

man... I did try that, I swear I did try RISING and FALLING and CHANGE.. even tho I have read that CHANGE may not work for some reason... how ever.. it NEVER worked for me. I have no idea why it does now -.- How ever.. I own you a beer!! Your ebay shop doesnt offer much that I could use, but a R3 Shild for Arduino can never be wrong :) Thanks alot man!!

The shop's a bit scant at the moment I'm afraid. I have plenty of products on the horizon, but just never seem to find the time to finalize them...

I'm down to my last few R3 shields. I need to order another batch really...