7 HAL ADC Generic Driver

Started by tha, June 28, 2022, 08:51:00 AM

Previous topic - Next topic

tha

•   uint32_t ADC_ChannelConfTypeDef::Rank
     ระบุ the rank ใน the regular group sequencer. parameter นี้สามารถเป็นค่าหนึ่งของ ADC_regular_rank หมายเหตุ: ในกรณี
     จำเป็นต้องปิดใช้งาน a channel หรือเปลี่ยนลำดับของ conversion sequencer, rank ที่บรรจุ a previous channel setting สามารถ
     ถูกเขียนทับโดย the new channel setting (หรือ parameter number ของ conversions สามารถถูกปรับ)

tha

•   uint32_t ADC_ChannelConfTypeDef::SamplingTime
     Sampling time value ที่ถูกเซ็ตสำหรับ the selected channel. Unit: ADC clock cycles Conversion time เป็นการบวกกันของ
     sampling time และ processing time (12.5 ADC clock cycles ที่ ADC resolution 12 bits). parameter นี้สามารถเป็นค่าหนึ่ง
     ของ ADC_sampling_times ข้อควรระวัง: parameter นี้อัฟเดต the parameter property ของ the channel, ที่สามารถถูกใช้ใน
     regular และ/หรือ injected groups. ถ้า channel เดียวกันนี้ถูกกำหนดค่าไว้ล่วงหน้าในกลุ่มอื่นแล้ว (regular/injected), มันจะ         
     ถูกอัฟเดตเป็น last setting. หมายเหตุ: ในกรณีของการใช้ของ internal measurement channels (VrefInt/TempSensor),
     sampling time constraints ต้องถูกเคารพ (sampling time สามารถถูกปรับใน function of ADC clock frequency และ
     sampling time setting) ดูที่ device datasheet สำหรับ timings values, parameters TS_vrefint, TS_temp (ค่าลำดับ
     คร่าวๆ: 5us ถึง 17.1us ขั้นต่ำ).

tha

7.1.3 ADC_AnalogWDGConfTypeDef
ADC_AnalogWDGConfTypeDef ถูกกำหนดใน the stm32f1xx_hal_adc.h
Data Fields
•   uint32_t WatchdogMode
•   uint32_t Channel
•   FunctionalState ITMode
•   uint32_t HighThreshold
•   uint32_t LowThreshold
•   uint32_t WatchdogNumber


Field Documentation
•   uint32_t ADC_AnalogWDGConfTypeDef::WatchdogMode
     กำหนดค่า the ADC analog watchdog mode: single/all channels, regular/injected group. parameter นี้สามารถเป็นค่า
     หนึ่งของ      ADC_analog_watchdog_mode.
•   uint32_t ADC_AnalogWDGConfTypeDef::Channel
     เลือก ADC channel ที่จะมอนิเตอร์โดย analog watchdog. parameter นี้มีผลเฉพาะถ้า watchdog mode ถูกกำหนดค่าใน
     single channel (parameter      WatchdogMode) parameter นี้สามารถเป็นค่าหนึ่งของ ADC_channels.
•   FunctionalState ADC_AnalogWDGConfTypeDef::ITMode
     ระบุว่า the analog watchdog ถูกกำหนดค่าใน interrupt หรือ polling mode. parameter นี้สามารถถูกเซ็ตเป็น ENABLE หรือ
     DISABLE
•   uint32_t ADC_AnalogWDGConfTypeDef::HighThreshold
     กำหนดค่า the ADC analog watchdog High threshold value. parameter ต้องเป็นตัวเลขระหว่าง Min_Data = 0x000 and
     Max_Data = 0xFFF.
•   uint32_t ADC_AnalogWDGConfTypeDef::LowThreshold
     กำหนดค่า the ADC analog watchdog High threshold value. parameter ต้องเป็นตัวเลขระหว่าง Min_Data = 0x000 and
     Max_Data = 0xFFF.
•   uint32_t ADC_AnalogWDGConfTypeDef::WatchdogNumber
     สงวนไว้สำหรับการใช้ในอนาคต, สามารถถูกเซ็ตเป็น 0


tha


tha

7.2 ADC Firmware driver API description

The following section แสดงรายการ the various functions of the ADC library.

7.2.1 ADC peripheral features
•   12-bit resolution
•   Interrupt generation ที่ the end of regular conversion, end of injected conversion, และในกรณีของ analog
     watchdog หรือ overrun events.
