STM32F1 TIM1 & TIM8

Started by tha, November 21, 2020, 08:18:38 AM

Previous topic - Next topic

tha

14.3.10 PWM mode
Pulse width modulation mode ยอมให้การสร้าง a signal ด้วย a frequency ที่กำหนดโดยค่าของ the TIMx_ARR register และ a duty cycle ที่กำหนดโดยค่าของ the TIMx_CCRx register

The PWM mode สามารถถูกเลือกอย่างอิสระบนแต่ละ channel (one PWM ต่อ OCx output) โดยการเขียน 110 (PWM mode 1) หรือ '111 (PWM mode 2) ใน the OCxM bits ใน the TIMx_CCMRx register. ผู้ใช้ต้องเปิดการใช้งาน the corresponding preload register โดยการเซ็ต the OCxPE bit ใน the TIMx_CCMRx register, และในที่สุด the auto-reload preload register
โดยการเซ็ต the ARPE bit ใน the TIMx_CR1 register.

ดังที่ the preload registers ถูกส่งถ่ายไปยัง the shadow registers ได้เพียงเมื่อ an update event เกิดขึ้น, ก่อนการเริ่ม the counter, ผู้ใช้ต้องเริ่ม the registers ทั้งหมดโดยการเซ็ต the UG bit ใน the TIMx_EGR register.

OCx polarity เป็น software programmable โดยใช้ the CCxP bit ใน the TIMx_CCER register. มันสามารถถูกโปรแกรมเป็น active high หรือ active low. OCx output ถูกเปิดการใช้งานโดยการรวมของ the CCxE, CCxNE, MOE, OSSI และ OSSR bits (TIMx_CCER และ TIMx_BDTR registers). อ้างอิงถึง the TIMx_CCERx register description สำหรับรายละเอียดที่มากขึ้น.

ใน PWM mode (1 หรือ 2), TIMx_CNT และ TIMx_CCRx เปรียบเทียบกันเสมอเพื่อตัดสินไม่ว่าจะ TIMx_CCRx≤TIMx_CNT หรือ TIMx_CNT≤TIMx_CCRx (ขึ้นอยู่กับทิศทางของ the counter).

The timer สามารถสร้าง PWM ใน edge-aligned mode หรือ center-aligned mode ขึ้นอยู่กับ the CMS bits ใน the TIMx_CR1 register.

PWM edge-aligned mode

•    Upcounting configuration
      Upcounting จะ active เมื่อ the DIR bit ใน the TIMx_CR1 register เป็น low. อ้างอิงถึง Upcounting mode.

      ในตัวอย่างดังต่อไปนี้, เราพิจารณา PWM mode 1. The reference PWM signal OCxREF เป็น high ตราบเท่าที่ TIMx_CNT
      <TIMx_CCRx อย่างอื่นมันจะกลายเป็น low. ถ้า the compare value ใน TIMx_CCRx มากกว่า the auto-reload value (ใน
      TIMx_ARR) เมื่อนั้น OCxREF จะอยู่ที่ '1. ถ้า the compare value เป็น 0 เมื่อนั้น OCxREF จะอยู่ที่ '0. Figure 84 แสดงบาง
      edge-aligned PWM waveforms ในตัวอย่างที่ TIMx_ARR=8.



•    Downcounting configuration
      Downcounting ทำงานเมื่อ the DIR bit ใน the TIMx_CR1 register เป็น high. อ้างอิงถึง Downcounting mode.

      ใน PWM mode 1, the reference signal ocxref เป็น low ตราบเท่าที่ TIMx_CNT>TIMx_CCRx อย่างอื่นมันจะกลายเป็น
      high. ถ้า the compare value ใน TIMx_CCRx มากกว่า the auto-reload value ใน TIMx_ARR, เมื่อนั้น ocxref จะอยู่ที่ '1.
      0% PWM ไม่สามารถเป็นได้ในโหมดนี้.

PWM center-aligned mode
Center-aligned mode ทำงานเมื่อ the CMS bits ใน TIMx_CR1 register แตกต่างจาก '00 (ทุกการกำหนดที่เหลือมีผลอย่างเดียวกันบน the ocxref/OCx signals). The compare flag ถูกเซ็ตเมื่อ the counter นับขึ้น, เมื่อมันนับลงหรือทั้งเมื่อมันนับขึ้นและลงขึ้นอยู่กับ the CMS bits configuration. The direction bit (DIR) ใน the TIMx_CR1 register ถูกอัปเดตโดย hardware และต้องไม่ถูก
เปลี่ยนโดย software. อ้างอิงถึง Center-aligned mode (up/down counting).

