Skip to content

Latest commit

ย 

History

History
403 lines (302 loc) ยท 19 KB

WhereAreYou.md

File metadata and controls

403 lines (302 loc) ยท 19 KB
Error in user YAML: (<unknown>): could not find expected ':' while scanning a simple key at line 4 column 1
---
title: Where are you?
author: Gildong Hong ([email protected])  
date: 2018-01-30
[๊ธฐ์ˆ ํ•  ๋‚ด์šฉ๋“ค - ๊ธฐ์ˆ ํ•˜๊ณ  ๋‚˜๋ฉด ํ•ด๋‹น ํ•ญ๋ชฉ ์ง€์šฐ๊ธฐ]
* ํšŒ์ „์ฒด์˜ ์œ„์น˜ ์ธก์ • ๋ฐฉ๋ฒ•:
* Gpt12 Encoder config
* iLLD
EXAMPLE:
	MyIlldModule_TC23A - Gpt12
	InfineonRacer_TC23A - TestGtp12
---


์‹œ์ž‘ํ•˜๋Š” ์งˆ๋ฌธ

  • ๋ชจํ„ฐ์˜ ์†๋„๋ฅผ ์ธก์ •ํ•˜๋ ค๋ฉด ๋ฌด์Šจ ์„ผ์„œ๋ฅผ ์จ์•ผํ•˜์ง€? ์†๋„์„ผ์„œ๋ผ๋Š” ๊ฒƒ์ด ์žˆ๋‚˜? ๋‹น์—ฐํžˆ ์žˆ๊ฒ ์ง€! ์ž๋™์ฐจ์˜ ๊ณ„๊ธฐํŒ์— ์ฐจ์†๊ณผ ์—”์ง„ rpm์„ ๋ณด์—ฌ์ฃผ๋Š” ๋ถ€๋ถ„์ด ์žˆ์ž–์•„? ๊ทธ ์›๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํšŒ์ „ํ•˜๋Š” ๋ชจํ„ฐ์˜ ์†๋„๋„ ์•Œ์•„ ๋‚ผ ์ˆ˜ ์žˆ๊ณ , ๋‹ฌ๋ฆฌ๋Š” ์ฐจ๋Ÿ‰์˜ ์†๋„๋„ ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ์„๊ฑฐ์•ผ.

์›€์ง์ด๋Š” ๋ฌผ์ฒด์˜ ์†๋„๋ฅผ ์ธก์ •ํ•˜๋Š” ๊ฒƒ์€ ๊ทธ๋ ‡๊ฒŒ ์‰ฌ์šด ์ผ์€ ์•„๋‹™๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ๋Š” ์œ„์น˜์˜ ๋ณ€ํ™”๋ฅผ ์ธก์ •ํ•ด์„œ ๊ทธ ๊ฐ’์„ ๋ฏธ๋ถ„ํ•ด์„œ ์†๋„๋ฅผ ์•Œ์•„๋‚ด๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ„๋‹จํ•˜๊ฒŒ๋Š” ํšŒ์ „์ถ•์— ๋ฐ˜์‚ฌํ˜• ๊ด‘์„ผ์„œ๋‚˜ ํ™€์„ผ์„œ ๋“ฑ์„ ๋ถ™์—ฌ ํšŒ์ „๊ณผ ๋™๊ธฐํ™”๋œ ํŽ„์Šค ์‹ ํ˜ธ๋ฅผ ๋งŒ๋“ค์–ด ๋‚ด๊ณ , ๊ทธ ์‹ ํ˜ธ์˜ ์ฃผ๊ธฐ๋ฅผ ์ธก์ •ํ•ด์„œ ๊ฐ„์ ‘์ ์œผ๋กœ ํšŒ์ „ ์†๋„๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์—ฌ๊ธฐ์— ํ•œ๊ฑธ์Œ ๋” ๋‚˜์•„๊ฐ€ ํšŒ์ „์ฒด์˜ ์†๋„ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํšŒ์ „์ฒด์˜ ์œ„์น˜, ์ฆ‰ ๊ฐ๋„๋ฅผ ์•Œ์•„๋‚ด์•ผ ํ•  ๊ฒฝ์šฐ๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๋Œ€ํ‘œ์ ์œผ๋กœ ์ž๋™์ฐจ ์—”์ง„์˜ ํฌ๋žญํฌ ์ถ•, ๋˜๋Š” ๋™๊ธฐ์ „๋™๊ธฐ์˜ ํšŒ์ „์ถ•์˜ ์œ„์น˜๋ฅผ ์•Œ์•„์•ผ ์ œ์–ด๋ฅผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๋ชฉ์ ์œผ๋กœ ์ฆ๋ถ„ํ˜• ์—”์ฝ”๋”(incremental encoder)๋ผ๋Š” ๊ฒƒ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์œ„์˜ ์†๋„ ์ธก์ •๋ฐฉ๋ฒ•๊ณผ์˜ ์ฐจ์ด๋Š” ํ›จ์”ฌ ๋” ๋งŽ์€ ํŽ„์Šค ์‹ ํ˜ธ๋ฅผ ๋ฐœ์ƒํ•˜๋„๋ก ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ๋•Œ 1ํšŒ์ „๋‹น ๋ช‡๊ฐœ์˜ ํŽ„์Šค๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š”๊ฐ€(PPR: Pulse Per Revolution)๋กœ ์—”์ฝ”๋”์˜ ์‚ฌ์–‘์„ ๊ฒฐ์ •ํ•˜๋Š” ์ค‘์š”ํ•œ ์ •๋ณด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.


