Stm32f4 DAC simple operation [use database functions]

Source: Internet
Author: User

The DAC of ipvf4 is a 12-bit voltage output DAC. It can be configured with 12 or 8 bits and can also be used together with DMA. DAC has two independent conversion channels. In dual-DAC mode, the DA capture mode can be configured to standalone mode or synchronous working mode. Both the reference voltage and ADC of the two-way DAC are vref.

[Main features]

1. Two Channels 2. 12-bit data can be configured to left or right alignment 3. synchronous update capability 4. Noise Generation 5. triangular wave generation 6. Independent or synchronous conversion between two channels 7. each channel has the DMA capability 8. DMA error detection 9. It can be triggered externally.

Formula for Calculating output voltage:

Vout = vref × Dor/4095 = reference voltage × DAC data register value/4095

[Experiment content]

The software triggers the DAC conversion by using the specified voltage output by the DAC.

Key Points of initialization]

1. Configure gpio as AIN/An to simulate the function. Remember to turn on the clock

Void dac_gpio_config (void)
{
Rcc_ahb1periphclockcmd (rcc_ahb1periph_gpioa, enable );
Gpio_initstructure.gpio_mode = gpio_mode_an;
Gpio_initstructure.gpio_otype = gpio_otype_pp;
Gpio_initstructure.gpio_pin = gpio_pin_4 | gpio_pin_5;
Gpio_initstructure.gpio_pupd = gpio_pupd_nopull;
Gpio_initstructure.gpio_speed = gpio_speed_100mhz;
Gpio_init (gpioa, & gpio_initstructure );

}

2. Set the DAC trigger mode to software trigger (dac_trigger_software)

Void dac_config (void)
{
Dac_gpio_config ();
Rcc_apb1periphclockcmd (rcc_apb1periph_dac, enable );
Dac_initstructure.dac_wavegeneration = dac_wavegeneration_none;
Dac_initstructure.dac_trigger = dac_trigger_software;
Dac_initstructure.dac_outputbuffer = dac_outputbuffer_enable;
Dac_init (dac_channel_1, & dac_initstructure );

Dac_cmd (dac_channel_1, enable );
Dac_setchannel1data (dac_align_12b_r, 0x0000 );

Dac_softwaretriggercmd (dac_channel_1, enable );
}

3. Use the following in the main function:

Write Data to the output register. The data can be obtained according to the above formula.

Dac_setchannel1data (dac_align_12b_r, 0xf0f0 );

Then, trigger

Dac_softwaretriggercmd (dac_channel_1, enable );

At this point, the GPIOA-4 on the pin will have a voltage output.

 

Of course, you can also set the timer to trigger. tim6 and tim7 are the timer used for conversion by the Public DAC. Initialization is also very convenient.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.