PWM Frequency Issue in STM32WB55CGU6TR with RTOS
Hello,
I am currently working with the STM32WB55CGU6TR MCU and using an RTOS. I've created two threads:
- PWM Thread: This thread generates PWM signals using the GPIO toggle method at frequencies of 60Hz and 600Hz.
- Read FIFO Thread: This thread reads data from the IMU FIFO. The IMU triggers an interrupt when data is ready, and the MCU waits for this interrupt via the EXTI_CALLBACK function to read the data.
Issue:
The PWM thread is producing signals at 50Hz and 500Hz instead of the intended 60Hz and 600Hz. Additionally, the duty cycle is not constant. Here are the steps I have tried:
Case 1: Both threads have the same priority, resulting in the PWM thread giving 50Hz and 500Hz.
Case 2: Increasing the PWM thread priority by 1 causes the Read FIFO thread to stop working entirely.
I would appreciate any insights or suggestions on how to resolve these issues.
Thank you!
/* USER CODE BEGIN Header_Startpwm_imuTask */
/**
* @brief Function implementing the pwm_imuTask thread.
* @PAram argument: Not used
* @retval None
*/
/* USER CODE END Header_Startpwm_imuTask */
void StartPWM_Task(void *argument)
{
int time=INTIAL_VALUE;
uint16_t time_delay=INTIAL_VALUE;
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
GPIO_SET_PIN(GPIOA, GPIO_PIN_0);//CAM_TRIG
for(time=1;time<=5;time++)
{
GPIO_SET_PIN(GPIOA, GPIO_PIN_8);//INS_TRIG
GPIO_SET_PIN(GPIOA, GPIO_PIN_9);//IMU1_TRIG
delay_us(833);
GPIO_CLEAR_PIN(GPIOA, GPIO_PIN_8);//INS_TRIG
GPIO_CLEAR_PIN(GPIOA, GPIO_PIN_9);
delay_us(833);
}
GPIO_CLEAR_PIN(GPIOA, GPIO_PIN_0);//CAM_TRIG
for(time=1;time<=5;time++)
{
GPIO_SET_PIN(GPIOA, GPIO_PIN_8);//INS_TRIG
GPIO_SET_PIN(GPIOA, GPIO_PIN_9);//IMU1_TRIG
delay_us(833);
GPIO_CLEAR_PIN(GPIOA, GPIO_PIN_8);//INS_TRIG
GPIO_CLEAR_PIN(GPIOA, GPIO_PIN_9);//IMU1_TRIG
delay_us(833);
}
}
}
/* USER CODE BEGIN Header_StartDefaultTask */
/**
* @brief Function implementing the defaultTask thread.
* @PAram argument: Not used
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartReadFIFOTask(void *argument)
{
uint32_t flagsWaiter=0;
uint32_t waitFlags = 0x01; // Wait for flag 0 to be set
uint8_t rawdata1[16]={0};
/* USER CODE BEGIN 5 */
/* Infinite loop */
#if 1
reset();
ICM42688_enableFifo();
ICM42688_enableLN_mode();
delay_ms(3);
ICM42688_enableDataReadyInterrupt();
delay_ms(3);
whoAmI();
#endif
while(1)
{
#if 1
//printf("while\n\r");
if(data_1_ready == 1)
{
data_1_ready = 0;
printf("Data ready interrupt 1... \n\r");
multi_i2c_read((0x69<<1),0x30,rawdata1,16);
for (size_t i=0; i<16; i++) {
printf("FIFO Data %#x.. \n\r", rawdata1[i]);
}
}
#endif
}
}