Objectives

  • General Purpose Timer ์ดํ•ด
  • Input Capture์™€ Pulse Accumulator๋ฅผ ์‚ฌ์šฉํ•œ ์†๋„ ์ธก์ • ๋ฐฉ๋ฒ• ์Šต๋“

References

  • TC23x TC22x Family User's Manual v1.1 - Chap 26 GPT12
  • iLLD_TC23A Help / Modules/ GPT12

[Example Code]

  • MyIlldModule_TC23A - GPT12

Example Description

  • Desired frequency ๋ฅผ ๊ฐ€์ง„ Pulse ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.
  • ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜ค๋Š” pulse๋ฅผ counting ํ•˜์—ฌ ์†๋„๋ฅผ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋‹ค.

Background ์ •๋ณด

  • ์†๋„ ์ธก์ • ๋ฐฉ๋ฒ•
    • Input capture: ์ž…๋ ฅ๋œ ์‹ ํ˜ธ์— edge๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ๋งˆ๋‹ค time stamp๋ฅผ ์ฐ๊ณ , ํ˜„์žฌ์™€ ์ง์ „ time stamp ๊ฐ„์˜ ์ฐจ์ด๋ฅผ ํ†ตํ•ด ์†๋„๋ฅผ ๊ณ„์ธกํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
    • Pulse accumulator: ์ผ์ •ํ•œ ์‹œ๊ฐ„๋™์•ˆ ์ž…๋ ฅ๋œ pulse ์ •๋ณด๋ฅผ countingํ•˜๊ณ , pulse ๊ฐฏ์ˆ˜๋ฅผ ํ†ตํ•ด ์†๋„๋ฅผ ๊ณ„์ธกํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
  • Encoder
    • ์†๋„ ๊ณ„์ธก์„ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ์„ผ์„œ๋กœ ํšŒ์ „์ถ•์— ์›ํŒ์„ ์„ค์น˜ํ•˜๊ณ  ์›ํŒ ๋‘˜๋ ˆ์— ์–‡์€ slip์„ ๋‚ด์–ด ๋น›์ด ํ†ต๊ณผํ•˜๊ฒŒ ๋งŒ๋“ค๊ณ , ์›ํŒ ์•ž๋’ค๋กœ ๋ฐœ๊ด‘/์ˆ˜๊ด‘ ์†Œ์ž๋ฅผ ์žฅ์ฐฉํ•ฉ๋‹ˆ๋‹ค. ์›ํŒ์ด ์„ค์น˜๋œ ์ถ•์ด ํšŒ์ „ํ•˜๊ฒŒ ๋˜๋ฉด slip์— ์˜ํ•ด ๋ฐœ๊ด‘์†Œ์ž์—์„œ ๋ฐœ์ƒ๋œ ๋น›์ด ์ˆœ๊ฐ„์ ์œผ๋กœ ์ˆ˜๊ด‘์†Œ์ž์— ๋„๋‹ฌํ•˜๊ฒŒ ๋˜๋Š” ๋ฐ, ์ด๋•Œ ๋ฐœ์ƒ๋˜๋Š” ์‹ ํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๊ฒƒ์ด Encoder์˜ ์›๋ฆฌ๊ฐ€ ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ถ•์ด ๋น ๋ฅด๊ฒŒ ํšŒ์ „ํ•˜๊ฒŒ ๋˜๋ฉด ์ˆ˜๊ด‘์†Œ์ž์— ๋น›์ด ๋„๋‹ฌํ•˜๋Š” ํšŸ์ˆ˜๊ฐ€ ์ฆ๊ฐ€ํ•˜๊ฒŒ ๋จ์œผ๋กœ, ์งง์€ ์‹œ๊ฐ„๋™์•ˆ ๋งŽ์€ ์ˆ˜์˜ pulse๊ฐ€ ๋‚˜์˜ค๊ฒŒ ๋˜๋ฉฐ, ๋ฐ˜๋Œ€๋กœ ์ €์†์œผ๋กœ ํšŒ์ „ํ•˜๋ฉด pulse ๋ฐœ์ƒ ์ฃผ๊ธฐ๊ฐ€ ๋Š๋ ค์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