Figure 85 แสดงบาง center-aligned PWM waveforms ในตัวอย่างที่:
•    TIMx_ARR=8,
•    PWM mode เป็น the PWM mode 1,
•    The flag ถูกเซ็ตเมื่อ the counter นับลง ตรงกันกับ the center-aligned mode 1 ที่เลือกสำหรับ CMS=01 ใน TIMx_CR1
      register.



คำแนะนำในการใช้ center-aligned mode:
•   เมื่อเริ่มต้นใน center-aligned mode, the current up-down configuration ถูกใช้. หมายความว่า the counter นับขึ้นหรือลง
     ขึ้นอยู่กับค่าที่เขียนใน the DIR bit ใน the TIMx_CR1 register. ยิ่งไปกว่านั้น, the DIR และ CMS bits ต้องไม่ถูกเปลี่ยนที่เวลา
     เดียวกันโดย the software
•   การเขียนำไปยัง the counter ขณะกำลังรันใน center-aligned mode ไม่ถูกแนะนำตามที่มันสามารถนำไปสู่ผลที่ไม่คาดคิด. โดย
     เฉพาะอย่างยิ่ง :
      – The direction ไม่ถูกอัปเดตถ้าผู้ใช้เขียนค่าใน the counter ที่มากกว่า the auto-reload value (TIMx_CNT>TIMx_ARR).
         ตัวอย่างเช่น, ถ้า the counter กำลังนับขึ้นอยู่, มันก็ยังคงนับขึ้น.
      – The direction ถูกอัปเดตถ้าผู้ใช้เขียน 0 หรือเขียน the TIMx_ARR value ใน the counter แต่ไม่มี Update Event UEV ถูก
         สร้าง
•    วิธีที่ปลอกภัยที่สุดในการใช้ center-aligned mode คือการสร้างการอัปเดตโดย software (โดยการเซ็ต the UG bit ใน the
      TIMx_EGR register) เพียงก่อนการเริ่มต้น the counter และไม่เขียน the counter ขณะที่มันกำลังรันอยู่.

ปล. ไปเร็วไปมั๊ย พอดีมันซ้ำๆกับ TIM2&5 อยู่ เลยก๊อบปี้เอา

tha

14.3.11 Complementary(ทำให้ครบ, ส่วนประกอบ, เต็มเติม) outputs and dead-time insertion
The advanced-control timers (TIM1 and TIM8) สามารถส่งออก two complementary signals และจัดการ the switching-off และ the switching-on ทันทีทันใดของ the outputs

time นี้รู้โดยทั่วไปว่า dead-time และมันต้องถูกปรับมันขึ้นอยู่กับ the devices ที่ต่อกับ the outputs และคุณลักษณะของมัน (intrinsic delays ของ level-shifters, delays เนื่องจาก power switches...)

ผู้ใช้สามารถเลือก the polarity ของ the outputs (main output OCx หรือ complementary OCxN) เป็นอิสระสำหรับแต่ละ output. นี้ถูกทำโดยการเขียนไปยัง the CCxP และ CCxNP bits ใน the TIMx_CCER register

The complementary signals OCx และ OCxN ถูกทำให้ทำงานโดยการรวมของหลาย control bits: the CCxE และ CCxNE bits ใน the TIMx_CCER register และ the MOE, OISx, OISxN, OSSI และ OSSR bits ใน the TIMx_BDTR และ TIMx_CR2 registers. อ้างอิงถึง Table 83 สำหรับรายละเอียดที่มากขึ้น. โดยเฉพาะอย่างยิ่ง, the dead-time ถูกทำให้ทำงานเมื่อสวิทช์ไปยัง the IDLE state (MOE ตกลงมา 0).

