STM32F7 22 Advanced-control timers (TIM1/TIM8)

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

Previous topic - Next topic

tha

22 Advanced-control timers (TIM1/TIM8)

22.1 TIM1/TIM8 introduction

The advanced-control timers (TIM1/TIM8) ประกอบด้วย a 16-bit auto-reload counter ที่ขับโดย a programmable prescaler.

มันอาจถูกใช้เพื่อวัตถุประสงค์ที่หลากหลาย, รวมถึงการวัด the pulse lengths of input signals (input capture) หรือการสร้าง output waveforms (output compare, PWM, complementary PWM ที่มีการใส่ dead-time).

Pulse lengths and waveform periods สามารถถูกมอดูเลตได้ตั้งแต่ไม่กี่ไมโครวินาทีไปจนถึงหลายมิลลิวินาทีโดยใช้ the timer prescaler and the RCC clock controller prescalers.

The advanced-control (TIM1/TIM8) and general-purpose (TIMy) timers เป็นอิสระอย่างสมบูรณ์และไม่แบ่งปันทรัพยากรใด ๆ พวกมันสามารถถูกซิงโครไนซ์เข้าด้วยกันตามที่อธิบายไว้ใน Section 22.3.25: Timer synchronization.

tha

22.2 TIM1 and TIM8 main features

TIM1 and TIM8 timer features ประกอบด้วย :
   •   16-bit up, down, up/down auto-reload counter.
   •   16-bit programmable prescaler ยอมให้การหาร ("ได้ทันที" อีกด้วย) the counter clock frequency โดยแฟ็คเตอร์ใดแฟ็ค
        เตอร์หนึ่งระหว่าง 1 และ 65536.
   •   มากถึง 4 independent channels สำหรับ:
        –   Input capture
        –   Output compare
        –   PWM generation (Edge- and Center-aligned modes)
        –   One-pulse mode output
   •   Complementary outputs ที่มี programmable dead-time
   •   Synchronization circuit เพื่อควบคุม the timer ด้วย external signals และเชื่อมต่อ timers หลายตัวเข้าด้วยกัน.
   •   ตัวนับการทำซ้ำ(Repetition counter)เพื่ออัปเดต the timer registers เฉพาะหลังจากจำนวนที่ให้ไว้ของรอบของ the counter
   •   2 break inputs เพื่อใส่ the timer's output signals ใน a safe user selectable configuration.
   •   Interrupt/DMA generation ตามเหตุการณ์ดังต่อไปนี้:
        –   Update: counter overflow/underflow, counter initialization (โดย software หรือ internal/external trigger)
        –   Trigger event (counter start, stop, initialization หรือนับโดย internal/external trigger)
        –   Input capture
        –   Output compare
   •   รองรับ incremental (quadrature) encoder และ hall-sensor circuitry สำหรับ positioning purposes
   •   Trigger input สำหรับ external clock หรือ cycle-by-cycle current management



tha

22.3 TIM1 and TIM8 functional description

22.3.1 Time-base unit

The main block ของ the programmable advanced-control timer คือ a 16-bit counter พร้อมด้วย related auto-reload register ของมัน. The counter สามารถนับขึ้น, ลง หรือทั้งขึ้นและลง. The counter clock สามารถถูกหารโดย a prescaler.

The counter, the auto-reload register และ the prescaler register สามารถถูกเขียนหรืออ่านโดย software. นี่เป็นจริงแม้ว่า the counter กำลังทำงานอยู่.

The time-base unit ประกอบด้วย :
•   Counter register (TIMx_CNT)
•   Prescaler register (TIMx_PSC)
•   Auto-reload register (TIMx_ARR)
•   Repetition counter register (TIMx_RCR)


tha

The auto-reload register ถูกโหลดไว้ล่วงหน้า. การเขียนไปยังหรือการอ่านจาก the auto-reload register จะเข้าถึง the preload register. The content ของ the preload register ถูกส่งถ่ายลงใน the shadow register อย่างถาวรหรือที่แต่ละ update event (UEV), ขึ้นอยู่กับ the auto-reload preload enable bit (ARPE) ใน TIMx_CR1 register. The update event ถูกส่งเมื่อ the counter ถึง the overflow (หรือ underflow เมื่อนับลง) และถ้า the UDIS bit เท่ากับ 0 ใน the TIMx_CR1 register. มันสามารถถูกสร้างโดย software. การสร้างขึ้นของ the update event ถูกอธิบายโดยรายละเอียดสำหรับแต่ละ configuration.

