chipKIT® Development Platform

Inspired by Arduino™

Interrupt-driven timer

Created Sat, 07 Jan 2012 22:13:25 +0000 by PitoPito


PitoPito

Sat, 07 Jan 2012 22:13:25 +0000

Hi all,

I am working with UNO32 for approx. one month now, and I am really impressed with the board. I am trying to set up a project where data from a 6-DOF IMU (Sparkfun, ADXL345 and ITG3200) is send via USB to a host computer. An exact timing of data acquisition is important. I managed to read out the sensor, but I am stuck now: I don't exactly now how to set up an interrupt driven timer which works with the UNO32. Does anybody know an easy solution or has some kind of sample code?

Thank you in advance for any kind of hint,

Tobias


majenko

Sat, 07 Jan 2012 22:14:47 +0000

What kind of time period are we talking about?


EmbeddedMan

Sat, 07 Jan 2012 22:34:56 +0000

So this is actually a great idea, and there are a number of more advanced features that are coming in one of the next MPIDE builds that will do exactly what you want (They are in testing right now).

However, until then, you can probably do exactly what you want by simply reading the time. Use the millis() or micros() calls to get the current time. Then sit in a loop, waiting until the proper amount of time has passed, and then go grab all of your IMU data and ship it up to the PC.

If this is the only thing you're doing, this technique will work very well. It will work very accurately, as you're just sitting and spinning waiting for the internal time to reach a certain value.

*Brian


PitoPito

Mon, 09 Jan 2012 18:54:24 +0000

@Brian, majenko: Thank you both very much for the reply!

I plan to sample data at 300-500 Hz. I have set bus clock to 400 kHz (it was explained in this forum how to do so), and it seems to work well even if I used a 30 cm connection cable. Just one thing I have noticed: In the last weeks, I also worked with the UBW32, where I received a constant flow of data from the virtual COM-port on my host computer (my UBW32 was in HID mode, interrupt-driven code). Currently, by driving the acquisition by an endless loop, I receive input rather blockwise, in 4092 Byte blocks. Is this due to the FTDI-chip? There is no possibility to use the build-in USB of the PIC, right?

@Brian: Thank you for this suggestion, I will try it. What exactly will you implement in the next version, a timer class or certain timer interrupts?

Regards

Tobias


EmbeddedMan

Mon, 09 Jan 2012 21:52:27 +0000

Tobias,

You CAN use the built-in USB in the PIC32s (like on the max32 or UBW32) from within MPIDE. For example, serial is already hooked up : see [url]http://www.chipkit.cc/wiki/index.php?title=Using_USB[/url]

And yes, the big chunks of data are because of the FTDI driver, but you can change the size and timeout before sending data blocks in the FDTI's driver property pages.

The new feature that will hopefully be in one of the next test builds is a method for calling a given function at a specific rate. It's pretty cool, and may be good for what you want to do.

*Brian


PitoPito

Mon, 09 Jan 2012 22:46:35 +0000

Hi Brian,

that sounds great! Thank you very much for supporting the community with advice and support!

Tobias


patrickk

Tue, 10 Jan 2012 03:56:04 +0000

Hey Brian,

In the meantime, are there any references on how to use the timers and associated interrupts? I'm having a heck of a time trying to figure it out or finding some info on how to do this with chipkit/mpide.

Alternatively, any ETA on a test build with the periodic function you mentioned?

-Patrick


EmbeddedMan

Tue, 10 Jan 2012 15:30:37 +0000

As far as an ETA - I don't have a good answer to that. But I will say that because the dev team is very small at this point, things tend to move very fast. It's likely to be only one or two test builds in the future.

For example timer code, check out this tutorial [url]http://hackaday.com/2011/06/08/chipkit-sketch-mini-polyphonic-sampling-synth/[/url] You'll have to ignore the sound stuff, and just look for the timer related code.

*Brian


patrickk

Tue, 10 Jan 2012 18:50:46 +0000

Thanks Brian. That's exactly what I was looking for. It looks a lot like the examples in the peripheral library pdf. I think I was just missing the extern "C" part.


yoshco

Tue, 17 Jan 2012 08:09:26 +0000

hey, i see the new nightly build (20120116) has a task manager lib but no documentation/examples i can find. any chance of an example of its usage? or a break down of the synth timer part? i need to run a led sequence while reading analog values.