AURIX - related

  • Overview

    • General Purpose Timer (GPT)๋Š” ์‹œ๊ฐ„ ์ธก์ •, ์ด๋ฒคํŠธ ์นด์šดํŒ…, ํŽ„์Šค ํญ ์ธก์ •, ํŽ„์Šค ์ƒ์„ฑ ๋“ฑ ๋‹ค์–‘ํ•ญ ๋ชฉ์ ์— ๋งž๊ฒŒ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด 5๊ฐœ์˜ 16 bits Timer๊ฐ€ ์กด์žฌํ•˜๋Š”๋ฐ ์ด Timer๋“ค์€ 2๊ฐœ์˜ Timer ๋ธ”๋Ÿญ์œผ๋กœ ๋‚˜๋‰˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค(GPT1, GPT2). ๊ฐ Timer๋Š” ๋‹ค์–‘ํ•œ ๋ชจ๋“œ ์ค‘ ํ•˜๋‚˜๋กœ ์„ค์ • ํ›„ ๋…๋ฆฝ์  ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ, ๊ฐ™์€ Timer ๋ธ”๋Ÿญ ๋‚ด์—์„œ๋Š” ํ•˜๋‚˜์˜ Timer๊ฐ€ ๋‹ค๋ฅธ Timer์™€ ํ•ฉ์ณ์ ธ์„œ ๊ตฌ๋™๋˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.
    • GPT1
      • GPT1 ๋ธ”๋Ÿญ์€ 3๊ฐœ์˜ Timer๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. Core timer์ธ T3์™€ ๋‘ ๊ฐœ์˜ auxiliary timer T2์™€ T4๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. Auxiliary timer๋“ค์€ ์„ค์ •์— ๋”ฐ๋ผ core timer๋ฅผ ์œ„ํ•œ reload๋‚˜ capture register๋กœ๋„ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
      • ์ตœ๋Œ€ ํ•ด์ƒ๋„๋Š” ์ด๊ณ , ์ด ๋•Œ ๋Š” GPT12 ๋ธ”๋Ÿญ์˜ clock์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.
      • 4๊ฐœ์˜ ๋ชจ๋“œ๋ฅผ ์ง€์›ํ•˜๋ฉฐ ๋ชจ๋“œ ์ข…๋ฅ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
        • Timer Mode
        • Gated Timer Mode
        • Counter Mode
        • Incremental Interface Mode
    • Capture/Reload ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
    • GPT2
      • GPT2 ๋ธ”๋Ÿญ์€ 2๊ฐœ์˜ Timer๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. Core timer์ธ T6์™€ auxiliary timer T5๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
      • ์ตœ๋Œ€ ํ•ด์ƒ๋„๋Š” ์ด์ž…๋‹ˆ๋‹ค.
      • 3๊ฐœ์˜ ๋ชจ๋“œ๋ฅผ ์ง€์›ํ•˜๋ฉฐ ๋ชจ๋“œ ์ข…๋ฅ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
        • Timer Mode
        • Gated Timer Mode
        • Counter Mode
        • Capture/Reload ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • GPT1

    • ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋“  Timer๋Š” count๋ฅผ up ๋˜๋Š” down ์‹œํ‚ต๋‹ˆ๋‹ค.
    • ๊ฐ Timer๋Š” ์ž…๋ ฅ ํ•€์„ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ Gated Timer Mode์—์„œ๋Š” gate control๋กœ, Counter Mode์—์„œ๋Š” count input์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
    • Timer๋ฅผ Up ์‹œํ‚ฌ ์ง€, Down์‹œํ‚ฌ ์ง€๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • Core Timer์˜ overflow๋‚˜ underflow ๋ฐœ์ƒ ์—ฌ๋ถ€๋Š” Output Toggle Latch T3OTL์„ ํ†ตํ•ด ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • GPT1๊ณผ ๊ด€๋ จ๋œ Interrupt๋Š” SR0, SR1, SR2๋ฅผ ํ†ตํ•ด ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.

    WhereAreYou_GPT1

    โ€‹

    • Modes

      • Timer Mode: ๋ฅผ Prescaler๋ฅผ ํ†ตํ•ด ์กฐ์ •ํ•œ ๋‹ค์Œ ์ถœ๋ ฅ clock์— ๋Œ€ํ•ด count๋ฅผ up ๋˜๋Š” down ํ•ฉ๋‹ˆ๋‹ค. T3R์€ ์Šค์œ„์น˜๋กœ์„œ count๋ฅผ ๋‚ด๋ณด๋‚ผ ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

      WhereAreYou_TimerMde

      • Gated Timer Mode: ๋™์ž‘ ๋ฐฉ์‹์€ Timer Mode์™€ ๋™์ผํ•˜๋‚˜, Prescaler ์ถœ๋ ฅ์— Gate Control์ด ์ถ”๊ฐ€๋œ ํ˜•ํƒœ ์ž…๋‹ˆ๋‹ค. Gate Control์€ ์™ธ๋ถ€ ์ž…๋ ฅ T3IN์„ ๋ฐ›์•„์„œ clock์„ ๋‚ด๋ณด๋‚ผ ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ, T3IN์€ ๋ฐ˜๋“œ์‹œ ์„ค์ •์„ ํ•ด ์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์š”์ปจ๋Œ€, T3IN๊ณผ T3R์ด Enable ๋  ๋•Œ๋งŒ count๊ฐ€ ๋ฐœ์ƒ๋ฉ๋‹ˆ๋‹ค.

      WhereAreYou_GatedTimerMode

      • Counter Mode: Timer Mode์—์„œ ์‚ฌ์šฉ๋˜์—ˆ๋˜ ๋ฅผ ์™ธ๋ถ€ ์ž…๋ ฅ (T3IN)์œผ๋กœ ๋ณ€๊ฒฝํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ทธ ์™ธ ๋‹ค๋ฅธ ๋™์ž‘์€ Timer Mode์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. T3IN์˜ rising๊ณผ falling edges ๋“ค ์ค‘ ์–ด๋–ค ๊ฒƒ์„ count๋ฅผ ํ•  ๊ฑด์ง€ ์„ค์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

      WhereAreYou_CounterMode

      • Incremental Interface Mode: T3IN๊ณผ T3EUD์˜ ์ž…๋ ฅ ์ˆœ์„œ ๋ฐ edge ๋ณ€์ด๋ฅผ ๋”ฐ๋ผ count๋ฅผ upํ•˜๊ฑฐ๋‚˜ down ์‹œํ‚ค๋Š” ๋ชจ๋“œ์ž…๋‹ˆ๋‹ค. ๋‘ ์ž…๋ ฅ์˜ ์ž…๋ ฅ ์ˆœ์„œ์— ๋”ฐ๋ผ ๋ฐฉํ–ฅ์„ ๊ฐ์ง€ํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ๊ณ , ๋‘ ์ž…๋ ฅ ๊ฐ„์˜ ์œ„์ƒ์ฐจ๋ฅผ ํ†ตํ•ด ๋‹จ์ผ ์ž…๋ ฅ ๋Œ€๋น„ 2๋ฐฐ ๋˜๋Š” 4๋ฐฐ ์ •๋„์˜ ํ•ด์ƒ๋„๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
        • Up ๋˜๋Š” down count๋ฅผ ์œ„ํ•œ ์กฐ๊ฑด์€ ๋‘ ์ž…๋ ฅ ์ค‘ ํ•˜๋‚˜์˜ ์ž…๋ ฅ์—์„œ edge๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ๋‹ค๋ฅธ ์ž…๋ ฅ์˜ level์„ ํ™•์ธํ•˜์—ฌ ๊ฒฐ์ •ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋•Œ, ๋ฐœ์ƒ๋œ edge์˜ ์ข…๋ฅ˜๋„ ๊ณ ๋ คํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ํ‘œ๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
        • ๊ทธ๋ฆฌ๊ณ  ๋ช‡ ๊ฐœ์˜ ์ž…๋ ฅ์˜ edge ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•  ๊ฑด์ง€์— ๋”ฐ๋ผ up / down์˜ ํšŸ์ˆ˜๋ฅผ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    WhereAreYou_IncrementalInterfaceMode

    โ€‹

    โ€‹ Up/Down Count ๋ฐœ์ƒ ์กฐ๊ฑด

    WhereAreYou_CountDirection

    โ€‹ 2๊ฐœ์˜ ์ž…๋ ฅ edge๋ฅผ ๋ชจ๋‘ count์— ๋ฐ˜์˜ํ•˜์˜€์„ ๊ฒฝ์šฐ

    WhereAreYou_2Inputs

    โ€‹

    โ€‹ 1๊ฐœ์˜ ์ž…๋ ฅ edge๋งŒ count์— ๋ฐ˜์˜ํ•˜์˜€์„ ๊ฒฝ์šฐ

    WhereAreYou_1Input

    • GPT2

      • ๊ธฐ๋ณธ์ ์ธ ๊ธฐ๋Šฅ์€ GPT1๊ณผ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
      • 2๊ฐœ์˜ Timer (T5, T6)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
      • ์ง€์›๋˜๋Š” ๋ชจ๋“œ๋Š” Timer Mode, Gated Timer Mode, Counter Mode์ด๋ฉฐ, ๋™์ž‘ ๋ฐฉ์‹์€ ์œ„์— ์„ค๋ช…ํ•œ ๊ฒƒ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
      • Core Timer๋Š” T6์ด๋ฉฐ, Auxiliary Timer๋Š” T5์ž…๋‹ˆ๋‹ค.

      โ€‹

