Stm32f103 DAC study notes
Recently, I am working on the current-type signal output project and encountered some problems. Here I will take a note of these solutions for future use. This part of the Manual is not detailed, so we also encountered some resistance in use.
A 64-core package is used. The reference vref + of this core ADC is the same port as the power supply, and vref-shares the power supply location. When the Active Value of the battery output is 0, the sampling resistance is 100 ohm and the current output is 66mA ohm. When the active value is 0, the output can reach 0025mA MPa as long as the output buffer of the failed port is reached during initialization. OK.
1 Void Analoginit ( Void ) 2 { 3 Dac_inittypedef dac_initstructure; 4 Gpio_inittypedef gpio_initstructure; 5 6 Rcc_apb2periphclockcmd (rcc_apb2periph_afio | Rcc_apb2periph_gpioa, enable ); 7 /* DAC periph clock enable */ 8 Rcc_apb1periphclockcmd (rcc_apb1periph_dac, enable ); 9 10 /* Configure DAC channe1 output pin */ 11 Gpio_initstructure.gpio_pin =Gpio_pin_4; 12 Gpio_initstructure.gpio_speed = Gpio_speed_50mhz; 13 Gpio_initstructure.gpio_mode = Gpio_mode_out_pp; 14 Gpio_init (gpioa ,& Gpio_initstructure ); 15 16 /* Configure DAC channe1 output pin */ 17 Gpio_initstructure.gpio_pin =Gpio_pin_5; 18 Gpio_initstructure.gpio_speed = Gpio_speed_50mhz; 19 Gpio_initstructure.gpio_mode = Gpio_mode_out_pp; 20 Gpio_init (gpioa ,& Gpio_initstructure ); 21 22 23 /* DAC channel1 Configuration */ 24 Dac_initstructure.dac_trigger = Dac_trigger_software; 25 Dac_initstructure.dac_wavegeneration = Dac_wavegeneration_none; 26 Dac_initstructure.dac_outputbuffer = dac_outputbuffer_disable; // Output buffer failure 27 Dac_initstructure.dac_lfsrunmask_triangleamplitude = Dac_triangleamplitude_4095; 28 29 Dac_init (dac_channel_1 ,& Dac_initstructure ); 30 31 /* DAC channel2 Configuration */ 32 Dac_init (dac_channel_2 ,& Dac_initstructure ); 33 34 /* Enable DAC channel1: Once the DAC channel1 is enabled, pa.04 is 35 Automatically connected to the DAC converter. */ 36 Dac_cmd (dac_channel_1, enable ); 37 /* Enable DAC channel2: Once the DAC channel2 is enabled, pa.05 is 38 Automatically connected to the DAC converter. */ 39 Dac_cmd (dac_channel_2, enable ); 40 41 } 42 43 // Update port 1ad Value 44 Void Dacloud Update (seconds) 45 { 46 Condition = (condition < 4 )& 0xfff0 ; 47 /* Set DAC channel1 dhr12l register */ 48 Dac_setchannel1data (dac_align_12b_l, region ); 49 50 /* Start DAC channel1 conversion by software */ 51 Dac_softwaretriggercmd (dac_channel_1, enable ); 52 } 53 54 Void Dac2_update (2010ch2) 55 { 56 CH2 = (CH2 < 4 )& 0xfff0 ; 57 /* Set DAC channel2 dhr12l register */ 58 Dac_setchannel2data (dac_align_12b_l, CH2 ); 59 60 /* Start DAC channel1 conversion by software */ 61 Dac_softwaretriggercmd (dac_channel_2, enable ); 62 }