Dead-time insertion ถูกเปิดการใช้งานโดยการเซ็ตทั้ง CCxE และ CCxNE bits, และ the MOE bit ถ้า the break circuit มีอยู่. DTG[7:0] bits ของ the TIMx_BDTR register ถูกใช้เพื่อควบคุม the dead-time generation สำหรับ channels ทั้งหมด. จาก a reference waveform OCxREF, มันสร้าง 2 outputs OCx และ OCxN. ถ้า OCx และ OCxN เป็น active high:
•    The OCx output signal เป็นเหมือนอย่าง the reference signal ยกเว้นสำหรับ the rising edge, ซึ่งถูก delayed เกี่ยวข้องกับ
      the reference rising edge.
•    The OCxN output signal เป็นตรงกันข้ามของ the reference signal ยกเว้นสำหรับ the rising edge, ซึ่งถูก delayed เกี่ยวข้อง
      กับ the reference falling edge

ถ้า the delay ใหญ่กว่าความกว้างของ the active output (OCx or OCxN) ดังนั้น the corresponding pulse จะไม่ถูกสร้าง.

รูปต่อไปนี้แสดงความสัมพันธ์ระหว่าง the output signals ของ the dead-time generator และ the reference signal OCxREF. (เราสมมุติว่า CCxP=0, CCxNP=0, MOE=1, CCxE=1 และ CCxNE=1 ในตัวอย่างเหล่านี้)




The dead-time delay เป็นเหมือนกันสำหรับแต่ละของ the channels และโปรแกรมได้ด้วย the DTG bits ใน the TIMx_BDTR register. อ้างอิงถึง Section 14.4.18: TIM1 and TIM8 break and dead-time register (TIMx_BDTR) สำหรับการคำนวน delay

Re-directing OCxREF to OCx or OCxN
ใน output mode (forced, output compare or PWM), OCxREF สามารถถูกเปลี่ยนทิศทางไปยัง the OCx output หรือไปยัง OCxN output โดยการกำหนดค่า the CCxE และ CCxNE bits ใน the TIMx_CCER register.

นี้ยอมให้ผู้ใช้ส่ง a specific waveform (อย่างเช่น PWM หรือ static active level) บน one output ขณะที่ตัวเติมเต็ม (the complementary) ยังคงอยู่ที่ inactive level ของมัน. ความเป็นไปได้อื่นๆคือมีทั้งสอง outputs ที่ inactive level หรือทั้งสอง outputs ที่ active และเสริมด้วย dead-time.

Note: เมื่อมีเพียง OCxN ถูกเปิดการใช้งาน (CCxE=0, CCxNE=1), มันไม่ได้ถูกเติมเต็มและกลายเป็น active ทันทีที่ OCxREF
           เป็น high. ตัวอย่างเช่น, ถ้า CCxNP=0 ดังนั้น OCxN=OCxRef. ในทางกลับกัน, เมื่อทั้ง OCx และ OCxN ถูกเปิดการใช้งาน
           (CCxE=CCxNE=1) OCx กลายเป็น active เมื่อ OCxREF เป็น high ขณะที่ OCxN ถูกเติมเต็มและกลายเป็น active เมื่อ
           OCxREF เป็น low.

ปล. ท่านใดจะเอาไปขับโหลดอย่าง DC Motor ผ่านทางทรายซิสเตอร์ โดย OCx ขับ PNP แล้วอีกทาง OCxN ไปขับ NPN ก็ได้ หรือเอาไปทำ inverter ได้มั๊ย มี 3 channels พอดี ไปปรับความเร็วมอเตอร์สามเฟส ท่านใดทำได้มั่ง

tha

14.3.12 Using the break function
เมื่อใช้ the break function, the output enable signals และ inactive levels ถูกแก้ไขสอดคล้องกับ additional control bits (MOE, OSSI และ OSSR bits ใน the TIMx_BDTR register, OISx และ OISxN bits ใน the TIMx_CR2 register). ไม่ว่าในกรณีใด, the OCx และ OCxN outputs ไม่สามารถถูกเซ้ตทั้งคู่เป็น active level ที่ a given time. อ้างอิงถึง Table 83 สำหรับรายละเอียดที่มากขึ้น

The break source สามารถเป็นอย่างใดอย่างหนึ่ง the break input pin หรือ a clock failure event, ที่สร้างโดย the Clock Security System (CSS), จาก the Reset Clock Controller. สำหรับข้อมูลเพิ่มเติมบน the Clock Security System, อ้างอิงถึง Section 7.2.7: Clock security system (CSS).

