230 likes | 421 Views
Microcontroller based system design. Asst. Prof. Dr. Alper ŞİŞMAN. ADC Hardware.
E N D
Microcontroller based system design Asst. Prof. Dr. Alper ŞİŞMAN
ADC Hardware • Three 12-bit analog-to-digital converters are embedded and each ADC shares up to 16 external channels, performing conversions in the single-shot or scan mode. In scan mode, automatic conversion is performed on a selected group of analog inputs. • The ADC can be served by the DMA controller. An analog watchdog feature allows very precise monitoring of the converted voltage of one, some or all selected channels. An interrupt is generated when the converted voltage is outside the programmed thresholds. • To synchronize A/D conversion and timers, the ADCs could be triggered by any of TIM1, TIM2, TIM3, TIM4, TIM5, or TIM8 timer.
Temperature Sensor / VBat • The temperature sensor has to generate a voltage that varies linearly with temperature. • The temperature sensor is internally connected to the ADC1_IN16 input channel which is used to convert the sensor output voltage into a digital value.
ADC Hardware STM32F405xx/STM32F407xx Datasheet
ADC Registers Activate ADC: ADON: ADCx->CR2 bit#0 Injected mode: JSWSTART: ADCx->CR2 bit#22 Regular mode: SWSTART: ADCx->CR2 bit#30 End of conversion control : JEOC: ADCx->SR bit#2 End of conversion conntrol : EOC: ADCx->SR bit#1 Read the result when conversion ends: Regular Mode: İnjected Mode: Result DATA REGISTER: ADCx->DR Result DATA REGISTER: ADCx->JDR
ADC Prescaler: (if needed) ADC->CCR -> bit# 17:16 Clock: ADC1: RCC->APB2ENR -> bit#8 ADC2: RCC->APB2ENR -> bit#9 ADC3: RCC->APB2ENR -> bit#10
Regular mode: Sequence length: SQR1: ADCx->SQR1 bit#23:20 SQR1,SQR2,SQR3: give the sequence in the desired order Injected mode: Sequence length: JSQR: ADCx->JSQR bit#21:20 JSQR : give the sequence in the desired order
Enable temperature sensor: TSVREFE: ADC->CCR bit#23
Cont. conversion mode operation Continious conversion: CONT: ADCx->CR2 bit#1
Analog watchdog: ADCx->HTR: High threshold ADCx->LTR: Low threshold AWDEN: ADCx->CR1 bit#23 AWDSGL: ADCx->CR1: bit#9 AWDCH: ADCx->CR1 bit#4:0 Injected Channels: JAWDEN: ADCx->CR1 bit#22
Channelx sampling time selection: ADCx->SMPR1 ADCx->SMPR2 ADCx->SMPR3 Wrıte the proper setting to the area of channel which will be set.