mercoledì 31 agosto 2011

DAC PWM glitch problem with STM32

With the project STM32: microSD Wav audio player with touchscreen I use microcontroller's PWM as 10 bit DAC but in first version of firmware I have found an annoying glitch during playback.


(coming soon video with glitch problem)

This problem is typical when you use TIM_OC1Init(TIM1,&TIM1_OCInitStructure) function to obtain PWM with costant frequency and variable duty cycle.

To solve this problem you can follow these steps:
First step: The initialization code

The initialization code is:

TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

TIM_DeInit(TIM1);

/* Time Base configuration */
TIM1_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM1_TimeBaseStructure.TIM_Period = 1020;

/* Channel 1,3 Configuration in PWM mode */
TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM1_OCInitStructure.TIM_Pulse = 1024/2;

TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure);

TIM_OC1Init(TIM1,&TIM1_OCInitStructure);

TIM_OC3Init(TIM1, &TIM1_OCInitStructure);

/* TIM1 counter enable */
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);

Second step: Update Duty cycle periodically
After initialization, if you want to update duty cycle periodically, you don't use a TIM_OC1Init(TIM1,&TIM1_OCInitStructure) function because you load all field of TIM1_OCInitStructure struct losing firmware efficiency inevitably and causing a glitch during playback but you must update the PWM writing the registers directly as follows:

TIM2->CCR2 = duty1;
TIM2->CCR3 = duty2;

 


 

lunedì 29 agosto 2011

TI Stellaris 8962 : microSD Wav audio player with PWM DAC

Stellaris 8962 is a TI's microcontroller with cortex m3 core.
The evaluation board LM3S8962 has OLED grayscale display(4bit 128 x 96), microSD adapter, 6 buttons(including reset), CAN, buzzer, Ethernet,Usb...
The board has an In-Circuit Debug Interface (ICDI) that provides hardware debugging functionality
The project play song on microSD with PWM's DAC. For this project I created template and firmware.
Display and microSD share same SPI.



STM32 ( cortex m3 ): piano with touchscreen and PWM

Play Piano with touchscreen!! I used PWM to generate a note.
I used a GUI, touchscreen library created for a project STM32: microSD Wav audio player with touchscreen .
Varying the frequency of PWM you can generate a single note.
For frequencies click on this link.



giovedì 25 agosto 2011

STM32: microSD Wav audio player with touchscreen

For this project I created GUI, touch screen library, template to develop a touch screen user interface (icons, menu, progress bar, font) and a firmware to play song .wav( I used PWM as 10 bit DAC to convert a sample in analog voltage).
I used module FATFS for the file system FAT32 on microSD.