The counter ถูก clocked โดย the prescaler output CK_CNT, ซึ่งถูกเปิดการใช้งานได้เพียงเมื่อ the counter enable bit (CEN) ใน TIMx_CR1 register ถูกเซ็ต (อ้างอิงถึง the slave mode controller description ด้วยเพื่อให้ได้รายละเอียดที่มากขึ้นบน counter enabling).

บันทึกไว้ว่า the counter เริ่มการนับ 1 clock cycle หลังจากการเซ็ต the CEN bit ใน the TIMx_CR1

tha

Prescaler description

The prescaler สามารถหาร the counter clock frequency โดยแฟคเตอร์ใดแฟคเตอร์หนึ่งระหว่าง 1 และ 65536. มันถูกตั้งอยู่บน a 16-bit counter ที่ควบคุมผ่านทาง  a 16-bit register (ใน the TIMx_PSC register). มันสามารถถูกเปลี่ยนได้กลางทางเนื่องจาก control register นี้ถูกบัฟเฟอร์. The new prescaler ratio ถูกนำมาพิจารณาที่ the next update event.

Figure 150 and Figure 151 แสดงบางตัวอย่างของ the counter behavior เมื่อ the prescaler ratio ถูกเปลี่ยนแปลงกลางทาง :




tha

22.3.2 Counter modes

Upcounting mode

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

ถ้า the repetition counter ถูกใช้, the update event (UEV) จะถูกสร้างหลังจากการนับขึ้นถูกซ้ำเป็นจำนวนครั้งที่โปรแกรมใน the repetition counter register บวกหนึ่ง (TIMx_RCR+1). ถ้าเป็นอย่างอื่น the update event จะถูกสร้างที่แต่ละ counter overflow.

การเซ็ต the UG bit ใน the TIMx_EGR register (โดย software หรือโดยการใช้ the slave mode controller) จะสร้าง an update event อีกด้วย

The UEV event สามารถถูกปิดการใช้งานโดย software โดยการเซ็ต the UDIS bit ใน TIMx_CR1 register. นี้เพื่อหลีกเลี่ยงการอัปเดต the shadow registers ในขณะที่เขียนค่าใหม่ใน the preload registers. ดังน้้นไม่มี update event เกิดขึนจนกว่า the UDIS bit ถูกเขียนเป็น 0. อย่างไรก็ตาม, the counter จะเริ่มต้นใหม่จาก 0, เช่นเดียวกันกับ the counter ของ the prescaler (แต่ the prescale rate ไม่ได้เปลี่ยน). นอกจากนี้, หาก 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.

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

รูปดังต่อไปนี้แสดงบางตัวอย่างของ the counter behavior สำหรับ clock frequencies ต่างๆเมื่อ TIMx_ARR=0x36.







tha

Downcounting mode

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

ถ้า the repetition counter ถูกใช้, the update event (UEV) ถูกสร้างหลังจากการนับลงถูกซ้ำเป็นจำนวนครั้งที่โปรแกรมใน the repetition counter register บวกหนึ่ง (TIMx_RCR+1). ถ้าเป็นอย่างอื่น the update event ถูกสร้างที่แต่ละ counter underflow.

การเซ็ต the UG bit ใน the TIMx_EGR register (โดย software หรือโดยการใช้ the slave mode controller). จะสร้าง an update event ได้อีกด้วย

tha

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 counter ของ the prescaler เริ่มใหม่จาก 0 (แต่ the prescale rate ไม่ได้เปลี่ยน).

นอกจากนี้, หาก 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.

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

รูปดังต่อไปนี้แสดงบางตัวอย่างของ the counter behavior สำหรับ clock frequencies ต่างๆเมื่อ TIMx_ARR=0x36.