เมื่อออกจาก reset, the break circuit ถูกปิดการใช้งานและ the MOE bit เป็น low. ผู้ใช้สามารถเปิดการใช้งาน the break function โดยการเซ็ต the BKE bit ใน the TIMx_BDTR register. The break input polarity สามารถถูกเลือกโดยการกำหนดค่า the BKP bit ใน the same register. BKE และ BKP สามารถถูกแก้ไขที่เวลาเดียวกัน. เมื่อ the BKE และ BKP bits ถูกเขียน, a delay ของ 1 APB clock cycle ถูกใช้ก่อนการเขียนจะเป็นผล. ด้วยเหตุนี้, มันมีความจำเป็นที่ต้องคอย 1 APB clock period เพื่อการอ่านกลับบิตอย่างถูกต้องหลังจาก the write operation

เพราะว่า MOE falling edge สามารถถูก asynchronous, a resynchronization circuit ถูกแทรกระหว่าง the actual signal (ทำงานบน the outputs) และ the synchronous control bit (เข้าถึงใน the TIMx_BDTR register). ส่งผลให้เกิดการ delays ระหว่าง the asynchronous และ the synchronous signals.  โดยเฉพาะอย่างยิ่ง, ถ้า MOE ถูกเขียนเป็น 1 ในขณะที่มันเป็น low, a delay
(dummy instruction) ต้องถูกใส่ก่อนการอ่านมันได้อย่างถูกต้อง. นี้ก็เพราะว่าผู้ใช้เขียน an asynchronous signal, แต่อ่าน a synchronous signal

เมื่อ a break เกิดขึ้น (ระดับที่เลือกบน the break input):
•    The MOE bit ถูกเคลียร์ไม่พร้อมกัน(asynchronously), ผลัก the outputs ลงใน inactive state, idle state หรือลงใน reset
      state (ที่เลือกโดย the OSSI bit).  คุณสมบัตินี้ทำงานได้แม้ว่า the MCU oscillator ถูก off.
•    แต่ละ output channel ถูกขับด้วย the level ที่โปรแกรมใน the OISx bit ใน the TIMx_CR2 register ทันทีที่ MOE=0. ถ้า
      OSSI=0 จากนั้น the timer จะปลดปล่อย the enable output ถ้าเป็นอย่างอื่น the enable output ยังคง high.
•    เมื่อ complementary outputs ถูกใช้:
      – The outputs ถูกใส่เป็นอันดับแรกใน reset state inactive state (ขึ้นอยู่กับ the polarity). นี้ถูกทำแบบ asynchronous ดัง
         นั้นมันทำงานได้แม้ว่าไม่มี clock ถูกจัดให้มีถึง the timer.
      – ถ้า the timer clock ยังคงมีอยู่, ดังนั้น the dead-time generator ถูกทำให้ทำงานใหม่เพื่อขับ the outputs ด้วย the level ที่
         ถูกโปรแกรมใน the OISx และ OISxN bits หลังจาก a dead-time. แม้ในกรณีนี้ , OCx และ OCxN ไม่สามารถถูกขับถึง active
         level ของมันร่วมกัน. โปรดสังเกตว่าเนื่องจาก the resynchronization บน MOE, the dead-time duration นานกว่าปกติเล็ก
         น้อย (ประมาณ 2 ck_tim clock cycles).
      – ถ้า OSSI=0 ดังนั้น the timer จะปลดปล่อย the enable outputs ถ้าเป็นอย่างอื่น the enable outputs ยังคงหรือกลายเป็น
         high ทันทีที่หนึ่งใน the CCxE หรือ CCxNE bits เป็น high.
•    The break status flag (BIF bit ใน the TIMx_SR register) ถูก set. An interrupt สามารถถูกสร้างถ้า the BIE bit ใน the
      TIMx_DIER register ถูก set. A DMA request สามารถถูกส่งถ้า the BDE bit ใน the TIMx_DIER register ถูก set.
