STM32F7 15 Analog-to-digital converter (ADC)

Started by tha, September 01, 2022, 06:48:47 AM

Previous topic - Next topic

tha

15.3.6 Continuous conversion mode

ใน continuous conversion mode, the ADC จะสตาร์ท a new conversion ทันทีที่มันสำเร็จการแปลงหนึ่งแล้ว. โหมดนี้ถูกสตาร์ทด้วย the CONT bit ที่ 1 อย่างใดอย่างหนึ่ง โดย external trigger หรือโดยการเซ็ต the SWSTRT bit ใน the ADC_CR2 register (สำหรับ regular channels เท่านั้น).

หลังจากการแปลงแต่ละครั้ง :
•   ถ้า a regular group of channels ถูกแปลงเสร็จแล้ว:
     –   The last converted data ถูกเก็บไว้ใน the 16-bit ADC_DR register
     –   The EOC (End Of Conversion) flag ถูก set
     –   An interrupt จะถูกสร้างขึ้นถ้า the EOCIE bit ถูกเซ็ต

Note: Injected channels ไม่สามารถถูกแปลงอย่างต่อเนื่องได้. ข้อยกเว้นเดียวคือเมื่อ an injected channel ถูกกำหนดค่าให้ถูกแปลง
         โดยอัตโนมัติหลังจาก regular channels ใน continuous mode (โดย JAUTO bit), โปรดดู Auto-injection section).


tha

15.3.7 Timing diagram

ดังแสดงในรูป Figure 74, the ADC ต้องการ a stabilization time tSTAB ก่อนที่มันจะสตาร์ทการแปลงอย่างเที่ยงตรง. หลังจากการสตาร์ทของ ADC conversion และหลังจากนั้นอีก 15 clock cycles, the EOC flag จะถูกเซ็ตและ the 16-bit ADC Data register บรรจุผลของการแปลง.


tha

15.3.8 Analog watchdog

The AWD analog watchdog status bit ถูกเซ็ตถ้า the analog voltage ที่แปลงโดย the ADC อยู่ต่ำกว่าขอบเขตทางต่ำ( low threshold)หรืออยู่เหนือกว่าขอบเขตทางสูง( high threshold). thresholds เหล่านี้ถูกโปรแกรมใน the 12 least significant bits(12 บิตทางต่ำ) ของ the ADC_HTR และ ADC_LTR 16-bit registers. An interrupt สามารถถูกเปิดการใช้งานโดยการใช้ the AWDIE bit ใน the ADC_CR1 register.

ค่าของขอบเขตเป็นอิสระจากการวางแนว(ชิดขวา/ชิดซ้าย)ที่เลือกโดย the ALIGN bit ใน the ADC_CR2 register. The analog voltage ถูกเปรียบเทียบกับ the lower and higher thresholds ก่อนที่จะวางแนว.

Table 94 แสดงวิธีที่ the ADC_CR1 register ควรถูกกำหนดค่าเพื่อเปิดใช้งาน the analog watchdog บนหนึ่งชาแนลหรือมากกว่า.





tha

15.3.9 Scan mode

mode นี้ถูกใช้สแกนกลุ่มของ analog channels.

Scan mode ถูกเลือกโดยการเซ็ต the SCAN bit ใน the ADC_CR1 register. เมื่อบิตนี้ถูกเซ็ต, ADC จะสแกน the channels ทั้งหมดที่ถูกเลือกใน the ADC_SQRx registers (สำหรับ regular channels) หรือใน the ADC_JSQR (สำหรับ injected channels). การแปลงเพียงครั้งเดียวถูกกระทำสำหรับแต่ละชาแนลของกลุ่ม. หลังจากจบแต่ละการแปลง ชาแนลถัดไปของกลุ่มจะถูกแปลงโดยอัตโนมัติ. ถ้า the CONT bit ถูกเซ็ต, conversion จะไม่หยุดที่่ชาแนลสุดท้ายที่เลือกของกลุ่ม แต่จะทำการแปลงต่ออีกจากชาแนลแรกที่เลือกของกลุ่ม

ถ้า DMA bit ต้องถูกเซ็ตและ the direct memory access controller ถูกใช้เพื่อส่งถ่าย the data ที่แปลงแล้วจาก regular group ของ channels ไปยัง SRAM หลังจากแต่ละ regular channel conversion.

