On my custom LPC54005 board, I am trying to use CTimer0 as a counter with PIO1_1 as the clock input.
(CT0_CAP3 — Capture 3 input to Timer 0). I have a 1Hz square wave connected to the pin. This signal is clean and recognized by the MCU. When using the interrupt as we do for counting slow signals, I see an exact count so I think the hardware is OK. When I try using the hardware CTIMER0 as a counter for higher frequency signals, retrieving the TC every minute and then immediately clearing the count, I get extremely large TC values ~ TC:10269 that are also not stable. I also tried reading the TC and using the difference from the last reading with same problem.
It looks like the timer is not routing PIO1_1 as its clock. I just want to use CTIMER0 as a hardware counter.
I added the FSL_FEATURE_CTIMER_HAS_CCR_CAP3=1 in my Symbols.
In the debugger using MCUXpresso I can not read the TC value but other registers are available:
I also attached my code snippets that initialize CTIMER0 and read it periodically.
Thanks
Hi David Kaplan,
Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
I'd like to suggest you implement a match feature of the Ctimer to toggle CTIMERn_MAT pin after the external clock has already driven the Ctimer module. It's able to be used to validate whether the Ctimer counter runs well.
In further, there's a simple_match demo in the SDK library for you to refer to.
So please give a try.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Sorry I do not understand how the 4 SDK examples can help me. I looked at all four and the CTimer is setup as a timer and not a counter. I need a 32 bit hardware counter from an external pin. Maybe this cannot be done.
In the four programs, GetDefaultConfig is called to set the defaults before changing anything.
In all of the programs the config.mode is not changed to one of the edge modes.
/*! @brief List of Timer modes */
typedef enum _ctimer_timer_mode
{
kCTIMER_TimerMode = 0U, /* TC is incremented every rising APB bus clock edge */
kCTIMER_IncreaseOnRiseEdge, /* TC is incremented on rising edge of input signal */
kCTIMER_IncreaseOnFallEdge, /* TC is incremented on falling edge of input signal */
kCTIMER_IncreaseOnBothEdge /* TC is incremented on both edges of input signal */
} ctimer_timer_mode_t;
void CTIMER_GetDefaultConfig(ctimer_config_t *config)
{
assert(config);
/* Initializes the configure structure to zero. */
memset(config, 0, sizeof(*config));
/* Run as a timer */
config->mode = kCTIMER_TimerMode;
/* This field is ignored when mode is timer */
config->input = kCTIMER_Capture_0;
/* Timer counter is incremented on every APB bus clock */
config->prescale = 0;
}
simple_match.c
CTIMER_GetDefaultConfig(&config);
CTIMER_Init(CTIMER, &config);
simple_match_interrupt.c
CTIMER_GetDefaultConfig(&config);
CTIMER_Init(CTIMER, &config);
simple_pwm.c
CTIMER_GetDefaultConfig(&config);
timerClock = srcClock_Hz / (config.prescale + 1);
CTIMER_Init(CTIMER, &config);
simple_pwm_interrupt.c
CTIMER_GetDefaultConfig(&config);
timerClock = srcClock_Hz / (config.prescale + 1);
CTIMER_Init(CTIMER, &config);
What am I missing?
Thanks
Hi David Kaplan,
Thanks for your reply.
Please modify CTIMER_GetDefaultConfig to enable the Ctimer to be clocked by the CAP input, just like the below shows.
void CTIMER_GetDefaultConfig(ctimer_config_t *config)
{
assert(config);
/* Initializes the configure structure to zero. */
memset(config, 0, sizeof(*config));
/* Run as a timer */
config->mode = kCTIMER_IncreaseOnRiseEdge;
/* This field is ignored when mode is timer */
config->input = kCTIMER_Capture_3;
/* Timer counter is incremented on every APB bus clock */
config->prescale = 0;
}
Note that, you also need to configure the CAP input pin the BOARD_InitPins() function.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------