.•    ถ้า the AOE bit ใน the TIMx_BDTR register ถูก set, the MOE bit ถูกเซ็ตโดยอัตโนมัติอีกครั้งที่ the next update event
      UEV. นี้สามารถถูกใช้เพื่อกระทำตามระเบียบข้อบังคับ, อย่างเช่น. ถ้าเป็นอย่างอื่น, MOE ยังคงเป็น low จนกระทั่งถูกเขียนเป็น '1' อีก
      ครั้ง. ในกรณีนี้, มันสามารถถูกใช้สำหรับความปลอดภัยและ the break input สามารถถูกต่อไปยังสัญญาณเตือนจาก power drivers,
      thermal sensors หรือ security components ใดๆ

Note: The break inputs กำลังทำงานบน level. ดังนั้น, the MOE ไม่สามารถถูกเซ้ตในขณะที่ the break input เป็น active
           (ไม่ว่าโดยอัตโนมัติหรือโดย software). ในระหว่างนี้, the status flag BIF ไม่สามารถถูกเเคลียร์.

The break สามารถถูกสร้างโดย the BRK input ซึ่งมี a programmable polarity และ an enable bit BKE ใน the TIMx_BDTR Register.

มีสองวิธีในการสร้าง a break:
•    โดยการใช้ the BRK input ซึ่งมี a programmable polarity และ an enable bit BKE ใน the TIMx_BDTR register
•    โดย software ผ่านทาง the BG bit ของ the TIMx_EGR register.

นอกจาก the break input และ the output management, a write protection ถูกนำมาใช้ภายใน the break circuit เพื่อป้องกัน the application. มันยอมให้การแช่แข็ง the configuration ของ several parameters (dead-time duration, OCx/OCxN polarities และ state เมื่อปิดการใช้งาน, OCxM configurations, break enable and polarity). ผู้ใช้สามารถเลือก จากสามระดับของ
protection ที่เลือกโดย the LOCK bits ใน the TIMx_BDTR register. อ้างอิงถึง Section 14.4.18: TIM1 and TIM8 break and dead-time register (TIMx_BDTR). The LOCK bits สามารถถูกเขียนเพียงครั้งเดียวหลังจาก an MCU reset.

Figure 89 แสดงตัวอย่างของ behavior ของ the outputs ในการตอบสนองต่อ a break.



tha

14.3.13 Clearing the OCxREF signal on an external event
The OCxREF signal สำหรับ a given channel สามารถถูกขับ Low โดยการใช้ a High level ไปยัง the ETRF input (OCxCE enable bit ของ the corresponding TIMx_CCMRx register เซ็ตเป็น '1'). The OCxREF signal ยังคง Low จนกระทั่ง the next update event, UEV, เกิดขึ้น.

function นี้สามารถถูกใช้เพียงใน output compare และ PWM modes, และไม่ทำงานใน forced mode.

ตัวอย่างเช่น, the ETR signal สามารถถูกต่อถึง the output ของ a comparator ที่ถูกใช้สำหรับการจัดการปัจจุบัน(current handling). ในกรณีนี้, ETR ต้องถูกกำหนดค่าดังต่อไปนี้ :
1.    The external trigger prescaler ควรถูกปิด: bits ETPS[1:0] ใน the TIMx_SMCR register ถูกเคลียร์เป็น 00.
2.    The external clock mode 2 ต้องถูกปิดการใช้งาน: bit ECE ใน the TIM1_SMCR register ถูกเคลียร์เป็น 0.
3.    The external trigger polarity (ETP) และ the external trigger filter (ETF) สามารถถูกกำหนดให้สอดคล้องกับ the
       application's needs.

Figure 90 แสดง the behavior ของ the OCxREF signal เมื่อ the ETRF input กลายเป็น high, สำหรับทั้งสองค่าของ the OCxCE enable bit. ในตัวอย่างนี้, the timer TIMx ถูกโปรแกรมใน PWM mode



tha

14.3.14 6-step PWM generation
เมื่อ complementary outputs ถูกใช้บน a channel, preload bits มีให้ใช้บน the OCxM, CCxE and CCxNE bits. The preload bits ถูกส่งถ่ายไปยัง the shadow bits ที่ the COM commutation event. ผู้ใช้สามารถดังนั้นโปรแกรมล่วงหน้า the configuration สำหรับ the next step และเปลี่ยน the configuration ของ the channels ทั้งหมดในเวลาเดียวกัน. COM สามารถถูกสร้างโดย
software โดยการเซ็ต the COM bit ใน the TIMx_EGR register หรือโดย hardware (บน TRGI rising edge).

