2024-07-28 11:04 PM
hallo
can anyone help me about how to program for convert adc to dac ini stm32cubemx with program keil U5, have you guys can help to bring me an example of your code or tips and step. i used the potentiometer for adc value and the value used to dac and read by osciloscop
can you help me? thanks
Solved! Go to Solution.
2024-07-29 03:03 AM
Hello @meriarajagukguk
For ADC config:
For DAC config:
In your while (1), you should set the DAC output to the ADC value
while (1)
{
// Poll for ADC conversion completion
if (HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY) == HAL_OK)
{
// Read the ADC converted value
uint32_t adcValue = HAL_ADC_GetValue(&hadc1);
// Set the DAC output to the ADC value
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, adcValue);
}
}
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-07-29 03:03 AM
Hello @meriarajagukguk
For ADC config:
For DAC config:
In your while (1), you should set the DAC output to the ADC value
while (1)
{
// Poll for ADC conversion completion
if (HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY) == HAL_OK)
{
// Read the ADC converted value
uint32_t adcValue = HAL_ADC_GetValue(&hadc1);
// Set the DAC output to the ADC value
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, adcValue);
}
}
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-07-29 03:10 AM
Hello sarra thanks for your reply.
i want to ask again about how to set value freq value, if i have stm32nucleo with 72 MHz CPU, CCM, 12-bit ADC 5 MSPS. if i want output of the freq value in osciloscop is 200 Hz.
f=F_CLK / ((Prescaler+1)×(Period+1))
I have used the formula above but when I apply it to htim2.Init.Prescaler and htim2.Init.Period but the results I get are only in the range of 35-40 hz, am I using the wrong formula or is there a step I missed please help me find the way.
2024-07-29 04:18 AM
The formula us correct,
Re-arranging the formula; (PSC+1)(Period+1) = F_CLK/f = (72.10^6)/200= 360 000
Now, you can choose a prescaler value and calculate the corresponding period value, or vice versa
For simplicity, let's choose a prescaler value of 359 (since prescaler is typically a small value)
For PSC=359 => Period= 999
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-07-29 07:47 AM
but why do the values produced by the oscilloscope not match the results even at only 35-40 hz?
Are there any conditions that must be met apart from the prescaler and the period?