2023-03-14 02:11 AM
I have a STM32-G071RB. I want to generate two sine outputs. one for reference and the second with a phase shift. Unfortunately, there is only one DAC port. I got an extra board but then I realized I need communication between the two boards to (I found SPI could be used) , because I want to design a phase locked loop. Are there any other ways to do this easily without having to use two boards? Or any methods?
2023-03-14 05:06 AM
The DAC in 'G0 is dual, i.e. there in fact are two DACs, with outputs on PA4 and PA5.
Read the DAC chapter in RM.
JW
2023-03-14 05:48 AM
I didn't see that before. Thanks.
2023-03-14 09:40 AM
Btw, i encountered this problem. I saw your comment in other post for dual dac mode.
If i choose two dac channels and the trigger source for both of them is tim2. Do i need to choose this external trigger too? How do I call them in the main code?
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
// Check which version of the timer triggered this callback and toggle LED
if (htim == &htim16 )
{
phase += tuning;
idx = (phase >> 20) & 0xFFF;
output_val1 = LUT_r[idx];
output_val2 = LUT_s[idx];
// if(counter >= ratio){
// counter = 0;
// slow_counter = 1;
//
// }
diff = (output_val1 - output_val2);
HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, output_val1);
HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_2, DAC_ALIGN_12B_R, output_val2);
// Trigger DAC output using TIM2
TIM2->EGR |= TIM_EGR_UG; // Generate update event to reload timer values
TIM2->SR &= ~TIM_SR_UIF; // Clear update interrupt flag
DAC->SWTRIGR |= DAC_SWTRIGR_SWTRIG1 | DAC_SWTRIGR_SWTRIG2; // Trigger DAC output
counter++;
// HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);
// HAL_DAC_Start(&hdac1, DAC_CHANNEL_2);
}
}
I did this to trigger DAC but this is not working. Could you help me with this?
2023-03-14 10:02 AM
You don't need to use any trigger - leave DAC_CR.TENx = 0, and then what you write into DAC_DHRx is automatically transferred to the output register and after the analog settling time appears as voltage at the output.
I don't use Cube/CubeMX and don't know what are the incantations to achieve the above. DAC is very simple, it can be easily used directly through registers, and the DAC chapter in RM contains an exact description of its functionality.
JW
2023-03-16 01:36 AM
unfortunately, i couldn't find DAC chapter in this manual. https://www.st.com/resource/en/reference_manual/rm0454-stm32g0x0-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
Edit: Thanks for telling me about registers. Turns out what I was originally (using HAL library to output DAC) doing was also giving me desired results but I understood it wrong.
2023-03-16 02:23 AM
for STM32G0x1:
DAC: chapter 16
If it is built like the G4 DAC, you can actually use a timer (G4: timer 6) to set the DAC's sampling rate and feed data via DMA.