A flag ถูกเซ็ตเมื่อ the COM event เกิดขึ้น (COMIF bit ใน the TIMx_SR register), ซึ่งสามารถสร้าง an interrupt (ถ้า the COMIE bit ถูกเซ็ตใน the TIMx_DIER register) หรือ a DMA request (ถ้า the COMDE bit ถูกเซ็ตใน the TIMx_DIER register).

Figure 91 อธิบาย the behavior ของ the OCx และ OCxN outputs เมื่อ a COM event เกิดขึ้น, ใน 3 ตัวอย่างที่ต่างกันของ programmed configurations


tha

14.3.15 One-pulse mode
One-pulse mode (OPM) เป็นกรณีเฉพาะของโหมดก่อนหน้านี้. มันยอมให้ the counter ถูกเริ่มต้นเพื่อตอบสนองต่อสิ่งกระตุ้นและเพื่อสร้าง a pulse ด้วย a programmable length หลังจาก a programmable delay.

การเริ่มต้น the counter สามารถถูกควบคุมผ่านทาง the slave mode controller. การสร้าง the waveform สามารถถูกกระทำใน output compare mode หรือ PWM mode. เลือก One-pulse mode โดยการเซ็ต the OPM bit ใน the TIMx_CR1 register. นี้ทำให้ the counter หยุดโดยอัตโนมัติที่ the next update event UEV.

A pulse สามารถถูกสร้างอย่างถูกต้องเพียงถ้า the compare value แตกต่างจาก the counter initial value. ก่อนการเริ่มต้น (เมือ่ the timer กำลังรอสำหรับ the trigger), the configuration ต้องถูก:
•    ใน upcounting: CNT<CCRx ≤ ARR (โดยเฉพาะ, 0<CCRx),
•    ใน downcounting: CNT>CCRx.



ตัวอย่างเช่นผู้ใช้ต้องการสร้าง a positive pulse บน OC1 ด้วยความยาวเป็น tPULSE และหลังจาก a delay ของ tDELAY ทันใดนั้น a positive edge ถูกตรวจพบบน the TI2 input pin

มาใช้ TI2FP2 เป็น trigger 1:
•    แมป TI2FP2 เข้ากับ TI2 โดยการเขียน CC2S=01 ใน the TIMx_CCMR1 register.
•    TI2FP2 ต้องตรวจจับ a rising edge, เขียน CC2P=0 ใน the TIMx_CCER register.
•    กำหนด TI2FP2 เป็น trigger สำหรับ the slave mode controller (TRGI) โดยการเขียน TS=110 ใน the TIMx_SMCR
      register.
•    TI2FP2 ถูกใช้เพื่อเริ่มต้น the counter โดยการเขียน SMS เป็น '110 ใน the TIMx_SMCR register (trigger mode).

The OPM waveform ถูกกำหนดโดยการเขียน the compare registers (โดยคำนึงถึง the clock frequency และ the counter prescaler).
•    The tDELAY ถูกกำหนดโดยค่าที่เขียนใน the TIMx_CCR1 register
•    The tPULSE ถูกกำหนดโดยความแตกต่างระหว่าง the auto-reload value และ the compare value (TIMx_ARR -
      TIMx_CCR + 1).
•    ให้เราบอกผู้ใช้ที่ต้องการสร้าง a waveform ด้วยการเปลี่ยนจาก '0 ไปเป็น '1 เมื่อ a compare match เกิดขึ้นและการเปลี่ยนจาก '1
      ไปเป็น '0 เมื่อ the counter ถึง the auto-reload value. ในการดำเนินการนี้ให้เปิดการใช้งาน PWM mode 2 โดยการเขียน
      OC1M=111 ใน the TIMx_CCMR1 register. ผู้ใช้สามารถมีทางเลือกที่จะเปิดการใช้งาน the preload registers โดยการเขียน
      OC1PE=1 ใน the TIMx_CCMR1 register และ ARPE ใน the TIMx_CR1 register. ในกรณีนี้เขียน the compare value ใน
      the TIMx_CCR1 register, the auto-reload value ใน the TIMx_ARR register, สร้าง an update โดยการเซ็ต the UG
      bit และคอยสำหรับ external trigger event บน TI2. CC1P ถูกเขียนเป็น '0 ในตัวอย่างนี้.