iLLD - related

Module Configuration

void Gpt12Demo_init(void)
{
    //    printf("Gpt12_init() called. \n");

    initTime();

    /* Initialize global clocks */
    /* FIXME Global prescaller should not be set by the driver as they are global resources */
    IfxGpt12_enableModule(&MODULE_GPT120);
    // Gpt1 block clock ์„ค์ •
    IfxGpt12_setGpt1BlockPrescaler(&MODULE_GPT120, IfxGpt12_Gpt1BlockPrescaler_8);
    // Gpt2 block clock ์„ค์ •
    IfxGpt12_setGpt2BlockPrescaler(&MODULE_GPT120, IfxGpt12_Gpt2BlockPrescaler_4);

    // Encoder๋กœ ๋“ค์–ด์˜ค๋Š” pulse๋ฅผ ์„ธ๊ธฐ ์œ„ํ•œ Gpt configuration ์ƒ์„ฑ
    IfxGpt12_IncrEnc_Config config;
    // Gpt Configuration ์ดˆ๊ธฐํ™”
    IfxGpt12_IncrEnc_initConfig(&config, &MODULE_GPT120);
#if 1
    {
        /* Test implementation with T3 as core */
        config.base.offset                    = 0;
        config.base.reversed                  = FALSE;
        config.base.resolution                = 32; // 2048; for test purpose
        config.base.periodPerRotation         = 1;
        config.base.resolutionFactor          = IfxStdIf_Pos_ResolutionFactor_fourFold;
        config.base.updatePeriod              = 100e-6;
        config.base.speedModeThreshold        = 200;
        config.base.minSpeed                  = 10;
        config.base.maxSpeed                  = 500;
        config.zeroIsrPriority                = ISR_PRIORITY(INTERRUPT_INCRINC_ZERO);
        config.zeroIsrProvider                = ISR_PROVIDER(INTERRUPT_INCRINC_ZERO);
        config.pinA                           = &IfxGpt120_T3INA_P02_6_IN;
        config.pinB                           = &IfxGpt120_T3EUDA_P02_7_IN;
        config.pinZ                           = &IfxGpt120_T4INA_P02_8_IN;
        config.pinMode                        = IfxPort_InputMode_noPullDevice;

        config.base.speedFilterEnabled        = TRUE;
        config.base.speedFilerCutOffFrequency = config.base.maxSpeed / 2 * IFX_PI * 2;
    }
#else
    {
        /* Test implementation with T2 as core */
        config.base.offset                    = 100;
        config.base.reversed                  = FALSE;
        config.base.resolution                = 2048;
        config.base.periodPerRotation         = 1;
        config.base.resolutionFactor          = IfxStdIf_Pos_ResolutionFactor_fourFold;
        config.base.updatePeriod              = 100e-6;
        config.base.speedModeThreshold        = 200;
        config.base.minSpeed                  = 10;
        config.base.maxSpeed                  = 500;
        config.zeroIsrPriority                = ISR_PRIORITY(INTERRUPT_INCRINC_ZERO);
        config.zeroIsrProvider                = ISR_PROVIDER(INTERRUPT_INCRINC_ZERO);
        config.pinA                           = &IfxGpt120_T2INA_P00_7_IN;
        config.pinB                           = &IfxGpt120_T2EUDA_P00_8_IN;
        config.pinZ                           = &IfxGpt120_T4EUDA_P00_9_IN;
        config.pinMode                        = IfxPort_InputMode_noPullDevice;

        config.base.speedFilterEnabled        = TRUE;
        config.base.speedFilerCutOffFrequency = config.base.maxSpeed / 2 * IFX_PI * 10;
    }
#endif
    IFX_VALIDATE(IFX_VERBOSE_LEVEL_ERROR, IfxGpt12_IncrEnc_init(&g_Gpt12.incrEnc, &config));

    g_Gpt12.control.run                  = TRUE;
    g_Gpt12.control.direction            = IfxStdIf_Pos_Dir_forward;
    g_Gpt12.control.resolution           = config.base.resolution;
    g_Gpt12.control.step                 = 3;
    g_Gpt12.control.rawPosition          = config.base.offset;
    g_Gpt12.control.speed                = IFX_PI * 2.0;
    g_Gpt12.control.multiplicationFactor = config.base.resolutionFactor;
    g_Gpt12.control.updatePeriod         = config.base.updatePeriod;
    g_Gpt12.control.positionMask         = g_Gpt12.control.resolution * g_Gpt12.control.multiplicationFactor - 1;

    g_Gpt12.interface.A                  = config.pinA->pin;
    g_Gpt12.interface.B                  = config.pinB->pin;
    g_Gpt12.interface.Z                  = config.pinZ->pin;

    /* Overwrite port configuration to enable feature check */
    IfxPort_setPinModeOutput(g_Gpt12.interface.A.port, g_Gpt12.interface.A.pinIndex, IfxPort_OutputMode_pushPull,
        IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(g_Gpt12.interface.B.port, g_Gpt12.interface.B.pinIndex, IfxPort_OutputMode_pushPull,
        IfxPort_OutputIdx_general);
    IfxPort_setPinModeOutput(g_Gpt12.interface.Z.port, g_Gpt12.interface.Z.pinIndex, IfxPort_OutputMode_pushPull,
        IfxPort_OutputIdx_general);
}

Module Behavior

// ์—”์ฝ”๋” ์ธํ„ฐํŽ˜์ด์Šค ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•˜์—ฌ ์ธ์œ„์ ์œผ๋กœ pulse๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค
void Gpt12Demo_step(void)
{
    if (g_Gpt12.control.run)
    {
        sint32 rawPosition;
        rawPosition = g_Gpt12.control.rawPosition;

        if (g_Gpt12.control.direction == IfxStdIf_Pos_Dir_forward)
        {
            g_Gpt12.control.step++;
            g_Gpt12.control.step &= 0x3;
            rawPosition++;
        }
        else
        {
            g_Gpt12.control.step--;
            g_Gpt12.control.step &= 0x3;
            rawPosition--;
        }

        rawPosition                &= g_Gpt12.control.positionMask;
        g_Gpt12.control.rawPosition = rawPosition;

#if 1
		// Encoder ์ค‘์—์„œ๋„ Z์ƒ์ด ์žˆ๋Š” ๊ฒŒ ์žˆ๊ณ  ์—†๋Š” ๊ฒŒ ์žˆ์œผ๋ฏ€๋กœ ์„ ํƒ์ ์œผ๋กœ Z์ƒ์„ ๋งŒ๋“ ๋‹ค.
        if (g_Gpt12.control.direction == IfxStdIf_Pos_Dir_forward)
        {
            if (rawPosition == 0)
            {
                IfxPort_setPinHigh(g_Gpt12.interface.Z.port, g_Gpt12.interface.Z.pinIndex);
            }
            else if (rawPosition == 1)
            {
                IfxPort_setPinLow(g_Gpt12.interface.Z.port, g_Gpt12.interface.Z.pinIndex);
            }
        }
        else
        {
            if (rawPosition == g_Gpt12.control.positionMask)
            {
                IfxPort_setPinHigh(g_Gpt12.interface.Z.port, g_Gpt12.interface.Z.pinIndex);
            }
            else if (rawPosition == g_Gpt12.control.positionMask - 1)
            {
                IfxPort_setPinLow(g_Gpt12.interface.Z.port, g_Gpt12.interface.Z.pinIndex);
            }
        }

#endif
		// 4๋ถ„ํ• ๋กœ ์ชผ๊ฐœ์„œ A์ƒ B์ƒ์˜ Pulse๋ฅผ ๋งŒ๋“ค์–ด๋ƒ„
        switch (g_Gpt12.control.step)
        {
        case 0:
            IfxPort_setPinLow(g_Gpt12.interface.A.port, g_Gpt12.interface.A.pinIndex);
            IfxPort_setPinLow(g_Gpt12.interface.B.port, g_Gpt12.interface.B.pinIndex);
            break;
        case 1:
            IfxPort_setPinLow(g_Gpt12.interface.A.port, g_Gpt12.interface.A.pinIndex);
            IfxPort_setPinHigh(g_Gpt12.interface.B.port, g_Gpt12.interface.B.pinIndex);
            break;
        case 2:
            IfxPort_setPinHigh(g_Gpt12.interface.A.port, g_Gpt12.interface.A.pinIndex);
            IfxPort_setPinHigh(g_Gpt12.interface.B.port, g_Gpt12.interface.B.pinIndex);
            break;
        case 3:
            IfxPort_setPinHigh(g_Gpt12.interface.A.port, g_Gpt12.interface.A.pinIndex);
            IfxPort_setPinLow(g_Gpt12.interface.B.port, g_Gpt12.interface.B.pinIndex);
            break;
        }
    }
}


void Gpt12Demo_run(void)
{
    printf("Gpt12_run() called \n");
    Ifx_TickTime tickPeriod;
    Ifx_TickTime tickRefresh;

    Ifx_TickTime refreshDeadLine;
    Ifx_TickTime tickDeadLine;

    tickRefresh     = g_Gpt12.control.updatePeriod * TimeConst_1s;

    refreshDeadLine = now();
    tickDeadLine    = refreshDeadLine;

    while (1)
    {
        g_Gpt12.control.run = g_Gpt12.control.speed != 0.0;

        if (!g_Gpt12.control.run)
        {}
        else
        {
            float32 roundDuration_s = (2.0 * IFX_PI) / g_Gpt12.control.speed;
            float32 tickDuration_s  = roundDuration_s / (g_Gpt12.control.positionMask + 1);

            tickPeriod = tickDuration_s * TimeConst_1s;

            if (isDeadLine(tickDeadLine))
            {
                tickDeadLine = addTTime(tickDeadLine, tickPeriod);
                Gpt12Demo_step();
            }
        }

        if (isDeadLine(refreshDeadLine))
        {
            refreshDeadLine = addTTime(refreshDeadLine, tickRefresh);
            // Gpt12 ์‚ฌ์šฉํ•˜์—ฌ ์—”์ฝ”๋” ์‹ ํ˜ธ ์ธํ„ฐํŽ˜์ด์Šค ํ™•์ธ
            // Update ๋œ ์‹ ํ˜ธ๋Š” g_Gpt12.incrEnc์— ์ €์žฅ
            IfxGpt12_IncrEnc_update(&g_Gpt12.incrEnc);

            // update๋œ ์—”์ฝ”๋” ์‹ ํ˜ธ๋ฅผ ์ด์šฉํ•ด speed, position, direction ์ •๋ณด๋ฅผ ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜
            g_Gpt12.status.speed       = IfxGpt12_IncrEnc_getSpeed(&g_Gpt12.incrEnc);
            g_Gpt12.status.rawPosition = IfxGpt12_IncrEnc_getRawPosition(&g_Gpt12.incrEnc);
            g_Gpt12.status.direction   = IfxGpt12_IncrEnc_getDirection(&g_Gpt12.incrEnc);
        }
    }
}

์ถ”๊ฐ€์ ์ธ ์„ค๋ช…

์—”์ฝ”๋” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ…Œ์ŠคํŠธ ํ•˜๋ ค๋ฉด ์—”์ฝ”๋” ์‹ ํ˜ธ๊ฐ€ ํ•„์š”

encoder emulation ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด์„œ ์—”์ฝ”๋” ์‹ ํ˜ธ๋ฅผ ๋ฐœ์ƒ ์‹œํ‚ค๊ณ 

Gpt12 ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์—”์ฝ”๋” ์‹ ํ˜ธ ์ธํ„ฐํŽ˜์ด์Šค ๊ธฐ๋Šฅ ํ™•์ธ

#define ENCODER_EMUL // 65 ํ–‰ Configuration.h ํŒŒ์ผ in InfineonRacer ํ”„๋กœ์ ํŠธ์—์„œ

์„ ์ •์˜ ํ•˜๋ฉด emulation ํ•  ์ˆ˜ ์žˆ๋‹ค.


๋งˆ์น˜๋ฉฐ...

ํšŒ์ „ํ•˜๋Š” ์ถ•์˜ ์œ„์น˜์™€ ์†๋„๋ฅผ ์ธก์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจํ„ฐ์™€ ์—”์ง„ ๋“ฑ์„ ์‚ฌ์šฉํ•˜๋Š” ์ œ์–ด ์‹œ์Šคํ…œ์—์„œ ๊ผญ ํ•„์š”ํ•œ ๊ธฐ๋ณธ์ ์ธ ์ •๋ณด ์ž…๋‹ˆ๋‹ค. ์ด ๊ฐ’์„ ์ธก์ •ํ•  ์ˆ˜ ์—†๋‹ค๋ฉด ๋Œ€์•ˆ์ ์œผ๋กœ๋Š” ๊ด€์ธก๊ธฐ ๋“ฑ์„ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜๋Š” ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋Œ€๋ถ€๋ถ„, ๊ด€์ธก๊ธฐ๋ฅผ ์•„๋ฌด๋ฆฌ ์ž˜ ๋งŒ๋“ ๋‹ค๊ณ  ํ•˜๋”๋ผ๋„ ์‹œ์Šคํ…œ์˜ ์ „์ฒด ๋™์ž‘๊ธฐ๊ฐ„ ๋™์•ˆ ํ™œ์šฉํ•˜๊ธฐ๋Š” ์–ด๋ ต์Šต๋‹ˆ๋‹ค. ์ธก์ •ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ๊ฐ€๋Šฅํ•œ ์ •๋ฐ€ํ•˜๊ฒŒ ์ด ์ •๋ณด๋ฅผ ์•Œ์•„๋‚ด๋Š” ๊ฒƒ์ด ์‹œ์Šคํ…œ์„ ์•ˆ์ •์ ์œผ๋กœ ๊ตฌ์„ฑํ•˜๋Š” ์ฒซ ๊ฑธ์Œ์ด ๋ฉ๋‹ˆ๋‹ค.

ํšŒ์ „์ถ•์˜ ์œ„์น˜, ํ˜น์€ ์†๋„๋ฅผ ์•Œ์•„๋‚ด๋Š” ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ•์€ ์ง๊ด€์ ์œผ๋กœ ๋ช…ํ™•ํ•ฉ๋‹ˆ๋‹ค. ์—”์ฝ”๋”์™€ ๊ฐ™์ด ํšŒ์ „์ฒด์˜ ํŠน์ • ์œ„์น˜๋งˆ๋‹ค ํŽ„์Šค๋ฅผ ๋ฐœ์ƒํ•˜๋Š” ์„ผ์„œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, ์ƒ˜ํ”Œ๋ง ์ฃผ๊ธฐ ์ด๋‚ด์— ํŽ„์Šค ์‹ ํ˜ธ๊ฐ€ ๋ฐœ์ƒ๋˜๋Š” ๋ณ€ํ™”๊ฐ€ ์žˆ์–ด์•ผ ์ธก์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ์‹œ์Šคํ…œ์—์„œ ํ•„์š”๋กœ ํ•˜๋Š” PPR์„ ๊ฐ–๋Š” ์—”์ฝ”๋”๋ฅผ ์„ ํƒํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

์œ„์น˜์ •๋ณด๋กœ ์†๋„๋ฅผ ์–ป๋Š” ๊ฒƒ๋„ ๊ณ ๋ คํ•ด์•ผ ํ•  ์‚ฌํ•ญ์ด ๋งŽ์Šต๋‹ˆ๋‹ค. ๊ฐ€์žฅ ๊ฐ„๋‹จํ•˜๊ฒŒ๋Š” ์œ„์น˜์ •๋ณด๋ฅผ ๋ฏธ๋ถ„ํ•ด์„œ ์†๋„๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์ง€๋งŒ ์ด ๊ฒฝ์šฐ ๋…ธ์ด์ฆˆ๊ฐ€ ์ฆํญ๋˜์–ด ๋ถ€์ •ํ™•ํ•œ ์†๋„๋ฅผ ๋งŒ๋“ค์–ด ๋‚ด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋“ฑ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์‹ ํ˜ธ์ฒ˜๋ฆฌ ๊ธฐ๋ฒ•๋“ค์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ตœ๊ทผ angle tracking observer ๋ผ ๋ถˆ๋ฆฌ๋Š” ํ•„ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์œ„์น˜์ •๋ณด๋ฅผ ํ•„ํ„ฐ๋งํ•˜๊ณ  ์†๋„์ •๋ณด๋ฅผ ์–ป๋Š” ๊ธฐ๋ฒ•์ด ์ผ๋ฐ˜์ ์œผ๋กœ ๋งŽ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

WhereAreYou_32PPR_10Hz_part

WhereAreYou_32PPR_10Hz_1Period