STM32 Timers #9. One Pulse Mode

Started by tha, March 04, 2023, 09:26:52 AM

Previous topic - Next topic

tha

https://controllerstech.com/stm32-timers-9-one-pulse-mode/

ขอแปลหน่อยนะครับ ขอขอบคุณเขามา ณ ที่นี้ด้วย ท่านใดพอจะมีทรัพย์ก็ Donate เขาด้วยนะ ฟังภาษาอังกฤษเขาในยูทูบก็ฟังง่ายดี(เปิดคำบรรยายด้วย)ครับ

                                                        STM32 Timers #9. One Pulse Mode

นี้เป็น the 9th tutorial ใน the STM32 Timer series และวันนี้เราจะเห็น timer feature อื่น, ตัวอย่างเช่น the one pulse mode.

One-pulse mode ถูกใช้เพื่อสร้าง a pulse ของ a programmable length เพื่อตอบสนองต่อ an external event. The pulse สามารถสตาร์ททันทีที่ the input trigger มาถึงหรือหลังจาก a programmable delay. เราสามารถควบคุมการสตาร์ทของ the pulse ได้เช่นเดียวกับ the pulse width.

The waveform สามารถถูกโปรแกรมเพื่อให้มี a single pulse ที่สร้างโดย the trigger, หรือเพื่อให้มี a continuous pulse train ที่สตาร์ทโดย  a single trigger.

One-pulse mode ยังเสนอตัวเลือกที่สามารถทริกซ้ำได้ ในกรณีนี้ ทริกใหม่ที่มาถึงก่อนจุดสิ้นสุดของ the pulse จะทำให้ the counter ถูกรีเซ็ตและความกว้างของพัลส์จะถูกขยายตามไปด้วย.


tha

                                                                                  CubeMX Setup

Clock configuration



ฉันได้กำหนดค่า the 8 MHz external crystal เพื่อจัดให้มี the clock. The system จะรันที่ 90MHz และโปรดทราบว่าทั้งสอง the APB timer clocks จะรันที่ 90MHz เช่นกัน. สิ่งนี้จะทำให้เรากำหนดค่า the timer ได้ง่ายขึ้น เนื่องจากเราไม่ต้องกังวลว่า timer ใดจะถูกต่อกับ APB bus ใด.

tha

Timer configuration

ฉันจะใช้ timer 1 สำหรับ application นี้. The setup ถูกแสดงข้างล่าง.



1.  The timer ต้องถูกกำหนดค่าใน the slave mode ด้วย trigger mode.
     •  ฉันได้เลือก the trigger source เป็น TI2FP2, คือ the channel 2 of the timer. ที่นี่เราจะเชื่อมต่อ the signal pin.
     •  The channel 1 จะถูกใช้สำหรับ the output compare. ที่นี่เราจะได้รับ the output จาก the timer.
2.  ตรวจสอบให้แน่ใจว่าได้เลือก the one pulse mode.
3.  The prescalar ที่ 90 จะทำให้ the clock ลดลงเป็น 1MHz. นี่คืออัตราที่ the counter นับและแต่ละนับจะใช้เวลา 1us.
     •  ฉันได้เซ็ต the ARR เป็น 50000, ดังนั้น the maximum width ของ the pulse จะเป็น 50ms.
     •  โปรดทราบว่า the Repetition counter ถูกเซ็ตเป็น 0, ซึ่งหมายความว่าเราต้องการเพียง a single pulse. หากคุณตั้งค่านี้เป็น 10
         (11-1), จะมี 11 pulses สำหรับแต่ละ trigger.
4.  The Mode ใน output compare จะถูกเปลี่ยนแปลงในภายหลังใน the code.
     •  The pulse value (the CCR1 value) ถูกเซ็ตเป็น 10000. นี่หมายความว่า the pulse จะถูกหน่วงเวลา 10000 counts, คือ
         10ms หลังจาก the trigger.

การกำหนดค่าข้างต้นจะสร้าง a pulse of 40ms (ARR – CCR) ในแต่ละ trigger บน channel 2 ของ the timer 1.

เราใช้ 2 channels สำหรับ the timer 1, ข้างล่างคือ the pinout สำหรับสิ่งเดียวกัน.



ที่นี่ the pin PA9 (TIM1_CH2) จะถูกใช้เป็น the input pin, ที่ที่เราจะส่ง the external signal. และ the pin PA8 (TIM1_CH1) จะถูกใช้เป็น the output pin, ที่ที่ the one pulse จะถูกสร้าง. เราจะมอนิเตอร์สิ่งนี้บน the oscilloscope.


tha

                                                                                Additional Setting

Generating Multiple pulses

การกำหนดค่าข้างต้นจะสร้าง a single pulse ของการหน่วงเวลาและ pulse width ที่กำหนดไว้ล่วงหน้า. หากคุณต้องการสร้าง a pulse train บน a single trigger signal, คุณต้องเขียนค่าใน the Repetition counter. นี้ถูกแสดงไว้ด้านล่าง.



การกำหนดค่าส่วนที่เหลือยังคงเหมือนเดิม ฉันได้แก้ไข the Repetition counter value เป็น 5 (6-1) เท่านั้น การจัดเตรียมนี้จะสร้าง the 6 pulses ที่มีความกว้างเท่ากันเมื่อได้รับ a trigger signal บน the channel 2.