I’m trying to synchronize this timer module with another time source.
According to the documentation, I can restart this timer by simply disabling and re-enabling it. I've set a break point immediately before and after the code listed below. I don’t think this is working as intended because the timer’s Current Value is decremented slightly and nowhere near the Reload Value.
PIT_TCTRL_REG( PIT_BASE_PTR, 0 ) &= ~PIT_TCTRL_TEN_SHIFT;
PIT_TCTRL_REG( PIT_BASE_PTR, 0 ) |= PIT_TCTRL_TEN_SHIFT;
Note: I’m referencing Figure 38-23 of the Document K10P144M100SF2RM Rev. 6, Nov 2011
Please let me know if you have any suggestions.
Hi
I think that you may need to write to the LDVAL register when the PIT is disabled so that it restarts.
This is an extract from the PIT code from the uTasker project which can be used as a single-shot / retriggerable or periodic timer - it was necessary to disable operation if its value was to be reset/retriggered - without this it doesn't react.
if (PIT_settings->mode & (PIT_SINGLE_SHOT | PIT_RETRIGGER)) { // single shot always behaves as retriggerable - periodic change at next timeout by default but can be forced with PIT_RETRIGGER
ptrCtl->PIT_TCTRL = 0; // disable PIT so that it can be retriggered if needed
}
ptrCtl->PIT_LDVAL = PIT_settings->count_delay; // load interval value
ptrCtl->PIT_TFLG = PIT_TFLG_TIF; // clear pending interrupts
ptrCtl->PIT_TCTRL = ulCommand; // start PIT with interrupt enabled, when handler defined
Regards
Mark