๋ชฉ์ฐจ
๐ Enhanced capture์ ์ฝ์๋ก ๊ฐ๋จํ๊ฒ ๋งํด์ ์๊ฐ๋ณ์์ analog data๋ฅผ digital๋ก ๋ฐ๊พธ๋ ๋์์ ์๋ฏธํ๋ค.
๐ ์ด ๋ชจ๋์์๋ PWM์ ๋ ฅ ์ ํธ์ Rinsing edge๋ฅผ ๊ฒ์ถ ํ๋๋ฐ ์ฒซ ๋ฒ์งธ Rising edge๋ฅผ ์ฒซ ๋ฒ์งธ Time-stamp์ ์ ์ฅ, ๋ ๋ฒ์งธ Rising edge์ time์ ๋ ๋ฒ์งธ Time-stamp์ ์ ์ฅํ๋ ์ด๋ฐ ๋ฐฉ์์ผ๋ก ๊ณ์ ์ ํธ๋ฅผ ๋ฐ์์ ๊ธฐ๋กํ๊ณ Timer๋ ๊ณ์ ์ฆ๊ฐํ๋๋ฐ ์ด ๊ฒฝ์ฐ Timer๊ฐ ์ ํธ๊ฐ ๋๋๊ธฐ ์ ๊น์ง reset๋์ง ์๊ธฐ ๋๋ฌธ์ overflow๊ฐ ๋ฐ์ํ ์ ์๋ค.
๐ ์ด ๋ชจ๋์์๋ PWM์ ๋ ฅ ์ ํธ์์ Rising edge์ ๊ทธ ๋ค์ Rising edge์ฌ์ด์ ์๊ฐ์ ์ ์ฅํ๋๋ฐ edge๊ฐ detect๋๋ฉด ์๋์ผ๋ก Timer๊ฐ reset์ด ๋๊ธฐ ๋๋ฌธ์ overflow๊ฐ ๊ฑฐ์ ๋ฐ์ํ์ง ์๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ edge๊ฐ์ ์๊ฐ์ Time-stamp์ ๊ธฐ๋ก๋๋ ๊ฐ์ ์ฝ์ผ๋ฉด ๋๋ค.
๐ Capture mode๊ฐ ํ์ํ์ง ์๋ค๋ฉด mode๋ฅผ ๋ฐ๊ฟ์ PWM์ฑ๋๋ก ํ์ฅ์ด ๊ฐ๋ฅํ๋ค. ์ด ๋ชจ๋์์๋ phase shift๊ธฐ๋ฅ๊ณผ ePWM๋ชจ๋๊ณผ ๋๊ธฐํ ๊ธฐ๋ฅ์ ์ ๊ณต์ ํ์ง๋ง ePWM์ ๋ค๋ฅธ ๊ธฐ๋ฅ๋ค์ ์ฌ์ฉํ ์ ์๋ค.
SOURCE TR28335_Rotary.h
/*===========================================================
*
* FILE : TR28335_Rotary.h .2017
* TITLE : TR28335 Temp ROTARY Sensor eCAP(Enhanced Capture)
*
*==========================================================*/
#ifndef __TR28335_ROTARY_H__
#define __TR28335_ROTARY_H__
#ifdef _cplusplus
extern "C" {
#endif
#include <main.h>
void InitRotaryIsr(void);
#ifdef _cplusplus
}
#endif /* extern "C" */
#endif /* __TR28335_ROTARY_H__ */
SOURCE TR28335_Rotary.c
/*===========================================================
*
* FILE : TR28335_Rotary.c .2017
* TITLE : TR28335 Temp ROTARY Sensor eCAP(Enhanced Capture)
*
*==========================================================*/
#include <TR28335_Rotary.h>
#include <TR28335_Led.h>
Uint16 gRotaryIsrTicker;
Uint32 gCaptureCounter1;
Uint32 gCaptureCounter2;
Uint32 gEdgeCount;
interrupt void eCapture1_isr(void);
static void InitECapture1(void);
/*==============================================================
*
* Name : InitECapture1
* Type : Fucntion
* Description : Rotary Interrupt Service Routine Initialization
*
================================================================*/
void InitRotaryIsr(void)
{
InitECap1Gpio();
EALLOW;
GpioCtrlRegs.GPACTRL.bit.QUALPRD3 = 0xFF;
GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 2;
EDIS;
/* Interrupt Service Routine Re-mapping */
EALLOW;
PieVectTable.ECAP1_INT = &eCapture1_isr;
EDIS;
/* Enable PIE group4 interrupt 1 for ECAP1_INT */
PieCtrlRegs.PIEIER4.all = M_INT1;
IER |= M_INT4;
gRotaryIsrTicker = 0;
gCaptureCounter1 = 0;
gCaptureCounter2 = 0;
gEdgeCount = 0;
InitECapture1();
return ;
}
/*=============================================
*
* Name : eCapture1_isr
* Type : Interrupt
* Description : eCap Interrupt Service Routine
*
==============================================*/
interrupt void eCapture1_isr(void)
{
/* Verifying the ISR */
gRotaryIsrTicker++;
/* Excute LED toggle function */
LedCtrl(LED_ALL, LED_TOGGLE);
/* Calculate counter value between Rising Edge and Falling Edge */
gCaptureCounter1 = ECap1Regs.CAP1;
gCaptureCounter2 = ECap1Regs.CAP2;
if(ECap1Regs.ECFLG.bit.CTROVF == 1)
{
gEdgeCount = (0xFFFFFFFF - gCaptureCounter1) + gCaptureCounter2;
ECap1Regs.ECCLR.bit.CTROVF = 1;
}
else
gEdgeCount = gCaptureCounter2 - gCaptureCounter1;
/* eCapture 1 Interrupt clear */
ECap1Regs.ECCLR.bit.CEVT2 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
/* Acknowledge this interrupt to receive more interrupts from group 4*/
PieCtrlRegs.PIEACK.bit.ACK4 = 1;
return ;
}
/*=======================================
*
* Name : InitECapture1
* Type : Fucntion
* Description : eCAP Initialization
*
=========================================*/
void InitECapture1(void)
{
ECap1Regs.ECEINT.all = 0x0000; /* Disable all capture interrupts */
ECap1Regs.ECCLR.all = 0xFFFF; /* Clear all CAP interrupt flag */
ECap1Regs.ECCTL1.bit.CAPLDEN = 0; /* Disable CAP1-CAP4 register loads */
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; /* Make sure the counter is stopped */
/* Configure peripheral regisers */
ECap1Regs.ECCTL2.bit.CAP_APWM = 0; /* ECAP1 Module operate in capture mode */
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; /* Operate in continuous mode */
ECap1Regs.ECCTL2.bit.STOP_WRAP = 1; /* Stop at 2 events */
ECap1Regs.ECCTL1.bit.CAP1POL = 0; /* Rising edge */
ECap1Regs.ECCTL1.bit.CAP2POL = 1; /* Falling edge */
ECap1Regs.ECCTL1.bit.CTRRST1 = 0; /* Absolute time-stamp operation */
ECap1Regs.ECCTL1.bit.CTRRST2 = 0; /* Absolute time-stamp operation */
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; /* Enable capture units */
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; /* Start Counter */
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; /* Enable CAP1- CAP4 register loads */
ECap1Regs.ECEINT.bit.CEVT2 = 1; /* 2 events = interrupt */
return ;
}
TR28335 ๋ชจ๋ PWM ์ฌ์ฉํ (0) | 2018.12.27 |
---|---|
FLASH API (0) | 2018.12.26 |
TR28335 ๊ฐ๋ฐ KIT IC2(Inter integrated circuit) ํต์ (2) | 2017.06.27 |
TR28335 ๊ฐ๋ฐ KIT Potentiometer ๊ฐ๋ณ์ ํญ ADC ๋ก Control (0) | 2017.06.26 |
TR28335 ๊ฐ๋ฐ KIT Switch GPIO Input (0) | 2017.06.23 |