I’m trying to connect my RC Receiver to a Redboard Artemis, the Problem is, reading the pulse lenght from the receiver isnt as easy as I thought. I previosly worked with an Arduino Uno and upgraded to the Redboard because of the faster cpu, so I searched in the apollo 3 Datasheet for possible methods to count how long it takes between the choosen pin to get high and low. I could use the commands in the arduino IDE, but for my purposes I need a quick way to read 6 pins, so I prefer direct Register Manipulation. Many other microcontroler got a method called Input Capture Mode and it works like this: “Embedded systems using input capture will record a timestamp in memory when an input signal is received. It will also set a flag indicating that an input has been captured. This allows the system to continue executing without interruption while an input is being received while still having the capability to trigger events based on the exact time when the input was received”.
I now I copy and pasted it, but as far as i know, the apollo 3(Redboard Artemis) isnt capable of doing this.
So my final question is: How can i get precised Pulse Capture with the Redboard Artemis?
use the pulseIn() function in Arduino. That would be the easy solution, but it uses polling.
use interrupts on signal changes, and record when these happened. You could so this with Arduino functions (attachInterrupt, microseconds) or at a lower level (using the Ambiq HAL or direct register manipulation if you want)
Ok, I would prefer the second method with direct register manipulation. All i have to is to configure a timer/counter with the registers and set up an interrupt for high->low andlow->high pin changes. I already know how to set up an interrupt with the regsiters, but how do I write the specific code that is executed whenever the interrupt accours? I mean how do I tell the Arduino IDE what it should do with the interrupt?
So as I don’t know how I programe an interrupt yet, i decided to simply try to get a timer to work.
For each timer there are 7 corresponding 32 bit regsiters(apollo 3 datasheet). I wrote a little test programm, that simply reads the timer value and prints it on the serial monitor.
So i uploaded the code and the serial moniter just shows zero’s https://imgur.com/ZCyykDp, but when i restart the serial monitor a couple of times, somehow the timer starts counting https://imgur.com/2WtWjND. If I restart it again it shows 0.
Maybe there is a problem with the serial monitor. But weirdly when I try to change the clock source from this:
CTIMER->CTRL0 = (6 << 1) | CTIMER->CTRL0;
to this: CTIMER->CTRL0 = (1 << 1) | CTIMER->CTRL0;. https://imgur.com/XzJRd20 The timer just doesn’t work at all (only zeros).