Hi all,
tombo,
samtal's code works in Maple IDE as-is, so you should be able to adapt it to your own purposes. However, he uses DMA a lot, which can get sort of confusing; there are some notes on DMA in the wiki, but unfortunately they're not that beginner friendly yet:
http://wiki.leaflabs.com/index.php?title=DMA
samtal,
Can you please add a generic timer interrupt option to the adc conversion start I used? (I need it for my app, but I am not sure how to get it work. I need to start a sequence every 40 microseconds, using a prescaler of 2880 (?)).
If you do not have the time for the full file, please post here or elsewhere just an example of setting the interrupt and the timer,
You should be able to get away with something like this (untested):
HardwareTimer timer(1); // uses timer 1; adjust as necessary
void setup() {
timer.pause(); // pause while we configure
timer.setPeriod(40); // sets a period of 40 microseconds
timer.setCompare(TIMER_CH1, 1); // timer channel 1 interrupt occurs when count hits 1
timer.attachInterrupt(TIMER_CH1, myInterruptHandler); // calls myInterruptHandler when channel 1 hits its count, which we just set to 1
timer.refresh(); // refresh the timer, to reset the counter to 0
timer.resume(); // resume counting
}
void myInterruptHandler() {
// this gets called every time the timer count hits 1, which happens once every 40 microseconds
}
See also "Using Timer Interrupts" in the HardwareTimer documentation:
http://leaflabs.com/docs/lang/api/hardwaretimer.html#using-timer-interrupts
Note that using timer 1 interferes with PWM on any pins connected to timer 1's capture/compare channels. You can find out which pins these are on your board's hardware page; for Maple, they're listed here:
http://leaflabs.com/docs/hardware/maple.html#timer-pin-map
(have you seen my flash example http://pastebin.com/h0CxGRQ7 ?)
I did see your post about it, but I haven't looked at the code too closely. We've been busy on some internal projects lately, and I haven't been able to spend as much time on the forums as I usually do. I'm working on some changes to libmaple which will hopefully make writing to Flash much easier, though, so don't despair ;). Your goals are aligned with ours.