STM32F1 ADC HAL

Started by tha, September 17, 2020, 09:42:20 AM

Previous topic - Next topic

tha

11.9.8 Combined regular simultaneous + alternate trigger mode
มันเป็นไปได้ที่จะอินเตอรัพท์ regular group simultaneous conversion เพื่อไปสตาร์ท alternate trigger conversion ของ an injected group. Figure 36 แสดงพฤติกรรมของ an alternate trigger อินเตอรัพท์ a regular simultaneous conversion.

The injected alternate conversion ถูกสตาร์ทโดยทันทีหลังจาก the injected event มาถึง. ถ้า regular conversion กำลังรันอยู่, เพื่อให้แน่ใจว่า synchronization(การเกิดขึ้นพร้อมกัน) หลังจาก the injected conversion, the regular conversion ของทั้ง (master/slave) ADCs ถูกหยุดและกลับคืนมาพร้อมกันที่การสิ้นสุดของ the injected conversion.

Note: ใน combined regular simultaneous + alternate trigger mode, the same sampling time ที่เท่ากันเป๊ะควรถูกกำหนดสำหรับ the two channels ที่จะถูกสุ่มพร้อมกันโดย ACD1 และ ADC2.



ถ้า a trigger เกิดขึ้นในระหว่าง an injected conversion ที่ไปอินเตอรัพท์ a regular conversion, มันจะถูกเพิกเฉย. Figure 37 แสดงพฤติกรรมของกรณีนี้ (the second trigger ถูกเพิกเฉย).



tha

11.9.9 Combined injected simultaneous + interleaved
มันเป็นไปได้ที่จะอินเตอรัพท์ an interleaved conversion ด้วย an injected event. ในกรณีนี้ the interleaved conversion ถูกอินเตอรัพท์และ the injected conversion สตาร์ท, ที่การสิ้นสุดของ the injected sequence the interleaved conversion ถูกคืนกลับ. Figure 38 แสดงพฤติกรรมการใช้ตัวอย่างนี้.

Note: เมื่อ the ADC clock prescaler ถูกเซ็ตเป็น 4, the interleaved mode ไม่กู้คืนด้วย sampling periods ที่เว้นระยะโดยสม่ำเสมอ: the sampling interval คือ 8 ADC clock periods ติดตามโดย 6 ADC clock periods, แทนที่จะเป็น 7 clock periods ติดตามโดย 7 clock periods.


tha

11.10 Temperature sensor
The temperature sensor สามารถถูกใช้วัด the ambient temperature (TA) ของ the device.

The temperature sensor ถูกต่อภายในถึง the ADCx_IN16 input channel ซึ่งถูกใช้เพื่อแปลง the sensor output voltage ไปเป็น a digital value. The recommended sampling time สำหรับ the temperature sensor คือ 17.1 μs.

The block diagram ของ the temperature sensor ถูกแสดงใน Figure 39.

เมื่อไม่ได้ใช้, sensor นี้สามารถถูกใส่ไว้ใน power down mode.

Note: The TSVREFE bit ต้องถูกเซ็ตเพื่อเปิดการใช้งานทั้ง internal channels: ADCx_IN16 (temperature sensor) และ ADCx_IN17 (VREFINT) conversion.

The temperature sensor output voltage เปลี่ยนแปลงเชิงเส้นตามอุณหภูมิ The offset ของ line นี้แตกต่างกันจากชิปหนึ่งไปยังชิปหนึ่งเนื่องจากความแตกต่างกันของขบวนการผลิต (มากถึง 45 °C จากชิปหนึ่งไปยังชิปอื่นๆ).

The internal temperature sensor เหมาะมากกับ applications ที่ตรวจจับ temperature variations แทนที่จะเป็น absolute temperatures. ถ้า accurate temperature readings ถูกต้องการ, an external temperature sensor part ควรถูกใช้.



Reading the temperature
เพื่อใช้ the sensor:
1. เลือก the ADCx_IN16 input channel.
2. เลือก a sample time เป็น 17.1 μs
3. เซ็ต the TSVREFE bit ใน the ADC control register 2 (ADC_CR2) เพื่อปลุก the temperature sensor จาก power down mode.
4. สตาร์ท the ADC conversion โดยการเซ็ต the ADON bit (หรือโดย external trigger).
5. อ่าน the resulting VSENSE data ใน the ADC data register
6. ได้มาซึ่ง the temperature โดยใช้สูตรดังต่อไปนี้ :
     Temperature (in °C) = {(V25 - VSENSE) / Avg_Slope} + 25.
     เมื่อ,
     V25 = VSENSE value for 25° C และ
     Avg_Slope = Average Slope สำหรับ curve ระหว่าง Temperature vs. VSENSE (ถูกให้ใน mV/° C หรือ μV/ °C).