•   Single and continuous conversion modes.
•   Scan mode สำหรับ conversion ของหลายชาแนลอย่างมีลำดับ.
•   Data alignment with in-built data coherency.
•   Programmable sampling time (channel wise)
•   ADC conversion of regular group and injected group.
•   External trigger (timer or EXTI) สำหรับทั้ง regular and injected groups.
•   DMA request generation for transfer of conversions data of regular group.
•   Multimode Dual mode (available on devices with 2 ADCs or more).
•   Configurable DMA data storage in Multimode Dual mode (มีให้ใช้งานบน devices ที่มี 2 ADCs หรือมากกว่า).
•   Configurable delay between conversions in Dual interleaved mode (มีให้ใช้งานบน devices ที่มี 2 ADCs หรือมากกว่า).
•   ADC calibration
•   ADC supply requirements: 2.4 V to 3.6 V ที่ full speed และต่ำถึง 1.8 V ที่ slower speed.
•   ADC input range: จาก Vref- (ต่อถึง Vssa) ถึง Vref+ (ต่อถึง Vdda หรือถึง an external voltage reference).

tha

7.2.2 How to use this driver

Configuration of top level parameters related to ADC
1.   เปิดใช้งาน the ADC interface
     –   ตามข้อกำหนดเบื้องต้น, ADC clock ต้องถูกกำหนดค่าที่ RCC top level. ข้อควรระวัง: บน STM32F1, ADC clock frequency
          max คือ 14MHz (ดูที่ device datasheet). ดังนั้น, ADC clock prescaler ต้องถูกกำหนดค่าใน function of ADC clock
          source frequency เพื่อให้ยังคงต่ำกว่า maximum frequency นี้.
     –   clock setting หนึ่งรายการคือข้อบังคับ: ADC clock (core clock, อาจเป็น conversion clock ด้วย).
          ◦   ตัวอย่าง: Into HAL_ADC_MspInit() (code location ที่แนะนำ) หรือด้วย device clock parameters configuration
              อื่น:
          ◦   RCC_PeriphCLKInitTypeDef PeriphClkInit;
          ◦   __ADC1_CLK_ENABLE();
          ◦   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
          ◦   PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV2;
          ◦   HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
2.   ADC pins configuration
     –   เปิดใช้งาน the clock สำหรับ the ADC GPIOs โดยใช้ macro __HAL_RCC_GPIOx_CLK_ENABLE()
     –   กำหนดค่า ADC pins เหล่านี้ใน analog mode โดยใช้ function HAL_GPIO_Init()
3.   เป็นทางเลือก, ในกรณีของการใช้ของ ADC พร้อมกับ interruptions:
     –   กำหนดค่า the NVIC for ADC โดยใช้ function HAL_NVIC_EnableIRQ(ADCx_IRQn)
     –   ใส่ the ADC interruption handler function HAL_ADC_IRQHandler() ลงใน the function of corresponding ADC
          interruption vector ADCx_IRQHandler().
4.   เป็นทางเลือก, ในกรณีของการใช้ของ DMA:
     –   กำหนดค่า the DMA (DMA channel, mode normal or circular, ...) โดยใช้ function HAL_DMA_Init().
     –   กำหนดค่า the NVIC สำหรับ DMA โดยใช้ function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn)
     –   ใส่ the ADC interruption handler function HAL_ADC_IRQHandler() ลงใน the function of corresponding DMA
          interruption vector DMAx_Channelx_IRQHandler().

tha

Configuration of ADC, groups regular/injected, channels parameters
1.   กำหนดค่า the ADC parameters (resolution, data alignment, ...) and regular group parameters (conversion
      trigger, sequencer, ...) โดยใช้ function HAL_ADC_Init().
2.   กำหนดค่า the channels สำหรับ regular group parameters (channel number, channel rank ลงใน sequencer, ...,
      ลงใน regular group) โดยใช้ function HAL_ADC_ConfigChannel().
3.   เป็นทางเลือก, กำหนดค่า the injected group parameters (conversion trigger, sequencer, ..., of injected group) และ
      the channels for injected group parameters (channel number, channel rank into sequencer, ..., into injected
      group) โดยใช้ function HAL_ADCEx_InjectedConfigChannel().
4.   เป็นทางเลือก, กำหนดค่า the analog watchdog parameters (channels monitored, thresholds, ...) โดยใช้ function
      HAL_ADC_AnalogWDGConfig().
