Hello,
Triangle wave generation is a DAC HW feature.
Sawtooth you need to generate it by software by samples using a lookup table like done for the escalator wave generation.
The escalator wave generation is the one you need:
const uint8_t aEscalator8bit[6] = {0x0, 0x33, 0x66, 0x99, 0xCC, 0xFF};
static void DAC_Ch1_EscalatorConfig(void)
{
/*##-1- Initialize the DAC peripheral ######################################*/
if (HAL_DAC_Init(&DacHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-1- DAC channel1 Configuration #########################################*/
sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
if (HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DACx_CHANNEL) != HAL_OK)
{
/* Channel configuration Error */
Error_Handler();
}
/*##-2- Enable DAC selected channel and associated DMA #############################*/
if (HAL_DAC_Start_DMA(&DacHandle, DACx_CHANNEL, (uint32_t *)aEscalator8bit, 6, DAC_ALIGN_8B_R) != HAL_OK)
{
/* Start DMA Error */
Error_Handler();
}
}
Meanwhile, you need to increase the samples as much as possible with a short time between samples to be nearest as much as possible to a sawtooth wave.