STM32F1 ADC HAL

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

Previous topic - Next topic

tha

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

Note: เมื่อใช้ triggered injection, ช่วงเวลาระหว่าง trigger events ต้องยาวนานกว่า the injection sequence. ตัวอย่างเช่น, ถ้า the sequence length เป็น 28 ADC clock cycles (นั่นคือมี 2 conversions พร้อมด้วยหนึ่ง a 1.5 clock-period sampling time), ช่วงเวลาที่สั้นที่สุดระหว่าง triggers ต้องเป็น 29 ADC clock cycles.

tha

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

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

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

สำหรับ ADC clock prescalers ย่านจาก 4 ถึง 8, การหน่วงเวลาหนึ่งคาบ ADC clock จะถูกใส่โดยอัตโนมัติเมื่อสวิทชิ่งจาก regular ไปยัง injected sequence ( injected ไปยัง regular ตามลำดับ). เมื่อ the ADC clock prescaler ถูกเซ็ตเป็น 2, the delay คือ 2 ADC clock periods.

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


tha

11.3.10 Discontinuous mode
Regular group
mode นี้ถูกเปิดการใช้งานโดยการเซ็ต 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 L[3:0] bits ใน the ADC_SQR1 register.

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

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


tha

Injected group
โหมดนี้ถูกเปิดการใช้งานโดยการเซ็ต the JDISCEN bit ใน the ADC_CR1 register. มันสามารถถูกใช้เพื่อแปลง the sequence ที่เลือกใน the ADC_JSQR register, channel ตาม 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
     first trigger: channel 1 ถูกแปลง
     second trigger: channel 2 ถูกแปลง
     third trigger: channel 3 ถูกแปลงและ EOC และ JEOC events ถูกสร้างขึ้น
     fourth trigger: channel 1

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

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

ผู้ใช้ต้องหลีกเลี่ยงการเซ็ต discontinuous mode สำหรับทั้ง regular และ injected groups เข้าด้วยกัน. Discontinuous mode ต้องถูกเปิดการใช้งานสำหรับ one group conversion เท่านั้น.

tha

11.4 Calibration
The ADC มี an built-in self calibration mode. การสอบเทียบช่วยลดความผิดพลาดที่ละเอียดเนื่องมาจาก internal capacitor bank variations(การเปลี่ยนแปลง) . ในระหว่าง calibration, an error-correction code (digital word) ถูกคำนวนสำหรับแต่ละ capacitor, และในระหว่างลำดับย่อยของการแปลงทั้งหมด, การสนับสนุนให้เกิดความผิดพลาดของแต่ละ capacitor ถูกเอาออกโดยใช้ code นี้.

Calibration ถูกสตาร์ทโดยการเซ็ต the CAL bit ใน the ADC_CR2 register. เมื่อการสอบเทียบเสร็จแล้ว, the CAL bit ถูกรีเซ็ตโดย hardware และการแปลงปกติสามารถถูกทำงานได้. ขอแนะนำให้ปรับเทียบ ADC หนึ่งครั้งเมื่อเปิดเครื่อง The calibration codes ถูกเก็บใน the ADC_DR ทันทีที่ the calibration phase ends.

Note: ขอแนะนำให้กระทำการ calibration หลังจากแต่ละ power-up.

ก่อนการสตาร์ท calibration, the ADC ต้องถูกอยู่ใน power-on state (ADON bit = '1') 2 ADC clock cycles เป็นอย่างน้อย.


tha

11.5 Data alignment
ALIGN bit ใน the ADC_CR2 register เลือกการวางแนวของ data เก็บหลังจาก conversion. Data สามารถวางแนวชิดซ้ายหรือชิดขวาดังแสดงในรูปที่ 27. และรูปที่ 28.

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

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



ปล. เป็นอย่างไรกันบ้าง แปลกันเป็นแล้วหรือยัง ไม่น่าจะยาก คำศัพย์มีไม่กี่ตัว ส่วนมากคู่มือจะมีรูปแบบประโยคเป็น passive voice ประธานเป็นผู้ถูกกระทำ มีรูปประโยคเป็น  ประธาน + verb to be + verb ช่องที่ 3 ตามที่ผมแปลว่า "ถูก" โน้น "ถูก" นี่ นั่นแหละครับ

tha

11.6 Channel-by-channel programmable(ที่โปรแกรมได้) sample time
ADC สุ่ม the input voltage เป็นจำนวนหนึ่งของ ADC_CLK cycles ซึ่งสามารถถูกโมดิฟายด์โดยใช้ the SMP[2:0] bits ใน the ADC_SMPR1 และ ADC_SMPR2 registers. แต่ละ channel สามารถถูกสุ่มด้วย a different sample time(เวลาสุ่มที่ต่างกัน).

The total conversion time ถูกคำนวณดังต่อไปนี้ :
     Tconv = Sampling time + 12.5 cycles

ตัวอย่าง:
     ด้วย an ADCCLK = 14 MHz และ a sampling time เท่ากับ 1.5 cycles:
     Tconv = 1.5 + 12.5 = 14 cycles = 1 μs

tha

11.7 Conversion on external trigger
Conversion สามารถถูกทริกโดย an external event (ตัวอย่างเช่น timer capture, EXTI line). ถ้า the EXTTRIG control bit ถูกเซ็ตเมื่อนั้น external events สามารถที่จะทริก a conversion. The EXTSEL[2:0] และ JEXTSEL[2:0] control bits ยอมให้ the application เลือกตัดสินใจจาก 8 events ที่เป็นได้ให้สามารถทริก conversion สำหรับ the regular และ injected groups.

Note: เมื่อ an external trigger ถูกเลือกสำหรับ ADC regular หรือ injected conversion, มีเพียงขอบขาขึ้นของสัญญานเท่านั้นที่สามารถสตาร์ท the conversion.



1. The TIM8_TRGO event มีใน high-density และ XL-density devices เท่านั้น.
2. การเลือกของ the external trigger EXTI line11 หรือ TIM8_TRGO event สำหรับ regular channels ถูกทำได้โดยผ่านการกำหนดค่าบิต ADC1_ETRGREG_REMAP และ ADC2_ETRGREG_REMAP สำหรับ ADC1 และ ADC2, ตามลำดับ.



The software source trigger events สามารถถูกทำให้เกิดขึ้นโดยการเซ็ตบิตนี้ใน a register (SWSTART และ JSWSTART ใน ADC_CR2).

A regular group conversion สามารถถูกอินเตอรัพท์โดย an injected trigger.