อ้างอิงถึง the Electrical characteristics section สำหรับค่าที่แท้จริงของ V25 และ Avg_Slope.

Note: The sensor มี a startup time หลังจากการปลุกจาก power down mode ก่อนมันสามารถเอ๊าพุท VSENSE ที่ระดับที่ถูกต้อง. The ADC ก็มี a startup time หลังจาก power-on, ดังนั้นเพื่อลดการหน่วงเวลา, the ADON และ TSVREFE bits ควรถูกเซ็ตที่เวลาเดียวกัน.

ปล. มีไม่เคลียร์ก็ที่ "The offset ของ line" ก็ยังไม่เข้าใจอยู่ ไม่รู้แปลถูกหรือเปล่า ช่วยดูกันด้วยนะครับ


tha

ก็มีตัวอย่างเก่าอยู่ สำหรับการวัด Temp วัด Vref ใช้ DMA ด้วย เป็นโปรแกรม CooCox ก็ลองดัดแปลงดู
http://www.mediafire.com/file/z6gh1q8wz4rp1r0/ADC_DMA.rar/file

tha

11.11 ADC interrupts
An interrupt สามารถถูกทำให้เกิดขึ้นบนการสิ้นสุดของ conversion สำหรับ regular และ injected groups และเมื่อ the analog watchdog status bit ถูกเซ็ต. Separate(แยกต่างหาก) interrupt enable bits มีให้ใช้สำหรับความยืดหยุ่น.

Note: ADC1 และ ADC2 interrupts ถูก mapped เข้าด้วยกันบน the same interrupt vector. ADC3 interrupts ถูก
mapped บน a separate(แยกต่างหาก) interrupt vector.

2 flags อื่นอีกที่แสดงใน the ADC_SR register, แต่ไม่มี interrupt ที่เกี่ยวพันกับมัน :
     • JSTRT (Start of conversion for injected group channels)
     • STRT (Start of conversion for regular group channels)


tha

11.12 ADC registers
อ้างถึงส่วน 2.2 ในหน้า 45 สำหรับรายการตัวย่อที่ใช้ใน register descriptions.
The peripheral registers สามารถถูกเข้าถึงโดย words (32-bit).



Bits 31:5 สงวนไว้, ต้องถูกเก็บไว้ที่ค่ารีเซ็ต.
Bit 4 STRT: Regular channel Start flag
บิตนี้ถูกเซ็ตโดย hardware เมื่อ regular channel conversion สตาร์ท. มันถูกเคลียร์โดย software.
     0: ไม่มี regular channel conversion ถูกสตาร์ท
     1: Regular channel conversion ถูกสตาร์ทแล้ว

Bit 3 JSTRT: Injected channel Start flag
บิตนี้ถูกเซ็ตโดย hardware เมื่อ injected channel group conversion สตาร์ท. มันถูกเคลียร์โดย software.
     0: ไม่มี injected group conversion ถูกสตาร์ท
     1: Injected group conversion ถูกสตาร์ทแล้ว

Bit 2 JEOC: Injected channel end of conversion
บิตนี้ถูกเซ็ตโดย hardware ที่การสิ้นสุดของ injected group channel conversion ทั้งหมด.  มันถูกเคลียร์โดย software.
     0: Conversion ยังไม่เสร็จสมบูรณ์
     1: Conversion เสร็จสมบูรณ์

Bit 1 EOC: End of conversion
บิตนี้ถูกเซ็ตโดย hardware ที่การสิ้นสุดของ a group channel conversion (regular หรือ injected). มันถูกเคลียร์โดย software หรือโดยการอ่าน the ADC_DR.
     0: Conversion ยังไม่เสร็จสมบูรณ์
     1: Conversion เสร็จสมบูรณ์

