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.