Hello Everyone,
I'm trying to set up a PWM to do pulse counting I'm not sure I have this correct could use a proof read.
This is the code snip It's my understanding that this is how to manipulate the count?
Does all this look correct I'm also using PWM output on GPIO 9.
Thank you in advance.
I'm trying to set up a PWM to do pulse counting I'm not sure I have this correct could use a proof read.
Code:
// PWM configuration parameters#define FAN_TACH 5 // Sense Pin GPIO 5#define PWM_WRAP_VALUE 1000 // value for PWM period#define PWM_LEVEL 500 // value for initial duty cycle#define PWM_CLKDIV 8 // value for clock divideruint Tach_Slice = pwm_gpio_to_slice_num(FAN_TACH);uint Tach_Channel = pwm_gpio_to_channel(FAN_TACH);// Configure GPIO for pulse countinggpio_set_function(FAN_TACH, GPIO_FUNC_PWM);pwm_set_wrap(Tach_Slice, PWM_WRAP_VALUE);pwm_set_chan_level(Tach_Slice, Tach_Channel, PWM_LEVEL);// Set PWM slice to capture mode for pulse countingpwm_set_enabled(Tach_Slice, true);pwm_set_mask_enabled(1 << Tach_Slice);pwm_set_clkdiv(Tach_Slice, PWM_CLKDIV);pwm_set_phase(Tach_Slice, Tach_Channel, 0);// ENDCode:
// Read the pulse count from the PWM sliceuint32_t pulse_count = pwm_hw->slice[ pwm_gpio_to_slice_num(FAN_TACH) ].slice->cc;// Reset the pulse count by writing 0 to the capture registerpwm_hw->slice[ pwm_gpio_to_slice_num(FAN_TACH) ].slice->cc = 0;Thank you in advance.
Statistics: Posted by DarkElvenAngel — Fri May 03, 2024 10:19 pm