STM32F7 22 Advanced-control timers (TIM1/TIM8)

Started by tha, December 26, 2022, 03:05:39 PM

Previous topic - Next topic

tha

22.3.25 Timer synchronization

The TIMx timers ถูกเชื่อมต่อเข้าด้วยกันภายในสำหรับ timer synchronization หรือ chaining. พวกมันสามารถถูกซิงโครไนซ์ในหลายโหมด: Reset mode, Gated mode, and Trigger mode.

Slave mode: Reset mode

The counter และ prescaler ของมันสามารถถูกเริ่มต้นใหม่โดยตอบสนองต่อ an event บน a trigger input. ยิ่งไปกว่านั้น, ถ้า the URS bit จาก the TIMx_CR1 register เป็น low, an update event UEV จะถูกสร้าง. จากนั้นทุก the preloaded registers (TIMx_ARR, TIMx_CCRx) จะถูกอัปเดต.

ในตัวอย่างต่อไปนี้, the upcounter จะถูกเคลียร์เพื่อตอบสนองต่อ a rising edge บน TI1 input:
•    กำหนดค่า the channel 1 เพื่อตรวจจับ rising edges บน TI1. กำหนดค่า the input filter duration (ในตัวอย่างนี้, เราไม่ต้องการ
      filter ใดๆ, ดังนั้นเราเก็บ IC1F=0000). The capture prescaler ไม่ถูกใช้สำหรับการทริก, ดังนั้นคุณไม่จำเป็นต้องกำหนดค่ามัน.
      The CC1S bits เลือก the input capture source เท่านั้น, CC1S = 01 ใน the TIMx_CCMR1 register. เขียน CC1P=0 and
      CC1NP='0' ใน TIMx_CCER register เพื่อตรวจสอบ the polarity (และตรวจจับ rising edges เท่านั้น).
•    กำหนดค่า the timer ใน reset mode โดยการเขียน SMS=100 ใน TIMx_SMCR register. เลือก TI1 เป็น the input source
      โดยการเขียน TS=101 ใน TIMx_SMCR register.
•    สตาร์ท the counter โดยการเขียน CEN=1 ใน the TIMx_CR1 register.

The counter สตาร์ทการนับบน the internal clock, จากนั้นจะทำงานตามปกติจนกระทั่ง TI1 rising edge. เมื่อ TI1 พุ่งขึ้น, the counter จะถูกเคลียร์และสตาร์ทใหม่จาก 0. ในขณะเดียวกัน, the trigger flag จะถูกเซ็ต (TIF bit ใน the TIMx_SR register) และ an interrupt request, หรือ a DMA request สามารถถูกส่งถ้าเปิดการใช้งาน (ขึ้นอยู่กับ the TIE และ TDE bits ใน TIMx_DIER register).

รูปต่อไปนี้แสดงพฤติกรรมนี้เมื่อ the auto-reload register TIMx_ARR=0x36. The delay ระหว่าง the rising edge บน TI1 และ the actual reset ของ the counter ที่เนื่องมาจาก the resynchronization circuit บน TI1 input.


tha

Slave mode: Gated mode

The counter สามารถถูกเปิดการใช้งานขึ้นอยู่กับ the level ของ a selected input.

ในตัวอย่างต่อไปนี้, the upcounter นับเพียงเมื่อ TI1 input เป็น low เท่านั้น:
•    กำหนดค่า the channel 1 เพื่อตรวจจับ low levels บน TI1. กำหนดค่า the input filter duration (ในตัวอย่างนี้, เราไม่ต้องการ
      filter ใดๆ, ดังนั้นเราเก็บ IC1F=0000). The capture prescaler ไม่ถูกใช้สำหรับการทริก, ดังนั้นคุณไม่จำเป็นต้องกำหนดค่ามัน.
      The CC1S bits เลือก the input capture source เท่านั้น, CC1S = 01 ใน the TIMx_CCMR1 register. เขียน CC1P=1 and
      CC1NP='0' ใน TIMx_CCER register เพื่อตรวจสอบ the polarity (และตรวจจับ low level เท่านั้น).
•    กำหนดค่า the timer ใน gated mode โดยการเขียน SMS=101 ใน TIMx_SMCR register. เลือก TI1 เป็น the input source
      โดยการเขียน TS=101 ใน TIMx_SMCR register
•    เปิดการใช้งาน the counter โดยการเขียน CEN=1 ใน the TIMx_CR1 register (ใน gated mode, the counter จะไม่สตาร์ทถ้า
      CEN=0, ไม่ว่า the trigger input level เป็นอะไรก็ตาม).

The counter สตาร์ทการนับบน the internal clock ตราบเท่าที่ TI1 เป็น low และหยุดทันทีที่ TI1 กลายมาเป็น high. The TIF flag ใน the TIMx_SR register ถูกเซ็ตทั้งเมื่อ the counter สตาร์ทหรือหยุด.

The delay ระหว่าง the rising edge บน TI1 และ the actual stop ของ the counter ที่เนื่องมาจาก the resynchronization circuit บน TI1 input.


tha

Slave mode: Trigger mode

