chipKIT® Development Platform

Inspired by Arduino™

Interrupt output

Created Sat, 07 Jul 2012 18:56:44 +0000 by soulid


soulid

Sat, 07 Jul 2012 18:56:44 +0000

Hi, I want to put a I/O to high with a microseconds delay after an interrupt orrcured. The delay is individual and will change frequently.

My issue is that the signal shall be as time accurate as possible and I do not want to use the "delay" command. Is there another command available?


JordanR

Mon, 09 Jul 2012 18:11:10 +0000

Hello soulid,

delay() is a millisecond delay. You can use delayMicroseconds(unsigned int us) if you would like.

Or you can set up a timer with a 1:8 prescale. Then you can use ReadTimer'x'() and compare it to 10. Each time ReadTimer'x'() == 10 clear TMRx register and count 1 microsecond.

Best Regards,

Jordan R Digilent


soulid

Sun, 22 Jul 2012 20:15:41 +0000

I agree. I tried that on my Duemilanove with that:

unsigned long first;
unsigned long second;
unsigned long result;

void setup()
{ Serial.begin(9600);}

void loop()
{ first= micros();
  delayMicroseconds(10);
  second= micros();
  result= second-first;
  Serial.println(result);}

The result changes between 12 and 16 (so wrong value as well as instable as well as in steps of 4 :( ). How is the UNO32 reacting on that?


JordanR

Mon, 23 Jul 2012 19:39:14 +0000

Hello soulid,

I ran your code on an Uno32. The output varied between 10 and 11. Changing delayMicroseconds(10) to delayMicroseconds(1000), the output varied between 1000 and 1001. Changing delayMicroseconds(1000) to delayMicroseconds(100000), the output was pretty constant at 100001.

Best Regards,

Jordan R Digilent