Trying to adapt from f4 to f3 DAC
parent
6fd2c2ee07
commit
1f49fb551f
|
|
@ -32,3 +32,6 @@
|
|||
*.out
|
||||
*.app
|
||||
|
||||
.pio
|
||||
.ccls-cache
|
||||
.ccls
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
# README
|
||||
|
||||
Console on PA2 (tx only) 115200@8n1
|
||||
|
||||
* Prints the ADC value on PA0 (adc channel 0) on the console
|
||||
* Echos half that ADC value out to DAC channel 2 on PA5
|
||||
* Prints the ADC value of PA1 (adc channel 1) to the console.
|
||||
|
||||
Recommended wiring:
|
||||
* pot or any resistor ladder to PA0
|
||||
* jumper from PA5 to PA1
|
||||
|
||||
example output:
|
||||
...
|
||||
tick: 228: adc0= 3950, target adc1=1975, adc1=1979
|
||||
tick: 229: adc0= 3949, target adc1=1974, adc1=1978
|
||||
tick: 230: adc0= 3950, target adc1=1975, adc1=1979
|
||||
tick: 231: adc0= 3949, target adc1=1974, adc1=1978
|
||||
...
|
||||
|
|
@ -36,17 +36,17 @@ int _write(int file, char *ptr, int len);
|
|||
|
||||
static void clock_setup(void)
|
||||
{
|
||||
rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
|
||||
rcc_clock_setup_hsi(&rcc_hsi_configs[RCC_CLOCK_HSI_64MHZ]);
|
||||
/* Enable GPIOD clock for LED & USARTs. */
|
||||
rcc_periph_clock_enable(RCC_GPIOD);
|
||||
rcc_periph_clock_enable(RCC_GPIOA);
|
||||
|
||||
/* Enable clocks for USART2 and dac */
|
||||
rcc_periph_clock_enable(RCC_USART2);
|
||||
rcc_periph_clock_enable(RCC_DAC);
|
||||
rcc_periph_clock_enable(RCC_DAC1);
|
||||
|
||||
/* And ADC*/
|
||||
rcc_periph_clock_enable(RCC_ADC1);
|
||||
rcc_periph_clock_enable(RCC_ADC12);
|
||||
}
|
||||
|
||||
static void usart_setup(void)
|
||||
|
|
@ -99,8 +99,8 @@ static void adc_setup(void)
|
|||
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
|
||||
|
||||
adc_power_off(ADC1);
|
||||
adc_disable_scan_mode(ADC1);
|
||||
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_3CYC);
|
||||
adc_set_clk_prescale(ADC1, ADC_CCR_CKMODE_DIV2);
|
||||
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_61DOT5CYC);
|
||||
|
||||
adc_power_on(ADC1);
|
||||
|
||||
|
|
@ -109,10 +109,10 @@ static void adc_setup(void)
|
|||
static void dac_setup(void)
|
||||
{
|
||||
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5);
|
||||
dac_disable(DAC1, DAC_CHANNEL2);
|
||||
dac_disable_waveform_generation(DAC1, DAC_CHANNEL2);
|
||||
dac_enable(DAC1, DAC_CHANNEL2);
|
||||
dac_set_trigger_source(DAC1, DAC_CR_TSEL2_SW);
|
||||
dac_disable(CHANNEL_1);
|
||||
dac_disable_waveform_generation(CHANNEL_1);
|
||||
dac_enable(CHANNEL_1);
|
||||
dac_set_trigger_source(DAC_CR_TSEL2_SW);
|
||||
}
|
||||
|
||||
static uint16_t read_adc_naiive(uint8_t channel)
|
||||
|
|
@ -143,8 +143,8 @@ int main(void)
|
|||
while (1) {
|
||||
uint16_t input_adc0 = read_adc_naiive(0);
|
||||
uint16_t target = input_adc0 / 2;
|
||||
dac_load_data_buffer_single(DAC1, target, DAC_ALIGN_RIGHT12, DAC_CHANNEL2);
|
||||
dac_software_trigger(DAC1, DAC_CHANNEL2);
|
||||
dac_load_data_buffer_single(target, RIGHT12, CHANNEL_2);
|
||||
dac_software_trigger(CHANNEL_1);
|
||||
uint16_t input_adc1 = read_adc_naiive(1);
|
||||
printf("tick: %d: adc0= %u, target adc1=%d, adc1=%d\n",
|
||||
j++, input_adc0, target, input_adc1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue