STM32F1 TIM2 to TIM5

Started by tha, September 30, 2020, 12:19:23 PM

Previous topic - Next topic

tha



Bit 15:13 Reserved, must be kept at reset value.

Bit 12 CC4OF: Capture/Compare 4 overcapture flag
อ้างอิงถึง CC1OF description

Bit 11 CC3OF: Capture/Compare 3 overcapture flag
refer to CC1OF description

Bit 10 CC2OF: Capture/compare 2 overcapture flag
refer to CC1OF description

Bit 9 CC1OF: Capture/Compare 1 overcapture flag
flag นี้ถูกเซ็ตโดย hardware เพียงเมื่อ the corresponding channel ถูกกำหนดค่าใน input capture mode. มันถูกเคลียร์โดย software โดยการเขียนมันเป็น '0'.
     0: ไม่มี overcapture ถูกตรวจจับแล้ว.
     1: The counter value ถูก captured แล้วใน TIMx_CCR1 register ขณะที่ CC1IF flag ถูกเซ็ตอยู่

Bits 8:7 Reserved, must be kept at reset value.

Bit 6 TIF: Trigger interrupt flag
flag นี้ถูกเซ็ตโดย hardware บน trigger event (active edge ถูกตรวจจับได้บน TRGI input เมื่อ the slave mode controller ถูก enabled ในทุก modes แต่ gated mode, ทั้งสอง edges ในกรณีที่ gated mode ถูกเลือก). มันถูกเคลียร์โดย software.
     0: ไม่มี trigger event เกิดขึ้น.
     1: Trigger interrupt ค้างอยู่.

Bit 5 Reserved, must be kept at reset value.

Bit 4 CC4IF: Capture/Compare 4 interrupt flag
อ้างอิงถึง CC1IF description

Bit 3 CC3IF: Capture/Compare 3 interrupt flag
refer to CC1IF description

Bit 2 CC2IF: Capture/Compare 2 interrupt flag
refer to CC1IF description

Bit 1 CC1IF: Capture/compare 1 interrupt flag
ถ้า channel CC1 ถูกกำหนดค่าเป็น output:
flag นี้ถูกเซ็ตโดย hardware เมื่อ the counter เท่ากับ the compare value, ด้วยบางข้อยกเว้นใน center-aligned mode (อ้างอิงถึง the CMS bits ใน the TIMx_CR1 register description). มันถูกเคลียร์โดย software.
     0: No match.
     1: The content ของ the counter TIMx_CNT เท่ากันกับ the content ของ the TIMx_CCR1 register.
ถ้า channel CC1 ถูกกำหนดค่าเป็น input:
บิตนี้ถูกเซ็ตโดย hardware บน a capture. มันถูกเคลียร์โดย software หรือโดยการอ่าน the TIMx_CCR1 register.
     0: ไม่มี input capture เกิดขึ้น.
     1: The counter value ถูก captured แล้วใน TIMx_CCR1 register (An edge ถูกตรวจจับได้แล้วบน IC1 ซึ่งเท่ากันกับ the
         selected polarity).

Bit 0 UIF: Update interrupt flag
– บิตนี้ถูกเซ็ตโดย hardware บน an update event. มันถูกเคลียร์โดย software.
     0: ไม่มี update เกิดขึ้น.
     1: Update interrupt ค้างอยู่. บิตนี้ถูกเซ็ตโดย hardware เมื่อ the registers ถูก updated:
– ที่ overflow หรือ underflow และถ้า the UDIS=0 ใน the TIMx_CR1 register.
– เมื่อ CNT ถูกเริ่มต้นใหม่โดย software โดยใช้ the UG bit ใน TIMx_EGR register, ถ้า URS=0 และ UDIS=0 ใน the
   TIMx_CR1 register.
– เมื่อ CNT ถูกเริ่มต้นใหม่โดย a trigger event (อ้างอิงถึง the synchro control register description), ถ้า URS=0 และ UDIS=0
   ใน the TIMx_CR1 register.

tha



Bits 15:7 Reserved, must be kept at reset value.

Bit 6 TG: Trigger generation
บิตนี้ถูกเซ็ตโดย software เพื่อสร้าง an event, มันถูกเคลียร์โดยอัตโนมัติโดย hardware.
     0: No action
     1: The TIF flag ถูกเซ็ตใน TIMx_SR register. interrupt หรือ DMA transfer ที่เกี่ยวข้องสามารถเกิดขึ้นถ้าถูกเปิดการใช้งาน.

Bit 5 Reserved, must be kept at reset value.

Bit 4 CC4G: Capture/compare 4 generation
refer to CC1G description

Bit 3 CC3G: Capture/compare 3 generation
refer to CC1G description

Bit 2 CC2G: Capture/compare 2 generation
refer to CC1G description

Bit 1 CC1G: Capture/compare 1 generation
บิตนี้ถูกเซ็ตโดย software เพื่อสร้าง an event, มันถูกเคลียร์โดยอัตโนมัติโดย hardware.
     0: No action
     1: A capture/compare event ถูกสร้างบน channel 1:
ถ้า channel CC1 ถูกกำหนดค่าเป็น output:
CC1IF flag ถูก set, interrupt or DMA request ที่ตรงกันถูกส่งถ้าถูกเปิดการใช้งาน..
ถ้า channel CC1 ถูกกำหนดค่าเป็น input:
The current value ของ the counter ถูก captured ใน TIMx_CCR1 register. The CC1IF flag ถูก set, the corresponding interrupt or DMA request ถูกส่งถ้าถูกเปิดการใช้งาน. The CC1OF flag ถูกเซ็ตถ้า the CC1IF flag เป็น high อยู่แล้ว.

Bit 0 UG: Update generation
บิตนี้ถูกเซ็ตโดย software เพื่อสร้าง an event, มันถูกเคลียร์โดยอัตโนมัติโดย hardware.
     0: No action
     1: เริ่มต้นใหม่ the counter และสร้าง an update ของ the registers. บันทึกไว้ว่า the prescaler counter ถูกเคลียร์ด้วย
         (อย่างไรก็ตาม the prescaler ratio ไม่ได้รับผลกระทบ). The counter ถูกเคลียร์ถ้า the center-aligned mode ถูกเลือกหรือ
        ถ้า DIR=0 (upcounting), มิฉะนั้นจะเอา the auto-reload value (TIMx_ARR) ถ้า DIR=1 (downcounting).

tha

15.4.7 TIMx capture/compare mode register 1 (TIMx_CCMR1)
Address offset: 0x18
Reset value: 0x0000

The channels สามารถถูกใช้ใน input (capture mode) หรือใน output (compare mode). The direction ของ a channel ถูกกำหนดโดยการกำหนดค่า the corresponding CCxS bits. ทุกบิตอื่นๆของ register นี้มี a different function ใน input และใน output mode. สำหรับ a given bit, OCxx อธิบายหน้าที่ของมันเมื่อ the channel ถูกกำหนดค่าใน output, ICxx อธิบายหน้าที่ของมันเมื่อ the channel ถูกกำหนดค่าใน input. ระวังว่าบิตเดียวกันสามารถมีความหมายแตกต่างกันสำหรับr the input stage และสำหรับ the output stage.



Output compare mode

Bit 15 OC2CE: Output compare 2 clear enable

Bits 14:12 OC2M[2:0]: Output compare 2 mode

Bit 11 OC2PE: Output compare 2 preload enable

Bit 10 OC2FE: Output compare 2 fast enable

Bits 9:8 CC2S[1:0]: Capture/Compare 2 selection
bit-field นี้กำหนด the direction ของ the channel (input/output) เช่นเดียวกับ the used input.
     00: CC2 channel ถูกกำหนดเป็น output
     01: CC2 channel ถูกกำหนดเป็น input, IC2 ถูกแม็ปบน TI2
     10: CC2 channel ถูกกำหนดเป็น input, IC2 ถูกแม็ปบน TI1
     11: CC2 channel ถูกกำหนดเป็น input, IC2 ถูกแม็ปบน TRC. โหมดนี้กำลังทำงานเพียงถ้า an internal trigger input ถูกเลือก
           ผ่านทาง the TS bit (TIMx_SMCR register)
Note: CC2S bits เขียนได้เพียงเมื่อ the channel ถูก OFF (CC2E = 0 ใน TIMx_CCER).

Bit 7 OC1CE: Output compare 1 clear enable
OC1CE: Output Compare 1 Clear Enable
     0: OC1Ref ไม่ถูกได้รับผลกระทบ the ETRF input
     1: OC1Ref ถูกเคลียร์ทันทีที่ a High level ถูกตรวจจับได้บน ETRF input

Bits 6:4 OC1M: Output compare 1 mode
บิตเหล่านี้กำหนด the behavior ของ the output reference signal OC1REF จากที่ OC1 และ OC1N สืบสายมา. OC1REF จะ active high ขณะที่ OC1 และ OC1N active level ขึ้นอยู่กับ CC1P และ CC1NP bits.
     000: Frozen - The comparison ระหว่าง the output compare register TIMx_CCR1 และ the counter TIMx_CNT ไม่มี
             ผลบน the outputs.(โหมดนี้ถูกใช้สร้าง a timing base).
     001: เซ็ต channel 1 เป็น active level เมื่อเท่ากัน. OC1REF signal ถูกบังคับเป็น high เมื่อ the counter TIMx_CNT เท่ากัน
             กับ the capture/compare register 1 (TIMx_CCR1).
     010: เซ็ต channel 1 เป็น inactive level เมื่อเท่ากัน. OC1REF signal ถูกบังคับเป็น low เมื่อ the counter TIMx_CNT เท่ากัน
             กับ the capture/compare register 1 (TIMx_CCR1).
     011: Toggle - OC1REF สลับเมื่อ TIMx_CNT=TIMx_CCR1.
     100: Force inactive level - OC1REF ถูกบังคับเป็น low.
     101: Force active level - OC1REF ถูกบังคับเป็น high.
     110: PWM mode 1 - ในการนับขึ้น, channel 1 จะ active ตราบเท่าที่ TIMx_CNT<TIMx_CCR1 เป็นอย่างอื่นจะ inactive. ใน
             การนับลง, channel 1 จะ inactive (OC1REF='0) ตราบเท่าที่ TIMx_CNT>TIMx_CCR1 เป็นอย่างอื่นจะ active
             (OC1REF=1).
     111: PWM mode 2 - ในการนับขึ้น, channel 1 จะ inactive ตราบเท่าที่ TIMx_CNT<TIMx_CCR1 เป็นอย่างอื่นจะ active. ใน
             การนับลง, channel 1 จะ active  ตราบเท่าที่ TIMx_CNT>TIMx_CCR1 เป็นอย่างอื่นจะ inactive.       
Note: ใน PWM mode 1 หรือ 2, the OCREF level เปลี่ยนเพียงเมื่อ the result ของ the comparison เปลี่ยนหรือเมื่อ the
           output compare mode สวิทช์จาก "frozen" mode ไปยัง "PWM" mode.

Bit 3 OC1PE: Output compare 1 preload enable
     0: Preload register บน TIMx_CCR1 ถูกปิดการใช้งาน. TIMx_CCR1 สามารถถูกเขียนได้ตลอดเวลา, ค่าใหม่จะถูกนำเข้าโดยทันที.
     1: Preload register บน TIMx_CCR1 ถูกเปิดการใช้งาน. Read/Write operations เข้าถึง the preload register.
         TIMx_CCR1 preload value ถูกโหลดใน the active register ที่แต่ละ update event.
Note: 1: บิตเหล่านี้ไม่สามารถถูกแก้ไขตราบเท่าที่ LOCK level 3 ถูกโปรแกรมแล้ว (LOCK bits ใน TIMx_BDTR register)
         และ CC1S=00 (the channel ถูกกำหนดใน output).
         2: The PWM mode สามารถถูกใช้โดยไม่ต้องตรวจสอบความถูกต้อง the preload register เพียงใน onepulse mode (OPM
         bit เซ็ตใน TIMx_CR1 register). เป็นอย่างอื่น the behavior ไม่ถูกรับประกัน.

Bit 2 OC1FE: Output compare 1 fast enable
บิตนี้ถูกใช้เร่งผลของ an event บน the trigger ใน input บน the CC output.
     0: CC1 ทำงานตามปกติโดยขึ้นอยู่กับ counter และ CCR1 values แม้เมื่อ the trigger จะ ON. The minimum delay ที่ทำให้
         CC1 output ทำงานเมื่อ an edge เกิดขึ้นบน the trigger input คือ 5 clock cycles.
     1: An active edge บน the trigger input ทำงานเหมือน a compare match บน CC1 output. จากนั้น, OC ถูกเซ็ตถึง the
         compare level เป็นอิสระจาก the result ของ the comparison. Delay เพื่อสุ่ม the trigger input และเพื่อทำให้ CC1
         output ทำงานถูกลดลงเป็น 3 clock cycles. OCFE ทำงานเพียงถ้า the channel ถูกกำหนดค่าใน PWM1 หรือ PWM2 mode.

Bits 1:0 CC1S: Capture/Compare 1 selection
bit-field นี้กำหนด the direction ของ the channel (input/output) เช่นเดียวกันกับ the used input.
     00: CC1 channel ถูกกำหนดค่าเป็น output.
     01: CC1 channel ถูกกำหนดค่าเป็น input, IC1 ถูกแม็ปบน TI1.
     10: CC1 channel is configured as input, IC1 is mapped on TI2.
     11: CC1 channel is configured as input, IC1 is mapped on TRC. โหมดนี้กำลังทำงานเพียงถ้า an internal trigger input
           ถูกเลือกผ่านทาง the TS bit (TIMx_SMCR register)
Note: CC1S bits เขียนได้เพียงเมื่อ the channel ถูก OFF (CC1E = 0 in TIMx_CCER).


tha

Input capture mode

Bits 15:12 IC2F: Input capture 2 filter

Bits 11:10 IC2PSC[1:0]: Input capture 2 prescaler

Bits 9:8 CC2S: Capture/compare 2 selection
bit-field นี้กำหนด the direction ของ the channel (input/output) เช่นเดียวกันกับ the used input.
     00: CC2 channel ถูกกำหนดค่าเป็น output.
     01: CC2 channel ถูกกำหนดค่าเป็น input, IC2 ถูกแม็ปบน TI2.
     10: CC2 channel is configured as input, IC2 is mapped on TI1.
     11: CC2 channel is configured as input, IC2 is mapped on TRC. โหมดนี้กำลังทำงานเพียงถ้า an internal trigger input
            ถูกเลือกผ่านทาง the TS bit (TIMx_SMCR register)
Note: CC2S bits เขียนได้เพียงเมื่อ the channel ถูก OFF (CC2E = 0 in TIMx_CCER).

Bits 7:4 IC1F: Input capture 1 filter
bit-field นี้จะกำหนด the frequency ที่ใช้เพื่อสุ่ม TI1 input และความยาวของ digital filter ที่ใช้กับ TI1. The digital filter ถูกทำจาก an event counter ที่ซึ่ง N consecutive events ถูกต้องการเพื่อทำให้ถูกต้อง a transition บน the output:
     0000: No filter, การสุ่มถูกทำที่ fDTS
     0001: fSAMPLING=fCK_INT, N=2
     0010: fSAMPLING=fCK_INT, N=4
     0011: fSAMPLING=fCK_INT, N=8
     0100: fSAMPLING=fDTS/2, N=6
     0101: fSAMPLING=fDTS/2, N=8
     0110: fSAMPLING=fDTS/4, N=6
     0111: fSAMPLING=fDTS/4, N=8
     1000: fSAMPLING=fDTS/8, N=6
     1001: fSAMPLING=fDTS/8, N=8
     1010: fSAMPLING=fDTS/16, N=5
     1011: fSAMPLING=fDTS/16, N=6
     1100: fSAMPLING=fDTS/16, N=8
     1101: fSAMPLING=fDTS/32, N=5
     1110: fSAMPLING=fDTS/32, N=6
     1111: fSAMPLING=fDTS/32, N=8

Bits 3:2 IC1PSC: Input capture 1 prescaler
bit-field นี้กำหนด the ratio ของ the prescaler ทำงานบน CC1 input (IC1).
The prescaler ถูก reset ทันทีที่ CC1E=0 (TIMx_CCER register).
     00: no prescaler, capture ถูกทำแต่ละเวลาที่ an edge ถูกตรวจจับได้บน the capture input
     01: capture ถูกทำหนึ่งครั้งทุกๆ 2 events
     10: capture is done once every 4 events
     11: capture is done once every 8 events

Bits 1:0 CC1S: Capture/Compare 1 selection
bit-field นี้กำหนด the direction ของ the channel (input/output) เช่นเดียวกันกับ the used input.
     00: CC1 channel ถูกกำหนดค่าเป็น output
     01: CC1 channel ถูกกำหนดค่าเป็น input, IC1 ถูกแม็ปบน TI1
     10: CC1 channel is configured as input, IC1 is mapped on TI2
     11: CC1 channel is configured as input, IC1 is mapped on TRC. โหมดนี้กำลังทำงานเพียงถ้า an internal trigger input
           ถูกเลือกผ่านทาง the TS bit (TIMx_SMCR register)
Note: CC1S bits เขียนได้เพียงเมื่อ the channel ถูก OFF (CC1E = 0 in TIMx_CCER).

tha


tha



Bits 15:14 Reserved, must be kept at reset value.

Bit 13 CC4P: Capture/Compare 4 output polarity
refer to CC1P description

Bit 12 CC4E: Capture/Compare 4 output enable
refer to CC1E description

Bits 11:10 Reserved, must be kept at reset value.

Bit 9 CC3P: Capture/Compare 3 output polarity
refer to CC1P description

Bit 8 CC3E: Capture/Compare 3 output enable
refer to CC1E description

Bits 7:6 Reserved, must be kept at reset value.

Bit 5 CC2P: Capture/Compare 2 output polarity
refer to CC1P description

Bit 4 CC2E: Capture/Compare 2 output enable
refer to CC1E description

Bits 3:2 Reserved, must be kept at reset value.

Bit 1 CC1P: Capture/Compare 1 output polarity
CC1 channel configured as output:
     0: OC1 active high.
     1: OC1 active low.
CC1 channel configured as input:
บิตนี้เลือกว่า IC1 หรือ IC1 ถูกใช้สำหรับ trigger หรือ capture operations.
     0: non-inverted: capture ถูกทำบน a rising edge ของ IC1. เมื่อถูกใช้เป็น external trigger, IC1 ถูก non-inverted.
     1: inverted: capture ถูกทำบน a falling edge ของ IC1. เมื่อถูกใช้เป็น external trigger, IC1 ถูก inverted.

Bit 0 CC1E: Capture/Compare 1 output enable
CC1 channel configured as output:
     0: Off - OC1 ไม่ active.
     1: On - OC1 signal จะส่งออกบน the corresponding output pin.
CC1 channel configured as input:
บิตนี้พิจารณาว่าถ้า a capture ของ the counter value สามารถถูกทำได้จริงลงใน the input capture/compare register 1 (TIMx_CCR1) หรือไม่.
     0: Capture ถูกปิดการใช้งาน.
     1: Capture ถูกเปิดการใช้งาน.



Note: The state ของ the external IO pins ที่ต่อถึง the standard OCx channels ขึ้นอยู่กับ the OCx channel state และ the
         GPIO และ AFIO registers

tha


tha

15.4.11 TIMx prescaler (TIMx_PSC)
Address offset: 0x28
Reset value: 0x0000



Bits 15:0 PSC[15:0]: Prescaler value
The counter clock frequency CK_CNT เท่ากันกับ fCK_PSC / (PSC[15:0] + 1).
PSC บรรจุค่าที่ถูกโหลดใน the active prescaler register ที่แต่ละ update event (รวมถึงเมื่อ the counter ถูกเคลียร์ผ่านทาง UG bit ของ TIMx_EGR register หรือผ่านทาง trigger controller เมื่อกำหนดค่าใน "reset mode").