STM32F7 22 Advanced-control timers (TIM1/TIM8)

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

Previous topic - Next topic

tha

Center-aligned mode (up/down counting)

ใน center-aligned mode, the counter นับจาก 0 ไปยัง the auto-reload value (สิ่งที่จุอยู่ภายในของ the TIMx_ARR register) – 1, สร้าง a counter overflow event, จากนั้นนับจาก the autoreload value ลงไปยัง 1 และสร้าง a counter underflow event. จากนั้นมันเริ่มการนับใหม่จาก 0.

Center-aligned mode จะทำงานเมื่อ the CMS bits ใน TIMx_CR1 register ไม่เท่ากับ '00'. The Output compare interrupt flag ของ channels ที่กำหนดค่าเป็น output จะถูกเซ็ตเมื่อ : the counter นับลง (Center aligned mode 1, CMS = "01"), the counter นับขึ้น (Center aligned mode 2, CMS = "10") the counter นับขึ้นและลง (Center aligned mode 3, CMS = "11").

ในโหมดนี้, the direction bit (DIR จาก TIMx_CR1 register) ไม่สามารถถูกเขียน. มันถูกอัปเดตโดย hardware และให้ทิศทางปัจจุบันของ the counter

tha

The update event สามารถถูกสร้างที่แต่ละ counter overflow และที่แต่ละ counter underflow หรือโดยการเซ็ต the UG bit ใน the TIMx_EGR register (โดย software หรือโดยการใช้ the slave mode controller) สร้าง an update event ได้อีกด้วย. ในกรณีนี้, the counter เริ่มใหม่การนับจาก 0, เช่นเดียวกันกับ the counter ของ the prescaler.

The UEV event สามารถถูกปิดการใช้งานโดย software โดยการเซ็ต the UDIS bit ใน TIMx_CR1 register. นี้เพื่อหลีกเลี่ยงการอัปเดต the shadow registers ในขณะที่เขียนค่าใหม่ใน the preload registers. ดังน้้นไม่มี update event เกิดขึนจนกว่า the UDIS bit ถูกเขียนเป็น 0. อย่างไรก็ตาม, the counter นับขึ้นและลงอย่างต่อเนื่อง, ตาม the current auto-reload value.

นอกจากนี้, หาก the URS bit (update request selection) ใน TIMx_CR1 register ถูกเซ็ต, การเซ็ต the UG bit จะสร้าง an update event UEV แต่ปราศจากการเซ็ต the UIF flag (ดังนั้นไม่มี interrupt หรือ DMA request ถูกส่ง). นี้เพื่อหลีกเลี่ยงการสร้างทั้ง update และจับ interrupts เมื่อเคลียร์ the counter บน the capture event.

tha

เมื่อ an update event เกิดขึ้น, ทุก the registers จะถูกอัปเดตและ the update flag (UIF bit ใน TIMx_SR register) จะถูกเซ็ต (ขึ้นอยู่กับ the URS bit):
•    The repetition counter ถูกโหลดใหม่ด้วย the content ของ TIMx_RCR register.
•    The buffer ของ the prescaler ถูกโหลดใหม่ด้วย the preload value (สิ่งที่จุอยู่ภายในของ the TIMx_PSC register)
•    The auto-reload active register ถูกอัปเดตด้วย the preload value (สิ่งที่จุอยู่ภายในของ the TIMx_ARR register) บันทึกไว้
      ว่าถ้า the update source คือ a counter overflow, the auto-reload จะถูกอัปเดตก่อน the counter ถูกโหลดใหม่, ดังนั้น the
      next period คือสิ่งที่คาดไว้ (the counter ถูกโหลดด้วย the new value).

รูปดังต่อไปนี้แสดงบางตัวอย่างของ the counter behavior สำหรับ clock frequencies ต่างๆ









tha

22.3.3 Repetition counter

Section 22.3.1: Time-base unit อธิบายวิธีที่ the update event (UEV) ถูกสร้างด้วยเคารพต่อ the counter overflows/underflows. มันถูกสร้างได้จริงเฉพาะเมื่อ the repetition counter ถึงศูนย์แล้วเท่านั้น. นี้เป็นประโยชน์เมื่อสร้าง PWM signals.

นี้หมายความว่า data ถูกส่งถ่ายจาก the preload registers ไปยัง the shadow registers (TIMx_ARR auto-reload register, TIMx_PSC prescaler register, แต่ TIMx_CCRx capture/compare registers ใน compare mode อีกด้วย) ทุกๆ N+1 counter overflows หรือ underflows, ที่ N คือค่าใน the TIMx_RCR repetition counter register.

The repetition counter ถูกลดลง:
•    ที่แต่ละ counter overflow ใน upcounting mode,
•    ที่แต่ละ counter underflow ใน downcounting mode,
•    ที่แต่ละ counter overflow และที่แต่ละ counter underflow ใน center-aligned mode. แม้ว่าจะจำกัด the maximum
      number ของ repetition ไว้ที่ 32768 PWM cycles, มันทำให้มันสามารถเป็นได้ที่จะอัปเดต the duty cycle สองครั้งต่อ PWM
      period. เมื่อรีเฟรช compare registers เพียงครั้งเดียวต่อ PWM period ใน center-aligned mode, maximum resolution
      คือ 2xTck, เนื่องจากความสมมาตรของรูปแบบ.

