Presentation is loading. Please wait.

Presentation is loading. Please wait.

Workshop 3. Digital-to-analog and analog-to digital conversion

Similar presentations


Presentation on theme: "Workshop 3. Digital-to-analog and analog-to digital conversion"— Presentation transcript:

1 Workshop 3. Digital-to-analog and analog-to digital conversion
Embedded Systems Software Training Center Workshop 3. Digital-to-analog and analog-to digital conversion COPYRIGHT © 2015 DSR CORPORATION

2 Objectives Learn how to measure voltage with ADC.
Learn how to generate analog signal with DAC Perform a test task. Copyright © 2015 DSR Corporation

3 Test task: Configure PA5 as an output pin.
Measure voltage on PA1 (ADC123_IN1). Change voltage using variable resistor and indicate voltage level using LEDs. Additional task for self development: Configure DAC channel 2 (PA5) and generate signal changing from 0 to MAX and back. Copyright © 2015 DSR Corporation

4 STM32 ADC 12-bit, 10-bit, 8-bit or 6-bit configurable resolution
Interrupt generation at the end of conversion, end of injected conversion, and in case of analog watchdog or overrun events Single and continuous conversion modes Scan mode for automatic conversion of channel 0 to channel ‘n’ Configurable DMA data storage in Dual/Triple ADC mode Configurable delay between conversions in Dual/Triple interleaved mode ADC conversion type (refer to the datasheets) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at slower speed ADC input range: VREF– <=VIN <= VREF+ Copyright © 2015 DSR Corporation

5 SPL ADC driver common configuration
1. Declare ADC_CommonInitStructure ADC_CommonInitTypeDef ADC_CommonInitStructure; /*ADC Common Init structure definition */ 2. Fill ADC_CommonInitStructure /*Configures the ADC to operate in independent or multi mode. */ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; /*Select the frequency of the clock to the ADC. The clock is common for all the ADCs */ ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; /*Configures the Direct memory access mode for multi ADC mode.*/ ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; /*Configures the Delay between 2 sampling phases.*/ ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; 3. Initializes the ADCs peripherals according to the specified parameters in the ADC_CommonInitStruct. ADC_CommonInit(&ADC_CommonInitStructure); Copyright © 2015 DSR Corporation

6 SPL ADC driver configuration
1. Declare ADC_InitStructure ADC_InitTypeDef ADC_InitStructure; 2. Fill ADC_InitStructure /* Configures the ADC resolution dual mode.*/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b; /* Specifies whether the conversion is performed in Scan (multichannels) or Single (one channel) mode.*/ ADC_InitStructure.ADC_ScanConvMode = DISABLE; /* Specifies whether the conversion is performed in Continuous or Single mode */ ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; /*Select the external trigger edge and enable the trigger of a regular group.*/ ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; /* Select the external event used to trigger the start of conversion of a regular group. */ ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; Copyright © 2015 DSR Corporation

7 SPL ADC driver configuration (continue)
/*Specifies whether the ADC data alignment is left or right.*/ ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; /*Specifies the number of ADC conversions that will be done using the sequencer for regular channel group. */ ADC_InitStructure.ADC_NbrOfConversion = 1; 3. Initializes the ADCx peripheral according to the specified parameters in the ADC_InitStruct ADC_Init(ADC1, &ADC_InitStructure); 4. Configures for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_144Cycles); 5. Enables or disables the specified ADC peripheral. ADC_Cmd(ADC1, ENABLE); Copyright © 2015 DSR Corporation

8 ADC operation 1. Enable the ADC interface clock using RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADCx, ENABLE); 2. ADC pins configuration Enable the clock for the ADC GPIOs: Configure these ADC pins in analog mode using GPIO_Init(); 3. Provide ADC initialization and configuration 4. To start ADC conversion call ADC_SoftwareStartConv(ADCx); 5. Wait for the end of conversion while(!(ADCx->SR & ADC_SR_EOC)) {}; 6. Read conversion result from ADC1->DR. Copyright © 2015 DSR Corporation

9 Thank you! COPYRIGHT © 2015 DSR CORPORATION
9


Download ppt "Workshop 3. Digital-to-analog and analog-to digital conversion"

Similar presentations


Ads by Google