@ptillisch and others, not sure if best to ask here, or up on Github issues?
As I mentioned in the Servo library Issue, plus forum post, I have not handled the case where the FsPTimer ends up trying to use an AGT timer. I thought I would try to make it work. If it works, will also update my Charlieplex code as well. So not sure best place. But as this is a stand alone issue, decided to ask on new thread:
In a test program, I preallocated all of the GTP timers so it then continued on to try to allocate a AGT timer, which it did, but it is not working the way I would expect.
The sketch:
#include "FspTimer.h"
#include <UNOR4_digitalWriteFast.h>
static FspTimer servo_timer;
void setup() {
while (!Serial && millis() < 5000)
;
Serial.begin(9600);
delay(500);
Serial.println("Servo test program");
pinMode(9, OUTPUT);
// We will start off with the first servo at 1500
// See if we can force the usage of AGT
FspTimer::set_initial_timer_channel_as_pwm(GPT_TIMER, 4);
FspTimer::set_initial_timer_channel_as_pwm(GPT_TIMER, 5);
FspTimer::set_initial_timer_channel_as_pwm(GPT_TIMER, 6);
uint8_t type = 0;
int8_t channel = FspTimer::get_available_timer(type);
Serial.print("\nservo_timer_config: type:");
Serial.print(type, DEC);
Serial.print(" Channel: ");
Serial.println(channel, DEC);
// lets initially configure the servo to 50ms
if (!servo_timer.begin(TIMER_MODE_PERIODIC, type, channel,
1000000.0f / 20000, 50.0f, servo_timer_callback, nullptr)) {
Serial.println("Timer failed to start");
}
// First pass assume GPT timer
servo_timer.setup_overflow_irq();
servo_timer.open();
servo_timer.start();
Serial.print("Raw Period: ");
Serial.println(servo_timer.get_period_raw(), DEC);
}
void loop() {
}
void servo_timer_callback(timer_callback_args_t *args) {
(void)args; // remove warning
digitalToggleFast(9);
}
(Sorry I cheated and used my own digitalToggleFast code)
I was expecting 20ms for the period:
But instead, it is about 1.77ms
Serial output:
Servo test program
servo_timer_config: type:1 Channel: 1
Raw Period: 960000
Note: servo_timer.get_period_raw() returned a period of 960000
Which does not make sense, as I am pretty sure this is a 16 bit counter.
Wonder maybe it did not like to do a period that long.
So tried changing to 1500.
Raw Period: 71999
Tried 750 -> 35999
Thoughts? Are there known issues with FSP and AGT?
Thanks
Kurt