Board LPCS5506 dev kit
I'm using 4 wire fan, Power, ground, TACH, and PWM.
For PWM I'm using Ctimer2 Mat 3 in PWM mode.. Timer clock is 16MHz, PWM period is 1KHz, Duty cycled at 20%.
That's working as expected.
I Intend to use Ctimer0 in Capture Mode on channel 0 to count the fan rotations, and measure the RPM. What's the best way to do this, I have implemented it but it's behaving rather weirdly.
I've configured ctimer0 at 1KHz to count the fan signals (2 rising and 2 falling make a rotation)
const ctimer_config_t CTIMER0_FAN_TACH_config = {
.mode = kCTIMER_TimerMode,
.input = kCTIMER_Capture_0,
.prescale = 15999
};
static void CTIMER0_FAN_TACH_init(void) {
/* CTIMER0 peripheral initialization */
CTIMER_Init(CTIMER0_FAN_TACH_PERIPHERAL, &CTIMER0_FAN_TACH_config);
/* capture channel 0 of CTIMER0 peripheral initialization */
CTIMER_SetupCapture(CTIMER0_FAN_TACH_PERIPHERAL, CTIMER0_FAN_TACH_CAPTURE_0_CHANNEL, kCTIMER_Capture_BothEdge, true);
CTIMER_RegisterCallBack(CTIMER0_FAN_TACH_PERIPHERAL, CTIMER0_FAN_TACH_callback, kCTIMER_SingleCallback);
/* Start the timer */
CTIMER_StartTimer(CTIMER0_FAN_TACH_PERIPHERAL);
}
I'm getting interrupts randomly, and they stop abruptly.
I get interrupts even without the fan connected. What am I missing ?