The EOC bit ถูกเซ็ตใน the ADC_SR register:
•   ที่ the end ของแต่ละ regular group sequence ถ้า the EOCS bit ถูกเคลียร์เป็น 0
•   ที่ the end ของแต่ละ regular channel conversion ถ้า the EOCS bit ถูกเซ็ตเป็น 1

The data ที่แปลงแล้วจาก an injected channel จะถูกเก็บไว้ใน the ADC_JDRx registers เสมอ.

tha

15.3.10 Injected channel management

Triggered injection

เพื่อใช้ triggered injection, the JAUTO bit ต้องถูกเคลียร์ใน the ADC_CR1 register.
1.   สตาร์ทการแปลงของกลุ่มของ regular channels อย่างใดอย่างหนึ่งโดย external trigger หรือโดยการเซ็ต the SWSTART bit ใน
      the ADC_CR2 register .
2.   ถ้า an external injected trigger เกิดขึ้นหรือถ้า the JSWSTART bit ถูกเซ็ตในระหว่าง the conversion of a regular group
      of channels, การแปลงปัจจุบันจะถูกรีเซ็ตและ the injected channel sequence จะสลับไปเป็น Scan once mode.
3.  จากนั้น, the regular conversion of the regular group of channels จะถูกกลับมาทำงานต่อจาก the last interrupted
     regular conversion.
     ถ้า a regular event เกิดขึ้นในระหว่าง an injected conversion, the injected conversion จะไม่ถูกอินเตอร์รัพท์แต่ the
     regular sequence จะถูกปฏิบัติที่ the end ของ the injected sequence. Figure 76 แสดง the corresponding timing
     diagram.

Note: เมื่อใช้ triggered injection, ช่วงเวลาระหว่าง trigger events ต้องยาวนานกว่า the injection sequence. ตัวอย่างเช่น, ถ้า
         the sequence length เป็น 30 ADC clock cycles (นั่นคือมี 2 conversions ที่มีเวลาสุ่ม 3 clock periods), ช่วงเวลาที่สั้น
         ที่สุดระหว่าง triggers ต้องเป็น 31 ADC clock cycles.


Auto-injection

ถ้า the JAUTO bit ถูกเซ็ต, เมื่อนั้น the channels ใน the injected group ถูกแปลงโดยอัตโนมัติหลังจาก the regular group of channels.. นี้สามารถถูกใช้เพื่อแปลง a sequence ได้มากถึง 20 conversions ที่โปรแกรมใน the ADC_SQRx and ADC_JSQR registers.

ใน mode นี้, external trigger บน injected channels ต้องถูกปิดการใช้งาน.

ถ้า the CONT bit ถูกเซ็ตด้วยพร้อมกันกับ the JAUTO bit, regular channels ถูกตามโดย injected channels จะถูกแปลงอย่างต่อเนื่อง

Note: มันเป็นไปไม่ได้ที่จะใช้ทั้ง the auto-injected และ discontinuous modes พร้อมกัน.


tha

15.3.11 Discontinuous mode

Regular group

โหมดนี้ถูกเปิดการใช้งานโดยการเซ็ต the DISCEN bit ใน the ADC_CR1 register. มันสามารถถูกใช้เพื่อแปลงลำดับสั้นๆของการแปลงจำนวน n (n <=8) ซึ่งเป็นส่วนหนึ่งของลำดับของการแปลงที่ถูกเลือกใน in the ADC_SQRx registers. ค่าของ n ถูกระบุโดยการเขียนไปยัง the DISCNUM[2:0] bits ใน the ADC_CR1 register.

เมื่อ an external trigger เกิดขึ้น, มันจะสตาร์ทการแปลงจำนวน n ถัดไปที่ถูกเลือกใน the ADC_SQRx registers จนกระทั่งการแปลงทั้งหมดใน the sequence ถูกกระทำแล้วเสร็จ. The total sequence length ถูกกำหนดโดย the L[3:0] bits ใน the ADC_SQR1 register.

ตัวอย่างเช่น:
     n = 3, channels ที่จะถูกแปลง = 0, 1, 2, 3, 6, 7, 9, 10
     1st trigger: ลำดับการแปลง 0, 1, 2. An EOC event ถูกสร้างที่แต่ละการแปลง
     2nd trigger: ลำดับการแปลง 3, 6, 7. An EOC event ถูกสร้างที่แต่ละการแปลง
     3rd trigger: ลำดับการแปลง 9, 10. An EOC event ถูกสร้างที่แต่ละการแปลง
     4th trigger: ลำดับการแปลง 0, 1, 2. An EOC event ถูกสร้างที่แต่ละการแปลง

