485 views|2 replies

2865

Posts

4

Resources
The OP
 

【NUCLEO-U083RC】DAC output and built-in comparator test [Copy link]

Test Introduction

This test is a composite test, which completes two tests, DAC and COMP. This test tests the DAC and internal comparator of STM32U083. The test generates a voltage signal through the DAC, and then introduces the voltage signal into the internal op amp circuit of the MCU. The test results are observed by setting comparison conditions.

The hardware uses the NUCLEO-U083RC development board of the STM32U083 MCU, and needs to use the DAC1 peripheral and COMP1 peripheral of the MCU. LED4 is used as a comparison indicator, and the light of LED4 indicates that an interrupt has occurred.

Use the BUTTON button to change the value of the DAC output.

Connect PA1 and PA4 with a wire. Press BUTTON to change the setting until LED4 lights up.

Hardware Connection and Setup

DAC settings: Peripheral: DAC1, Output mode: External output

COMP settings: Peripheral: COMP1, comparison voltage: 1/2 internal reference source, interrupt turned on.

COMP1 Settings

DAC1 Settings

BSP settings, use LED4 and BUTTON1, turn on the button interrupt

Test Procedure and Working Principle

COMP comparator, the comparison input is the physical pin PA1. Comparison reference: internal reference source and external reference source, or DAC channel, comparison output result: can use query mode or interrupt mode. This test uses interrupt mode, and can also use output to physical pin. This method does not require the participation of MCU and has a very fast response speed.

The BUTTON1 button is used in the test, the interrupt mode of the button is enabled, and the UserButtonStatus value is set in the interrupt to drive the test.

/**

* @brief EXTI line detection callbacks

* @param GPIO_Pin: Specifies the pins connected EXTI line

* @retval None

*/

void BSP_PB_Callback(Button_TypeDef Button)

{

UserButtonStatus = 1;

}

In the main program, query the UserButtonStatus value to modify the output voltage of the DAC.

if (UserButtonStatus == 1)

{

UserDACValue = (UserDACValue + 10) % 4096;

if (HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_8B_R, UserDACValue) != HAL_OK)

{

/* Setting value Error */

Error_Handler();

}

UserButtonStatus=0;

}

The whole procedure is not very complicated.

Comparator interrupt routine.

/**

* @brief Comparator interruption callback

* @note This function is called when comparator threshold is triggered.

* @param hcomp COMP handle

* @retval None

*/

void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)

{

/* Set LED state in function of comparator output level */

if (HAL_COMP_GetOutputLevel(hcomp) == COMP_OUTPUT_LEVEL_HIGH)

{

BSP_LED_Off(LED4);

}

else

{

BSP_LED_On(LED4);

}

}

Testing process

Connect pins PA1 and PA4 and power on the board.

Initially, LED4 is off.

Start pressing BOTTON1 several times.

LED4 lights up, indicating that the interrupt is working.

Test Summary

This is the first time to test COMP output. I have no experience. The whole test is actually done separately. I started by referring to the DAC_SimpleConversion routine and debugging the DAC output. Then I drove the key. During the test, the key interrupt process could not be started, but the interrupt program could be entered. This made me feel strange. Later I found that it was a BSP version problem. After using the correct version, it was completed. Mainly: the BSP_PB_Callback file name caused it. Pay attention to use the name declared in the BSP driver.

After debugging the buttons, I debugged the COMP program, referring to the COMP_CompareGpioVsVrefInt_IT program. The whole process took 2 days to figure out COMP.

This post is from stm32/stm8

Latest reply

Thanks for sharing   Details Published on 2024-6-3 15:38
 

2865

Posts

4

Resources
2
 
The source code used in this test is DACCMOP.zip (990.53 KB, downloads: 0)
This post is from stm32/stm8
 
 

5

Posts

0

Resources
3
 

Thanks for sharing

This post is from stm32/stm8
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list