I want to use the Discovery kit with STM32H745XI MCU to generate sawtooth waves.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-27 8:01 PM
The Discovery kit with STM32H745XI MCU outputs a triangle wave, but how can I make it output a sawtooth wave instead of a triangle wave?
Please let me know the specific improvement and source code.
Looking forward to your answer.
Solved! Go to Solution.
- Labels:
-
STM32Cube MCU Packages
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-28 7:24 AM - edited ‎2024-02-28 8:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-28 6:44 AM - edited ‎2024-02-28 6:48 AM
Hello @Ateam and welcome to the community :),
You can use DAC to generate a sawtooth wave.
For that, I advise you to take a look to this wiki page Getting started with DAC - stm32mcu.
This wiki example used NUCLEO-L476RG board but it can be easily tailored to any other board.
I hope this help you!
Kaouthar
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-28 7:18 AM
The DAC will output any waveform you describe in the pattern buffer.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-02-28 7:24 AM - edited ‎2024-02-28 8:27 AM
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.
