Library 07- DA Converter on STM32F4
Digital to Analog Converter has inverse function as ADC. It converts digital value in microcontroller to analog value.
Library
Features
- Output analog value from STM32F4x
Dependencies
- CMSIS
- STM32F4xx
- STM32F4xx GPIO
- STM32F4xx DAC
- TM
- TM GPIO
- defines.h
- TM GPIO
STM32F4 has 1 DAC with 2 channels output. Table below shows pins for DAC.
DAC Channel | ALIAS | Pin | APB |
---|---|---|---|
DAC_Channel_0 | TM_DAC1 | PA4 | 1 |
DAC_Channel_1 | TM_DAC2 | PA5 | 1 |
Alias is used in my library for easier use in library.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/** * Keil project for DAC example * * Before you start, select your target, on the right of the "Load" button * * @author Tilen Majerle * @email tilen@majerle.eu * @website http://stm32f4-discovery.net * @ide Keil uVision 5 */ /* Include core modules */ #include "stm32f4xx.h" /* Include my libraries here */ #include "defines.h" #include "tm_stm32f4_dac.h" int main(void) { /* Initialize system */ SystemInit(); /* Initialize DAC channel 1, pin PA4 */ TM_DAC_Init(TM_DAC1); /* Initialize DAC channel 2, pin PA5 */ TM_DAC_Init(TM_DAC2); /* Set 12bit analog value of 1500/4096 * 3.3V */ TM_DAC_SetValue(TM_DAC1, 1500); /* Set 12bit analog value of 2047/4096 * 3.3V */ TM_DAC_SetValue(TM_DAC2, 2047); while (1) { } } |
Project is available on Github Github, download library below.
DAC library to convert digital value to analog voltage
Recent comments