Bit 0 AWD: Analog watchdog flag
บิตนี้ถูกเซ็ตโดย hardware เมื่อ the converted voltage ข้ามค่าที่โปรแกรมใน the ADC_LTR and ADC_HTR registers. มันถูกเคลียร์โดย software.
     0: ไม่มี Analog watchdog event เกิดขึ้น
     1: Analog watchdog event เกิดขึ้น

tha



Bits 31:24 สงวนไว้, ต้องถูกเก็บไว้ที่ค่ารีเซ็ต.
Bit 23 AWDEN: Analog watchdog enable on regular channels
บิตนี้ถูกเซ็ต/รีเซ็ตโดย software.
     0: Analog watchdog ปิดการใช้งานอยู่บน regular channels
     1: Analog watchdog เปิดการใช้งานอยู่บน regular channels

Bit 22 JAWDEN: Analog watchdog enable on injected channels
บิตนี้ถูกเซ็ต/รีเซ็ตโดย software.
     0: Analog watchdog ปิดการใช้งานอยู่บน injected channels
     1: Analog watchdog เปิดการใช้งานอยู่บน injected channels

Bits 21:20 สงวนไว้, ต้องถูกเก็บไว้ที่ค่ารีเซ็ต.
Bits 19:16 DUALMOD[3:0]: Dual mode selection
บิตนี้ถูกเขียนโดย software เพื่อเลือก the operating mode.
     0000: Independent mode.
     0001: Combined regular simultaneous + injected simultaneous mode
     0010: Combined regular simultaneous + alternate trigger mode
     0011: Combined injected simultaneous + fast interleaved mode
     0100: Combined injected simultaneous + slow Interleaved mode
     0101: Injected simultaneous mode only
     0110: Regular simultaneous mode only
     0111: Fast interleaved mode only
     1000: Slow interleaved mode only
     1001: Alternate trigger mode only
Note: บิตเหล่านี้ถูกสงวนไว้ใน ADC2 และ ADC3.
ใน dual mode, การเปลี่ยนแปลงของการกำหนดค่าชาแนลทำให้เกิดการรีสตาร์ทที่สามารถสร้างการสูญเสียของ synchronization(การประสานกัน). สนับสนุนให้ปิดการใช้งาน dual mode ก่อนการเปลี่ยนการกำหนดค่าใดๆ.

Bits 15:13 DISCNUM[2:0]: Discontinuous mode channel count
บิตเหล่านี้ถูกเขียนโดย software เพื่อกำหนดจำนวนของ regular channels ที่จะถูกแปลงใน discontinuous mode, หลังจากการรับ an external trigger.
     000: 1 channel
     001: 2 channels
     .......
     111: 8 channels

Bit 12 JDISCEN: Discontinuous mode on injected channels
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable discontinuous mode บน injected group channels
     0: Discontinuous mode on injected channels ปิดการใช้งานอยู่
     1: Discontinuous mode on injected channels เปิดการใช้งานอยู่

Bit 11 DISCEN: Discontinuous mode on regular channels
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable Discontinuous mode บน regular channels.
     0: Discontinuous mode on regular channels ปิดการใช้งานอยู่
     1: Discontinuous mode on regular channels เปิดการใช้งานอยู่

Bit 10 JAUTO: Automatic Injected Group conversion
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable automatic injected group conversion หลังจาก regular group conversion.
     0: Automatic injected group conversion ปิดการใช้งานอยู่
     1: Automatic injected group conversion เปิดการใช้งานอยู่

Bit 9 AWDSGL: Enable the watchdog on a single channel in scan mode
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable the analog watchdog บน the channel ระบุโดย the AWDCH[4:0] bits.
     0: Analog watchdog เปิดการใช้งานอยู่บนทุก channels
     1: Analog watchdog เปิดการใช้งานอยู่บน a single channel

Bit 8 SCAN: Scan mode
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable Scan mode. ใน Scan mode, the inputs ถูกเลือกผ่านทาง the ADC_SQRx หรือ ADC_JSQRx registers ถูกแปลง.
     0: Scan mode ปิดการใช้งานอยู่
     1: Scan mode เปิดการใช้งานอยู่
Note: An EOC หรือ JEOC interrupt ถูกทำให้เกิดขึ้นเพียงการสิ้นสุดของ conversion ของชาแนลสุดท้าย ถ้า the corresponding(ที่ตรงกัน) EOCIE หรือ JEOCIE bit ถูกเซ็ต