ในตัวอย่างของเรา, the DIR และ CMS bits ใน the TIMx_CR1 register ควรเป็น low.

ผู้ใช้ต้องการเพียง one pulse (Single mode), ดังนั้นให้เขียน '1 ใน the OPM bit ใน the TIMx_CR1 register เพื่อหยุด the counter ที่ the next update event (เมื่อ the counter ม้วนวนจาก the auto-reload value กลับไปยัง 0). เมื่อ OPM bit ใน the TIMx_CR1 register ถูกเซ็ตเป็น '0', ดังนั้น the Repetitive Mode ถูกเลือก.

Particular case: OCx fast enable:
ใน One-pulse mode, the edge detection บน TIx input เซ็ต the CEN bit ซึ่งเปิดการใช้งาน the counter. จากนั้น the comparison ระหว่าง the counter และ the compare value ทำให้ the output toggle. แต่ several clock cycles ถูกต้องการสำหรับการทำงานเหล่านี้และมันจำกัด the minimum delay tDELAY เป็นนาทีที่เราสามารถจะได้.

เพื่อส่งออก a waveform ที่มี the minimum delay, ผู้ใช้สามารถเซ็ต the OCxFE bit ใน the TIMx_CCMRx register. จากนั้น OCxRef (และ OCx) ถูกบังคับให้ตอบสนองต่อสิ่งกระตุ้นโดยไม่คำนึงถึง the comparison. new level ของมันเป็นเหมือนกับ a compare match ที่เกิดขึ้นแล้ว. OCxFE ทำงานก็ต่อเมื่อ the channel ถูกกำหนดใน PWM1 หรือ PWM2 mode.

tha

14.3.16 Encoder interface mode
เพื่อเลือก Encoder Interface mode เขียน SMS='001 ใน the TIMx_SMCR register ถ้า the counter กำลังนับบน TI2 edges เพียงอย่างเดียว, SMS=010 ถ้ามันกำลังนับบน TI1 edges เพียงอย่างเดียวและ SMS=011 ถ้ามันกำลังนับบนทั้ง TI1 and TI2 edges.

เลือก the TI1 และ TI2 polarity โดยการโปรแกรม the CC1P และ CC2P bits ใน the TIMx_CCER register. เมื่อจำเป็น, ก็โปรแกรม the input filter ด้วย.