The counter สามารถสตาร์ทโดยตอบสนองต่อ an event บน a selected input.

ในตัวอย่างต่อไปนี้, the upcounter สตาร์ทโดยตอบสนองต่อ a rising edge บน TI2 input:
•    กำหนดค่า the channel 2 เพื่อตรวจจับ rising edges บน TI2. กำหนดค่า the input filter duration (ในตัวอย่างนี้, เราไม่ต้องการ
      filter ใดๆ, ดังนั้นเราเก็บ IC2F=0000). The capture prescaler ไม่ถูกใช้สำหรับการทริก, ดังนั้นคุณไม่จำเป็นต้องกำหนดค่ามัน.
      The CC2S bits ถูกกำหนดค่าเพื่อเลือก the input capture source เท่านั้น, CC2S = 01 ใน the TIMx_CCMR1 register.
      เขียน CC2P=1 and CC2NP=0 ใน TIMx_CCER register เพื่อตรวจสอบ the polarity (และตรวจจับ low level เท่านั้น).
•    กำหนดค่า the timer ใน trigger mode โดยการเขียน SMS=110 ใน TIMx_SMCR register. เลือก TI2 เป็น the input
      source โดยการเขียน TS=110 ใน TIMx_SMCR register.

เมื่อ a rising edge เกิดขึ้นบน TI2, the counter สตาร์ทการนับบน the internal clock และ the TIF flag ถูกเซ็ต

The delay ระหว่าง the rising edge บน TI2 และ the actual start ของ the counter ที่เนื่องมาจาก the resynchronization circuit บน TI2 input.



tha

Slave mode: Combined reset + trigger mode

ในกรณีนี้, a rising edge ของ the selected trigger input (TRGI) เริ่มต้นใหม่ the counter, สร้างการอัฟเดตของ the registers, และสตาร์ท the counter.

โหมดนี้ถูกใช้สำหรับ one-pulse mode.

tha

Slave mode: External Clock mode 2 + trigger mode

The external clock mode 2 สามารถถูกใช้นอกเหนือไปจาก slave mode อื่นๆ (ยกเว้น external clock mode 1 และ encoder mode). ในกรณีนี้, the ETR signal ถูกใช้เป็น external clock input, และ input อื่นสามารถถูกเลือกเป็น trigger input เมื่อทำงานใน reset mode, gated mode หรือ trigger mode. แนะนำไม่ให้เลือก ETR เป็น TRGI ผ่านทาง the TS bits ของ TIMx_SMCR register.

ในตัวอย่างต่อไปนี้, the upcounter ถูกเพิ่มขึ้นที่แต่ละ rising edge ของ the ETR signal ทันทีที่ a rising edge ของ TI1 เกิดขึ้น
1.    กำหนดค่า the external trigger input circuit โดยการโปรแกรม the TIMx_SMCR register ดังต่อไปนี้:
        –   ETF = 0000: ไม่มี filter
        –   ETPS = 00: prescaler ถูกปิดการใช้งาน
        –   ETP = 0: การตรวจจับของ rising edges บน ETR และ ECE=1 เพื่อเปิดการใช้งาน the external clock mode 2.
2.    กำหนดค่า the channel 1 ดังต่อไปนี้, เพื่อตรวจจับ rising edges บน TI:
        –   IC1F = 0000: ไม่มี filter.
        –   The capture prescaler ไม่ถูกใช้สำหรับการทริกเกอร์และไม่จำเป็นต้องกำหนดค่า.
        –   CC1S = 01 ใน TIMx_CCMR1 register เพื่อเลือกเฉพาะ the input capture source
        –   CC1P = 0 ใน TIMx_CCER register เพื่อตรวจสอบ the polarity (และตรวจจับ rising edge เท่านั้น).
3.    กำหนดค่า the timer ใน trigger mode โดยการเขียน SMS=110 ใน TIMx_SMCR register. เลือก TI1 เป็น the input
       source โดยการเขียน TS=101 ใน TIMx_SMCR register

A rising edge บน TI1 เปิดการใช้งาน the counter และเซ็ต the TIF flag. The counter จากนั้นนับบน ETR rising edges.

The delay ระหว่าง the rising edge ของ the ETR signal และ the actual reset ของ the counter เนื่องมาจาก the resynchronization circuit บน ETRP input.



Note: The clock of the slave peripherals (timer, ADC, ...) ที่ได้รับ the TRGO or the TRGO2 signals ต้องถูกเปิดใช้งานก่อน
          เพื่อรับ events จาก the master timer, และ the clock frequency (prescaler) ต้องไม่ถูกเปลี่ยนกลางทางในระหว่าง
          triggers ถูกรับจาก the master timer.

tha

22.3.26 ADC synchronization

The timer สามารถสร้าง an ADC triggering event ด้วย internal signals ต่างๆ, อย่างเช่น reset, enable หรือ compare events. มันยังเป็นไปได้ที่จะสร้าง a pulse ที่ปล่อยออกโดย internal edge detectors, อย่างเช่น:
     –   Rising and falling edges of OC4ref
     –   Rising edge on OC5ref or falling edge on OC6ref

