Stm32--dac

Source: Internet
Author: User

0. Compare the pits.

0) stm32f10x Board

1) "Gpio_initstructure.gpio_mode = Gpio_mode_ain; Analog Input "

PIN is set as analog input to prevent interference

2) "//dac_initstructure.dac_outputbuffer = dac_outputbuffer_disable; DAC1 output cache off Boff1=1 "
"Dac_initstructure.dac_outputbuffer = dac_outputbuffer_enable; DAC1 output cache open for improved port drive Boff1=0 "

The second sentence has a certain driving ability, or die or die even a lamp is not bright

Use another board to read the value, 2 code can output the ideal voltage, but the 1th sentence code can not drive a small lamp, it is estimated that the current is too small; voltage follower is said to be added

3) The board I bought did not directly connect Vref to the power supply; I need to supply the reference voltage myself.

1.

1) TheGpioa clock is in the APB2, and theDAC clock is in APB1

2) The DAC's channel PIN is in the circuit diagram.

Pa4--dac_out1

Pa5--dac_out2

3) The mode has 8 bits and 12 bits;

to 12-bit mode, set the value within 4095

3) process

Set GPIOA to analog output

Do not use the trigger function

Does not use waveforms to occur

Shielding, amplitude setting

DAC1 output cache on "Improve port drive capability!" 】

Initializing the DAC Channel 1

Enable to DAC1

Setting the DAC value

4) Repeated modification of the value call is only called with the following 2 lines of code

Dac_setchannel1data (Dac_align_12b_r, Value);
Dac_softwaretriggercmd (Dac_channel_1, ENABLE);

2. Code: PA4 Port output = 3000/4095 * Vref voltage

#include <stm32f10x.h>voidGpio_config (void);voidDac_config (void);voidDac_setvalue (intValue); intMain () {gpio_config ();        Dac_config ();  while(1);}voidGpio_config () {gpio_inittypedef gpio_initstructure;        Rcc_apb2periphclockcmd (Rcc_apb2periph_gpioa, ENABLE); Gpio_initstructure.gpio_pin=Gpio_pin_4; Gpio_initstructure.gpio_mode= Gpio_mode_ain;//Analog InputGpio_initstructure.gpio_speed =Gpio_speed_50mhz; Gpio_init (Gpioa,&gpio_initstructure);}voidDac_config () {dac_inittypedef dac_initstructure; //Enable DAC channel clockrcc_apb1periphclockcmd (RCC_APB1PERIPH_DAC, ENABLE); //do not use the trigger function ten1=0Dac_initstructure.dac_trigger =Dac_trigger_none; //does not use waveforms to occurDac_initstructure.dac_wavegeneration =Dac_wavegeneration_none; //shielding, amplitude settingDac_initstructure.dac_lfsrunmask_triangleamplitude =dac_lfsrunmask_bit0; //DAC1 output cache off Boff1=1//dac_initstructure.dac_outputbuffer = dac_outputbuffer_disable; //DAC1 output cache open for improved Port drive boff1=0Dac_initstructure.dac_outputbuffer =dac_outputbuffer_enable; //initializing the DAC Channel 1Dac_init (Dac_channel_1, &dac_initstructure); //Enable to DAC1dac_cmd (Dac_channel_1, ENABLE); //12-bit right-aligned data format set DAC valueDac_setchannel1data (Dac_align_12b_r, the);}/******************************************* Setting the Channel 1 output voltage * * Call and modify the value repeatedly call only the following 2 sentences * * The main function is not used, standby ************************* ****************/voidDac_setvalue (intValue)    {Dac_setchannel1data (Dac_align_12b_r, Value); Dac_softwaretriggercmd (Dac_channel_1, ENABLE);}

Stm32--dac

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.