cancel
Showing results for 
Search instead for 
Did you mean: 

DAC conversion with 12 bits resolution

MHuer.1
Associate II

Hi!

I am struggling while using the DAC of my STM32F446RE with 12 bits resolution.

I want to output the value of a variable (val_av) after some calculations on the STM and collect it with a data logger. At the beginning, I had a data logger with digital inputs so I used a PWM signal with variable duty cycle(10-90%). To estimate the duty cycle I used a linear interpolation between the maximum and minimum value(1550 and 1350). This work fine. However, now I have another data logger without digital input capability so I have to use an DAC and record the values.

I tried something similar for the DAC using 8 bits resolution and it work fine. I measure the output voltage on the PIN and it goes from 0 to 3 volts(approx). NowI want to use now 12 bits resolution, however the voltage value is now much shorter(0-200 mv) and I can not measure properly with the data logger.

what I am doing wrong?

any comment will help!

Thanks in advance!

code (I initialised the DAC before):

val_av = (uint32_t)(sum/loop);

//******Output as PMW signal with variable duty cycle

duty_cycle = 900 + (((100 - 900)/(1550 - 1350))*(val_av - 1350)); //linear interpolation for PWM signal (duty cycle)

htim1.Instance->CCR1=duty_cycle;//change of the duty cycle

//*****Output as analog signal using DAC

voltage_value = 0.3 + (((3.0 - 0.3)/(1350-1550))*(val_av-1550));//linear interpolation for the Analog output

val_Byte=(uint8_t)((voltage_value/3.0)*255);//conversion digital to analog signal

HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_8B_R, val_Byte); // output the value to the DAC

//***for the 12 bits

/*

val_Byte=(uint16_t)((voltage_value/3.0)*4095);//conversion digital to analog signal

HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, val_Byte); // output the value to the DAC

*/

1 REPLY 1
TDK
Guru

My guess is that val_Byte is declared as a uint8_t.

If you feel a post has answered your question, please click "Accept as Solution".