The triggers ถูกปล่อยออกบน the TRGO2 internal line ซึ่งถูกเปลี่ยนเส้นทางไปยัง the ADC. มีทั้งหมด 16 possible events, ซึ่งสามารถถูกเลือกโดยใช้ the MMS2[3:0] bits ใน the TIMx_CR2 register.

ตัวอย่างของ an application สำหรับ 3-phase motor drives ถูกให้ไว้ใน Figure 187 บนหน้า 682.

Note: The clock of the slave peripherals (timer, ADC, ...) ที่ได้รับ the TRGO or the TRGO2 signals ต้องถูกเปิดใช้งานก่อน
          เพื่อรับ events จาก the master timer, และ the clock frequency (prescaler) ต้องไม่ถูกเปลี่ยนกลางทางในระหว่าง
          triggers ถูกรับจาก the master timer.

Note: The clock of the ADC ต้องถูกเปิดใช้งานก่อนเพื่อรับ events จาก the master timer, และต้องไม่ถูกเปลี่ยนกลางทางในระหว่าง
          triggers ถูกรับจาก the timer.

tha

22.3.27 DMA burst mode

The TIMx timers มีความสามารถในการสร้างหลาย DMA requests ต่อ a single event. จุดประสงค์หลักคือสามารถตั้งโปรแกรมใหม่ในส่วนของ the timer ได้หลายครั้งโดยไม่มี software overhead, แต่มันยังสามารถถูกใช้อ่านหลาย registers ติดต่อกัน, เป็นระยะ.

The DMA controller destination มีอยู่อันเดียวและต้องชี้ไปยัง the virtual register TIMx_DMAR. บน a given timer event, the timer เริ่มลำดับของ DMA requests (ส่งข้อมูลเป็นชุดอย่างเร็ว). แต่ละการเขียนลงใน the TIMx_DMAR register จริง ๆ แล้วจะถูกเปลี่ยนเส้นทางไปยังหนึ่งใน the timer registers.

The DBL[4:0] bits ใน the TIMx_DCR register เซ็ต the DMA burst length. The timer รับรู้ a burst transfer เมื่อ a read or a write access ถูกทำไปยัง the TIMx_DMAR address), เช่นจำนวนของการส่งถ่าย (อย่างใดอย่างหนึ่งใน half-words หรือใน bytes).

The DBA[4:0] bits ใน the TIMx_DCR registers กำหนด the DMA base address สำหรับ DMA transfers (เมื่อ read/write access ถูกทำผ่านทาง the TIMx_DMAR address). DBA ถูกกำหนดเป็น an offset ที่สตาร์ทจาก the address of the TIMx_CR1 register:

Example:
00000: TIMx_CR1
00001: TIMx_CR2
00010: TIMx_SMCR

tha

ตัวอย่างเช่น, the timer DMA burst feature ถูกใช้เพื่ออัฟเดตสิ่งที่จุอยู่ภายในของ the CCRx registers (x = 2, 3, 4) เมื่อ an update event, ด้วย the DMA จะส่งถ่าย half words ลงใน the CCRx registers

นี้ถูกทำในขั้นตอนต่อไปนี้
1.   กำหนดค่า the corresponding DMA channel ดังต่อไปนี้:
      –   DMA channel peripheral address คือ the DMAR register address
      –   DMA channel memory address คือ the address of the buffer ใน the RAM ที่บรรจุ the data ที่จะถูกส่งโดย DMA
           ลงใน CCRx registers.
      –   จำนวนของ data ที่จะส่ง = 3 (ดูหมายเหตุข้างล่าง).
      –   Circular mode ถูกปิดใช้งาน
2.   กำหนดค่า the DCR register โดยการกำหนดค่า the DBA and DBL bit fields ดังต่อไปนี้:
      DBL = 3 transfers, DBA = 0xE.
3.   เปิดใช้งาน the TIMx update DMA request (เซ็ต the UDE bit in the DIER register).
4.   เปิดใช้งาน TIMx
5.   เปิดใช้งาน the DMA channel

ตัวอย่างนี้ใช้สำหรับกรณีที่ทุก CCRx register ได้รับการอัพเดตหนึ่งครั้ง. ถ้าทุก CCRx register จะต้องถูกอัพเดท 2 ครั้ง ตัวอย่างเช่น, จำนวนของ data ที่จะส่งถ่ายควรเป็น 6. เอาล่ะนำตัวอย่างของ a buffer ใน the RAM ที่บรรจุ data1, data2, data3, data4, data5 and data6. The data ถูกส่งไปยัง the CCRx registers ดังต่อไปนี้: ตอน the first update DMA request, data1 ถูกส่งถ่ายไปยัง CCR2, data2 ถูกส่งถ่ายไปยัง CCR3, data3 ถูกส่งถ่ายไปยัง CCR4 และตอน the second update DMA request, data4 ถูกส่งถ่ายไปยัง CCR2, data5 ถูกส่งถ่ายไปยัง CCR3 and data6 ถูกส่งถ่ายไปยัง CCR4.

Note: A null value สามารถถูกเขียนไปยัง the reserved registers.