Bit 7 JEOCIE: Interrupt enable for injected channels
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable the end of conversion interrupt สำหรับ injected channels.
     0: JEOC interrupt ปิดการใช้งานอยู่
     1: JEOC interrupt เปิดการใช้งานอยู่. An interrupt ถูกทำให้เกิดขึ้นเมื่อ the JEOC bit ถูกเซ็ต.

Bit 6 AWDIE: Analog watchdog interrupt enable
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable the analog watchdog interrupt.
     0: Analog watchdog interrupt ปิดการใช้งานอยู่
     1: Analog watchdog interrupt เปิดการใช้งานอยู่

Bit 5 EOCIE: Interrupt enable for EOC
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable the End of Conversion interrupt.
     0: EOC interrupt ปิดการใช้งานอยู่
     1: EOC interrupt เปิดการใช้งานอยู่. An interrupt ถูกทำให้เกิดขึ้นเมื่อ the EOC bit ถูกเซ็ต.

Bits 4:0 AWDCH[4:0]: Analog watchdog channel select bits
บิตเหล่านี้เซ็ตและเคลียร์โดย software. มันเลือก the input channel ที่จะถูกปกป้องโดย the Analog watchdog.
     00000: ADC analog Channel0
     00001: ADC analog Channel1
     ....
     01111: ADC analog Channel15
     10000: ADC analog Channel16
     10001: ADC analog Channel17
     ค่าอื่นๆถูกสงวนไว้.
Note: ADC1 analog Channel16 และ Channel17 ถูกต่อภายในถึง the temperature sensor และถึง VREFINT, ตามลำดับ.
         ADC2 analog inputs Channel16 และ Channel17 ถูกต่อภายในถึง VSS.
         ADC3 analog inputs Channel9, Channel14, Channel15, Channel16 and Channel17 ถูกต่อถึง VSS.

tha



Bits 31:24 สงวนไว้, ต้องถูกเก็บไว้ที่ค่ารีเซ็ต.

Bit 23 TSVREFE: Temperature sensor and VREFINT enable
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable the temperature sensor และ VREFINT channel. ใน mcu เบอร์ที่มี dual ADCs บิตนี้มีอยู่ใน ADC1 เท่านั้น.
     0: Temperature sensor and VREFINT channel disabled
     1: Temperature sensor and VREFINT channel enabled

Bit 22 SWSTART: Start conversion of regular channels
บิตนี้เซ็ตโดย software เพื่อ start conversion และเคลียร์โดย hardware ทันทีที่ conversion สตาร์ท. มันสตาร์ท a conversion ของ a group ของ regular channels ถ้า SWSTART ถูกเลือกเป็น trigger event โดย the EXTSEL[2:0] bits.
     0: Reset state
     1: Starts conversion of regular channels