5.   เป็นทางเลือก, สำหรับ devices ที่มีหลาย ADC instances: กำหนดค่า the multimode parameters โดยใช้ function
      HAL_ADCEx_MultiModeConfigChannel().

tha

Execution of ADC conversions
1.   เป็นทางเลือก, ดำเนินการ an automatic ADC calibration เพื่อปรับ the conversion accuracy ให้ดีขึ้นโดยใช้ function
      HAL_ADCEx_Calibration_Start().
2.   ADC driver สามารถถูกใช้ในหมู่ three modes: polling, interruption, ส่งถ่ายโดย DMA.
      –   ADC conversion by polling:
          ◦   เปิดใช้งาน the ADC peripheral และสตาร์ท conversions โดยใช้ function HAL_ADC_Start()
          ◦   รอสำหรับ ADC conversion completion โดยใช้ function HAL_ADC_PollForConversion() (หรือสำหรับ injected
              group: HAL_ADCEx_InjectedPollForConversion() )
          ◦   ดึง conversion results โดยใช้ function HAL_ADC_GetValue() (หรือสำหรับ injected group:
              HAL_ADCEx_InjectedGetValue() )
          ◦   หยุด conversion และปิดใช้งาน the ADC peripheral โดยใช้ function HAL_ADC_Stop()
     –   ADC conversion by interruption:
          ◦   เปิดใช้งาน the ADC peripheral และสตาร์ท conversions โดยใช้ function HAL_ADC_Start_IT()
          ◦   รอสำหรับ ADC conversion completion โดยการเรียกของ function HAL_ADC_ConvCpltCallback() (ฟังชั่นนี้ต้องถูก
              จัดให้มีใช้ใน user program) (หรือสำหรับ injected group: HAL_ADCEx_InjectedConvCpltCallback() )
          ◦   ดึง conversion results โดยใช้ function HAL_ADC_GetValue() (หรือสำหรับ injected group:
              HAL_ADCEx_InjectedGetValue() )
          ◦   หยุด conversion และปิดใช้งาน the ADC peripheral โดยใช้ function HAL_ADC_Stop_IT()
     –   ADC conversion with transfer by DMA:
          ◦   เปิดใช้งาน the ADC peripheral และสตาร์ท conversions โดยใช้ function HAL_ADC_Start_DMA()
          ◦   รอสำหรับ ADC conversion completion โดยการเรียกของ function HAL_ADC_ConvCpltCallback() หรือ
              HAL_ADC_ConvHalfCpltCallback() (ฟังชั่นเหล่านี้ต้องถูกจัดให้มีใช้ใน user program)
          ◦   Conversion results ถูกส่งถ่ายโดยอัตโนมัติโดย DMA ลงใน destination variable address.
          ◦   หยุด conversion และปิดใช้งาน the ADC peripheral โดยใช้ function HAL_ADC_Stop_DMA()
     –   สำหรับ devices ที่มีหลาย ADCs: ADC multimode conversion ด้วยการส่งถ่ายโดย DMA:
          ◦   เปิดใช้งาน the ADC peripheral (slave) และสตาร์ท conversions โดยใช้ function HAL_ADC_Start()
          ◦   เปิดใช้งาน the ADC peripheral (master) และสตาร์ท conversions โดยใช้ function
              HAL_ADCEx_MultiModeStart_DMA()
          ◦   รอสำหรับ ADC conversion completion โดยการเรียกของ function HAL_ADC_ConvCpltCallback() หรือ
              HAL_ADC_ConvHalfCpltCallback() (ฟังชั่นเหล่านี้ต้องถูกจัดให้มีใช้ใน user program)
          ◦   Conversion results ถูกส่งถ่ายโดยอัตโนมัติโดย DMA ลงใน destination variable address.
          ◦   หยุด conversion และปิดใช้งาน the ADC peripheral (master) โดยใช้ function
              HAL_ADCEx_MultiModeStop_DMA()
          ◦   หยุด conversion และปิดใช้งาน the ADC peripheral (slave) โดยใช้ function HAL_ADC_Stop_IT()

Note: Callback functions ต้องถูกจัดให้มีใช้ใน user program:
      •   HAL_ADC_ErrorCallback()
      •   HAL_ADC_LevelOutOfWindowCallback() (callback of analog watchdog)
      •   HAL_ADC_ConvCpltCallback()
      •   HAL_ADC_ConvHalfCpltCallback
      •   HAL_ADCEx_InjectedConvCpltCallback()