tha

The repetition counter เป็น an auto-reload type; the repetition rate ถูกคงไว้ตามที่กำหนดโดย the TIMx_RCR register value (อ้างอิงถึง Figure 169). เมื่อ the update event ถูกสร้างโดย software (โดยการเซ็ต the UG bit ใน TIMx_EGR register) หรือโดย hardware ผ่านทาง the slave mode controller, มันเกิดขึ้นโดยทันทีไม่ว่าค่าของ the repetition counter คืออะไรและ the repetition counter จะถูกโหลดใหม่ด้วยสิ่งที่จุอยู่ภายในของ the TIMx_RCR register.

ใน center-aligned mode, สำหรับค่าคี่ของ RCR, the update event เกิดขึ้นอย่างใดอย่างหนึ่งบน the overflow หรือบน the underflow ขึ้นอยู่กับเมื่อไหร่ the RCR register ถูกเขียนและเมื่อไหร่ the counter ถูกเริ่ม. ถ้า the RCR ถูกเขียนก่อนการเริ่ม the counter, the UEV จะเกิดขึ้นบน the overflow. ถ้า the RCR ถูกเขียนหลังจากการเริ่ม the counter, the UEV จะเกิดขึ้นบน the underflow.

ตัวอย่างเช่น, สำหรับ RCR = 3, the UEV ถูกสร้างบนแต่ละ 4th overflow หรือ underflow event ขึ้นอยู่กับเมื่อไหร่ RCR ถูกเขียน.


Update event : Preload register ส่งถ่ายถึง active register และ update interrupt ถูกสร้าง
Update Event : ถ้า the repetition counter underflow เกิดขึ้นเมื่อ the counter เท่ากันกับ the auto-reload value

tha

22.3.4 External trigger input

The timer มี an external trigger input ETR. มันสามารถถูกใช้เป็น:
•   external clock (external clock mode 2, ดู Section 22.3.5)
•   trigger สำหรับ the slave mode (ดู Section 22.3.25)
•   PWM reset input สำหรับ cycle-by-cycle current regulation (ดู Section 22.3.7)

Figure 170 ข้างล่างอธิบาย the ETR input conditioning. The input polarity ถูกกำหนดด้วย the ETP bit in TIMxSMCR register. The trigger สามารถถูกปรับล่วงหน้าด้วยตัวหารที่โปรแกรมโดย the ETPS[1:0] bitfield และ digitally filtered ด้วย the ETF[3:0] bitfield.


tha

22.3.5 Clock selection

The counter clock สามารถถูกจัดให้มีโดย clock sources ต่อไปนี้:
•    Internal clock (CK_INT)
•    External clock mode1: external input pin (TIx)
•    External clock mode2: external trigger input (ETR).
•    Encoder mode

Internal clock source (CK_INT)

ถ้า the slave mode controller ถูกปิดการใช้งาน (SMS=000), ดังนั้น the CEN, DIR (ใน the TIMx_CR1 register) และ UG bits (ใน the TIMx_EGR register) เป็น actual control bits และสามารถถูกเปลี่ยนได้เพียงโดย software (ยกเว้น UG ซึ่งยังคงถูกเคลียร์โดยอัตโนมัติ). ทันทีที่ the CEN bit ถูกเขียนเป็น 1, the prescaler ถูกให้สัญญานนาฬิกาโดย the internal clock C K_INT.

Figure 171 แสดงลักษณะการทำงานของ the control circuit และ the upcounter ใน normal mode, โดยไม่มี prescaler.


tha

External clock source mode 1

โหมดนี้ถูกเลือกเมื่อ SMS=111 ใน the TIMx_SMCR register. The counter สามารถนับที่แต่ละขอบขาขึ้นหรือขอบขาลงบนอินพุทที่เลือก.



ตัวอย่างเช่น, ในการกำหนดค่า the upcounter เพื่อนับที่ตอบสนองต่อ a rising edge บน the TI2 input, ใช้ขบวนการดังต่อไปนี้:
1.    กำหนดค่า channel 2 เพื่อตรวจจับ rising edges บน the TI2 input โดยการเขียน CC2S= '01 ใน the TIMx_CCMR1
       register.
2.    กำหนดค่า the input filter duration โดยการเขียน the IC2F[3:0] bits ใน the TIMx_CCMR1 register (ถ้าไม่มี filter ถูก
       ต้องการ, ให้เก็บ IC2F=0000).
3.    เลือก rising edge polarity โดยการเขียน CC2P=0 และ CC2NP=0 ใน the TIMx_CCER register
4.    กำหนดค่า the timer ใน external clock mode 1 โดยการเขียน SMS=111 ใน the TIMx_SMCR register.
5.    เลือก TI2 เป็น the input source โดยการเขียน TS=110 ใน the TIMx_SMCR register.
6.    เปิดการใช้งาน the counter โดยการเขียน CEN=1 ใน the TIMx_CR1 register

Note: The capture prescaler ไม่ได้ถูกใช้สำหรับการทริก, ดังนั้นผู้ใช้ไม่มีความจำเป็นต้องกำหนดค่ามัน.

เมื่อ a rising edge เกิดขึ้นบน TI2, the counter นับหนึ่งครั้งและ the TIF flag ถูกเซ็ต.

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