The two inputs TI1 และ TI2 ถูกใช้เพื่อ interface กับ an incremental encoder. อ้างอิงถึง Table 81. The counter ถูก clocked โดยแต่ละ valid transition บน TI1FP1 หรือ TI2FP2 (TI1 และ TI2 หลังจาก input filter และ polarity selection, TI1FP1=TI1 ถ้าไม่ filtered และไม่ inverted, TI2FP2=TI2 ถ้าไม่ filtered และไม่ inverted) ทึกทักเอาว่ามันถูกเปิดการใช้งาน (CEN bit ใน TIMx_CR1 register ถูกเขียนเป็น '1). The sequence ของ transitions ของ the two inputs ถูกตีค่าและสร้าง count pulses เช่นเดียวกันกับ the direction signal. ขึ้นอยู่กับ the sequence the counter นับขึ้นหรือลง, the DIR bit ใน the TIMx_CR1 register ถูกแก้ไขโดย hardware สอดคล้องกัน. The DIR bit ถูกคำนวณที่แต่ละ transition บน input ใดๆ (TI1 หรือ TI2), อะไรก็ได้ the counter นับบน TI1 เท่านั้น, TI2 เท่านั้นหรือทั้งคู่ TI1 และ TI2.

Encoder interface mode ทำงานอย่างง่ายๆคล้าย an external clock ที่มี direction selection. นี้หมายความว่า the counter เพียงนับต่อเนื่องไประหว่าง 0 และ the auto-reload value ใน the TIMx_ARR register (0 ไปยัง ARR หรือ ARR ลงไป 0 ขึ้นอยู่กับ the direction). ดังนั้นผู้ใช้ต้องกำหนด TIMx_ARR ก่อนการสตาร์ท. ในทำนองเดียวกัน, the capture, compare, prescaler, trigger output features ยังคงทำงานได้ตามปกติ. Encoder mode และ External clock mode 2 เข้ากันไม่ได้และต้องไม่ถูกเลือกเข้าด้วยกัน.

ในโหมดนี้, the counter ถูกปรับเปลี่ยนโดยอัตโนมัติตาม the speed และ the direction ของ the incremental encoder และสิ่งที่อยู่ภายในของมัน, ดังนั้น,จึงแสดง the encoder's position เสมอ. The count direction ตรงกันกับ the rotation direction ของ the connected sensor.

Table 81 สรุป the possible combinations, ทึกทักเอาว่า TI1 และ TI2 ไม่สวิทช์ในเวลาเดียวกัน.



An external incremental encoder สามารถถูกต่อโดยตรงเข้ากับ the MCU โดยปราศจาก external interface logic. อย่างไรก็ตาม, comparators โดยปกติถูกใช้แปลง the encoder's differential outputs ไปเป็น digital signals. สิ่งนี้เพิ่ม noise immunity อย่างมาก. The third encoder output ซึ่งแสดง the mechanical zero position, อาจถูกต่อถึง an external interrupt input และทริกเกอร์ a counter reset.

Figure 93 แสดงตัวอย่างของ counter operation, แสดง count signal generation และ direction control. มันยังแสดงวิธีที่ input jitter ถูกชดเชยในที่ๆทั้งสอง edges ถูกเลือก. สิ่งนี้อาจเกิดขึ้นหาก the sensor อยู่ในตำแหน่งใกล้กับ the switching points จุดใดจุดหนึ่ง. สำหรับตัวอย่างนี้เราถือว่าการกำหนดค่ามีดังต่อไปนี้:
•    CC1S= '01' (TIMx_CCMR1 register, TI1FP1 mapped on TI1)
•    CC2S= '01' (TIMx_CCMR2 register, TI2FP2 mapped on TI2)
•    CC1P= '0', CC1NP = '0', IC1F ='0000' (TIMx_CCER register, TI1FP1 noninverted, TI1FP1=TI1)
•    CC2P= '0', CC2NP = '0', IC2F ='0000' (TIMx_CCER register, TI2FP2 noninverted, TI2FP2=TI2)
•    SMS= '011' (TIMx_SMCR register, ทั้งสอง inputs ทำงานบนทั้ง rising และ falling edges)
•    CEN = 1 (TIMx_CR1 register, Counter ถูกเปิดการใช้งาน)



Figure 94 แสดงตัวอย่างของ counter behavior เมื่อ TI1FP1 polarity ถูกกลับ (การกำหนดเหมือนอย่างข้างบน ยกเว้น CC1P=1).



The timer, เมื่อกำหนดค่าใน Encoder Interface mode จัดให้มี information บน the sensor's current position. ผู้ใช้สามารถได้รับ dynamic information (speed, acceleration, deceleration) โดยการวัด the period ระหว่าง two encoder events โดยใช้ a second timer กำหนดค่าใน capture mode. The output ของ the encoder ซึ่งแสดง the mechanical zero สามารถถูกใช้สำหรับจุดมุ่งหมายนี้. ขึ้นอยู่กับ the time ระหว่าง two events, the counter สามารถถูกอ่านที่ regular times ได้อีกด้วย. ผู้ใช้สามารถทำการนี้โดยล็อค(latching) the counter value ลงใน a third input capture register ถ้ามีให้ใช้ (จากนั้น the capture signal ต้องถูกทำเป็นระยะๆและสามารถถูกสร้างโดย timer อื่น). เมื่อมีให้ใช้, มันเป็นไปได้ที่จะอ่านค่าของมันได้อีกด้วยผ่านทาง a DMA request ที่สร้างโดย a Real-Time clock.

tha

14.3.17 Timer input XOR function
The TI1S bit ใน the TIM1_CR2 register, ยอมให้ the input filter ของ channel 1 ถูกต่อถึง the output ของ a XOR gate, รวม the three input pins TIMx_CH1, TIMx_CH2 และ TIMx_CH3.

The XOR output สามารถถูกใช้กับทุก the timer input functions อย่างเช่น trigger หรือ input capture.

The XOR output สามารถถูกใช้กับทุก the timer input functions อย่างเช่น trigger หรือ input capture. ตัวอย่างของคุณลักษณะนี้ใช้เพื่ออินเตอร์เฟส Hall sensors ถูกให้ไว้ใน Section 14.3.18.