Bit 21 JSWSTART: Start conversion of injected channels
บิตนี้เซ็ตโดย software เพื่อ start conversion และเคลียร์โดย hardware ทันทีที่ conversion สตาร์ท. มันสตาร์ท a conversion ของ a group ของ injected channels (ถ้า JSWSTART ถูกเลือกเป็น trigger event โดย the JEXTSEL[2:0] bits.
     0: Reset state
     1: Starts conversion of injected channels

Bit 20 EXTTRIG: External trigger conversion mode for regular channels
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable the external trigger ใช้เพื่อสตาร์ท conversion ของ a regular channel group.
     0: Conversion on external event disabled
     1: Conversion on external event enabled

Bits 19:17 EXTSEL[2:0]: External event select for regular group
บิตเหล่านี้เลือก the external event ใช้เพื่อทริก the start of conversion ของ a regular group:
สำหรับ ADC1 และ ADC2, ทริกที่กำหนดคือ :
     000: Timer 1 CC1 event
     001: Timer 1 CC2 event
     010: Timer 1 CC3 event
     011: Timer 2 CC2 event
     100: Timer 3 TRGO event
     101: Timer 4 CC4 event
     110: EXTI line 11/TIM8_TRGO event (TIM8_TRGO มีให้ใช้ใน high-density and XLdensity devices เท่านั้น)
     111: SWSTART

     สำหรับ ADC3, ทริกที่กำหนดคือ:
     000: Timer 3 CC1 event
     001: Timer 2 CC3 event
     010: Timer 1 CC3 event
     011: Timer 8 CC1 event
     100: Timer 8 TRGO event
     101: Timer 5 CC1 event
     110: Timer 5 CC3 event
     111: SWSTART

Bit 16 Reserved, must be kept at reset value.

Bit 15 JEXTTRIG: External trigger conversion mode for injected channels
บิตนี้เซ็ตและเคลียร์โดย software เพื่อ enable/disable the external trigger ใช้เพื่อสตาร์ท conversion ของ an injected channel group.
     0: Conversion on external event disabled
     1: Conversion on external event enabled

Bits 14:12 JEXTSEL[2:0]: External event select for injected group
บิตเหล่านี้เลือก the external event used ใช้เพื่อทริก the start of conversion of an injected group:
For ADC1 and ADC2 the assigned triggers are:
     000: Timer 1 TRGO event
     001: Timer 1 CC4 event
     010: Timer 2 TRGO event
     011: Timer 2 CC1 event
     100: Timer 3 CC4 event
     101: Timer 4 TRGO event
     110: EXTI line15/TIM8_CC4 event (TIM8_CC4 is available only in high-density and XLdensity devices)
     111: JSWSTART

     For ADC3 the assigned triggers are:
     000: Timer 1 TRGO event
     001: Timer 1 CC4 event
     010: Timer 4 CC3 event
     011: Timer 8 CC2 event
     100: Timer 8 CC4 event
     101: Timer 5 TRGO event
     110: Timer 5 CC4 event
     111: JSWSTART

Bit 11 ALIGN: Data alignment
บิตนี้เซ็ตและเคลียร์โดย software. อ้างอิงถึง Figure 27.and Figure 28.
     0: Right Alignment
     1: Left Alignment

Bits 10:9 Reserved, must be kept at reset value.
Bit 8 DMA: Direct memory access mode
บิตนี้เซ็ตและเคลียร์โดย software. อ้างอิงถึง the DMA controller chapter สำหรับรายละเอียดที่มากขึ้น.
     0: DMA mode disabled
     1: DMA mode enabled
มีเพียง ADC1 และ ADC3 เท่านั้นที่สามารถทำให้เกิด a DMA request.

Bits 7:4 Reserved, must be kept at reset value.

Bit 3 RSTCAL: Reset calibration
บิตนี้เซ็ตโดย software และเคลียร์โดย hardware. มันจะถูกเคลียร์หลังจาก the calibration registers ถูกเริ่มต้น.
     0: Calibration register เริ่มต้นไปแล้ว.
     1: เริ่มต้น calibration register.
Note: ถ้า RSTCAL ถูกเซ็ตเมื่อ conversion กำลังดำเนินอยู่, จำเป็นต้องมี cycles เพิ่มเติมเพื่อเคลียร์ the calibration registers.

Bit 2 CAL: A/D Calibration
บิตนี้เซ็ตโดย software เพื่อ start the calibration. มันถูกรีเซ็ตโดย hardware หลังจาก calibration เสร็จสมบูรณ์.
     0: Calibration เสร็จสมบูรณ์แล้ว
     1: Enable calibration

Bit 1 CONT: Continuous conversion
บิตนี้ถูกเซ็ตและเคลียร์โดย software. ถ้าเซ็ตการแปลงเกิดขึ้นอย่างต่อเนื่องจนกระทั่งบิตนี้ถูกรีเซ็ต.
     0: Single conversion mode
     1: Continuous conversion mode

Bit 0 ADON: A/D converter ON / OFF
บิตนี้ถูกเซ็ตและเคลียร์โดย software. หากบิตนี้มีค่าเป็นศูนย์อยู่และ1 ถูกเขียนไปยังมัน เมื่อนั้นมันจะ wakes up the ADC จาก Power Down state.
Conversion สตาร์ทเมื่อบิตนี้มีค่าเป็น 1 อยู่และ 1 ถูกเขียนไปยังมัน. The application ควรยอมให้มีการหน่วงเวลาของ tSTAB ระหว่าง power up และ start of conversion. อ้างอิงถึง Figure 23.
     0: Disable ADC conversion/calibration and go to power down mode.
     1: Enable ADC and to start conversion
Note: ถ้าบิตอื่นๆใน register นี้นอกเหนือจาก ADON ถูกเปลี่ยนในเวลาเดียวกัน, เมื่อนั้น conversion จะไม่ถูกทริก. นี้เป็นการป้องกันการทริกการแปลงที่ผิดพลาด.