Hi guys
I want to make a wave player whit stm32f4, read the wave files from sdcard and into PWM CH_1 and CH_2.
and timer1_ch1 and timer1_ch2 pins are connected to RC filter(res: 1M,3.9k & c:4.7nf), ch_lo connected to 1M and ch_hi connected to 3.9k.
but the filter output is consistently noisy.
the MCU clock is 84MHZ and timer configuration is :
prescaler:0
Auto reload register :255
pwm pulse:%50
this program works as a ping pong.
this is main code.
#include "main.h"
#include "fatfs.h"
SD_HandleTypeDef hsd;
TIM_HandleTypeDef htim1;
/* USER CODE BEGIN 0 */
#define sample_no 256
uint8_t sai_buf[2][sample_no];
uint32_t br;
FATFS SDFatFs; /* File system object for SD disk logical drive */
FIL MyFile; /* File object */
extern char SDPath[4]; /* SD disk logical drive path */
uint8_t refill=0;
uint32_t index_buf=0;
static FRESULT res;
uint32_t block_size;
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 2 */
uint8_t count=0;
int t=1;
res=f_mount(&SDFatFs, (TCHAR const*)SDPath, 0);
if(res==FR_OK)
{
res=f_open(&MyFile,"6.wav",FA_READ);
block_size=f_size(&MyFile);
if(res==FR_OK)
{
res=f_read(&MyFile,&sai_buf[0],sample_no,&br);
}
}
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2);
HAL_TIM_Base_Start_IT(&htim1);
/* USER CODE END 2 */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(refill)
{
index_buf++;
res=f_read(&MyFile,&sai_buf[(index_buf)%2],sample_no,&br);
refill=0;
}
}
/* USER CODE END 3 */
}
this is a ISR code:
void TIM1_UP_TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
/* USER CODE END TIM1_UP_TIM10_IRQn 0 */
HAL_TIM_IRQHandler(&htim1);
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
wcnt++;
if(wcnt>7)
{
wcnt=0;
TIM1->CCR1=sai_buf[index_buf%2][i];
TIM1->CCR2=sai_buf[index_buf%2][i+1];
i+=3;
if(i>=(sample_no-1))
{
i=0;
refill =1;
}
}
/* USER CODE END TIM1_UP_TIM10_IRQn 1 */
}
someone know what is the problem?