Note: เมื่อ a regular group ถูกแปลงใน discontinuous mode, การวนรอบจะไม่เกิดขึ้น.
          เมื่อกลุ่มย่อยทั้งหมดถูกแปลง, การทริกถัดไปจะสตาร์ทการแปลงของกลุ่มย่อยแรก. ในตัวอย่างข้างบน, การทริกครั้งที่ 4 จะแปลงซ้ำ
          กลุ่มย่อยแรก channels 0, 1 และ 2.


Injected group

โหมดนี้ถูกเปิดการใช้งานโดยการเซ็ต the JDISCEN bit ใน the ADC_CR1 register. มันสามารถถูกใช้เพื่อแปลง the sequence ที่เลือกใน the ADC_JSQR register, ทีละ channel, หลังจาก an external trigger event.

เมื่อ an external trigger เกิดขึ้น, มันจะสตาร์ท the next channel conversions ที่เลือกใน the ADC_JSQR registers จนกระทั่ง the conversions ทั้งหมดใน the sequence ถูกกระทำแล้วเสร็จ. The total sequence length ถูกกำหนดโดย the JL[1:0] bits ใน the ADC_JSQR register.

ตัวอย่าง:
     n = 1, channels ที่ถูกแปลง = 1, 2, 3
     1st trigger: channel 1 ถูกแปลง
     2nd trigger: channel 2 ถูกแปลง
     3rd trigger: channel 3 ถูกแปลงและ EOC และ JEOC events ถูกสร้างขึ้น
     4th trigger: channel 1

Note: เมื่อ injected channels ทั้งหมดถูกแปลง, the next trigger จะสตาร์ทการแปลงของ the first injected channel. ในตัวอย่าง
          ข้างบน, the fourth trigger จะแปลงซ้ำใหม่ the first injected channel 1.

          มันไม่สามารถใช้ทั้ง auto-injected และ discontinuous modes ได้พร้อมกัน.

         Discontinuous mode ต้องไม่ถูกเซ็ตสำหรับ regular and injected groups ในเวลาเดียวกัน.
         Discontinuous mode ต้องถูกเปิดใช้งานเฉพาะสำหรับ the conversion of one group.

tha

15.4 Data alignment

ALIGN bit ใน the ADC_CR2 register เลือกการวางแนวของ data ที่เก็บหลังจาก conversion. Data สามารถวางแนวชิดซ้ายหรือชิดขวาดังแสดงใน Figure 77 and Figure 78.

The converted data value จาก the injected group of channels ถูกลดลงโดย the user-defined offset(ค่าหักลงที่ผู้ใช้กำหนด) ที่ถูกเขียนไว้ใน the ADC_JOFRx registers ดังนั้นผลที่ได้สามารถถูกทำให้เป็นค่าลบ. The SEXT bit เป็น the extended sign value.(ค่าเครื่องหมายที่เพิ่มมา)

สำหรับ regular group channels ไม่มี offset มาลบ ดังนั้นมีเพียง 12 bits เป็นนัยสำคัญ.


กรณีพิเศษ: เมื่อจัดชิดซ้าย, the data จะถูกจัดเรียงบน a half-word basis ยกเว้นเมื่อ the resolution ถูกเซ็ตเป็น 6-bit. ในกรณีนั้น, the data จะถูกจัดเรียงบน a byte basis ดังแสดงใน Figure 79.

tha

15.5 Channel-wise programmable sampling time

The ADC จะสุ่ม the input voltage เป็นเวลาจำนวนของ ADCCLK cycles ที่สามารถถูกแก้ไขโดยใช้ the SMP[2:0] bits ใน the ADC_SMPR1 and ADC_SMPR2 registers. แต่ละ channel สามารถถูกสุ่มด้วยเวลาสุ่มที่แตกต่างกัน.

The total conversion time ถูกคำนวณดังต่อไปนี้:

       Tconv = Sampling time + 12 cycles

Example:

       ด้วย ADCCLK = 30 MHz และ sampling time = 3 cycles:

       Tconv = 3 + 12 = 15 cycles = 0.5 μs ด้วย APB2 ที่ 60 MHz