• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Input Capture沒啟用中斷一直Target Halted
#1
新會員
新會員


查看用戶資訊
求助各位大大
mcu使用--dsPIC33EV64GM104
編譯器用 XC16-v1.6 + MPLAB X v5.3

最近想用input capture做寬範圍的轉速偵測(0~99999RPM),
想用33EV的2個16bit input capture級連成32bit的input capture,不用中斷的方式處理capture信號,想用scan的方式偵測捕捉溢位(ICOV)再來計算轉速,經debug測試當buffer滿及IC1TMR由0xfff跳至0時老是跳出 Target Halted,因沒啟動IC1中斷,查過技術文件無相關資料,故求助各位.不知是何原因
以下是我重作的1個小的測試程式,問題仍然相同,


#include "xc.h"
#include "p33EV64GM104.h"

struct two_word
{ unsigned long low:16;
unsigned long hi:16;
};

union long_data
{ unsigned long all;
struct two_word word;
};

union long_data icdata1,icdata2;
unsigned int Ic1Fifo[5],Ic2Fifo[5];
int aa;

main(void)
{
// FRCDIV FRC/1; PLLPRE 7; DOZE 1:1; PLLPOST 1:2; DOZEN disabled; ROI disabled;
CLKDIV = 0x0005;
// TUN Center frequency;
OSCTUN = 0x00;
// ROON disabled; ROSEL FOSC; RODIV 0; ROSSLP disabled;
REFOCON = 0x00;
// PLLDIV 112; 0x70=112 = *114 multiple
PLLFBD = 0x70;
// AD1MD enabled; PWMMD enabled; T3MD enabled; T4MD enabled; T1MD enabled; U2MD enabled; T2MD enabled; U1MD enabled; SPI2MD enabled; SPI1MD enabled; C1MD enabled; T5MD enabled; I2C1MD enabled;
PMD1 = 0x00;
// IC4MD enabled; IC3MD enabled; OC1MD enabled; IC2MD enabled; OC2MD enabled; IC1MD enabled; OC3MD enabled; OC4MD enabled;
PMD2 = 0x00;
// CMPMD enabled;
PMD3 = 0x00;
// CTMUMD enabled; REFOMD enabled;
PMD4 = 0x00;
// PWM2MD enabled; PWM1MD enabled; PWM3MD enabled;
PMD6 = 0x00;
// DMA0MD enabled;
PMD7 = 0x00;
// DMTMD enabled; SENT2MD enabled; SENT1MD enabled;
PMD8 = 0x00;
// CF no clock failure; NOSC FRCPLL; CLKLOCK unlocked; OSWEN Switch is Complete;
__builtin_write_OSCCONH((unsigned char) (0x01));
__builtin_write_OSCCONL((unsigned char) (0x01));
// Wait for Clock switch to occur
while (OSCCONbits.OSWEN != 0);
while (OSCCONbits.LOCK != 1);

//----------------------pps set----------------
__builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS ,unlock i/o lock

RPINR7bits.IC1R=0x27; //RP39 PIN CONFIGURE TO IC1 ,RP39 39=0X27

__builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS

//-----------------------t2 init----------------------
/* ensure Timer 2 is in reset state */
T2CON = 0;

/* set Timer2 interrupt priority level to 4 */
IPC1bits.T2IP = 4;

/* reset Timer 2 interrupt flag */
IFS0bits.T2IF = 0;

/* disable Timer 2 interrupt */
IEC0bits.T2IE = 0;



/* set Timer 1 period register */
T2CONbits.TCS=0; //TCS=CLOCK SOURCE, 0=FOSC/2, 1= EXIT TxCK PIN INPUT
T2CONbits.TCKPS=3; //預分頻 3=256, 0=1, 1=8, 2=64, 3=256
// PR2=0xffff;

//----------------ic1 set--------------------------
TRISBbits.TRISB7=1; //set ic2 input pin -> input
CNPUBbits.CNPUB7=1;


IFS0bits.IC1IF = 0; // Clear the IC1 interrupt status flag
IEC0bits.IC1IE = 0; // disable IC1 interrupts
// IPC0bits.IC1IP = 4; // Set module interrupt priority as 1

IC1CON1bits.ICTSEL=0b001; //use timer 2
IC1CON1bits.ICI=0b11; //4 times input capture ,interrupt once

IC1CON2bits.IC32=0; //ic1 16bit ic
IC1CON2bits.ICTRIG=1; //1; //set ic1 TRIGSTAT to tigger mode
IC1CON2bits.SYNCSEL=0; //0b10101; //0; //ic1 no tigger source

IC1CON1bits.ICM=4;
T2CONbits.TON=1;
IC1CON2bits.TRIGSTAT=1;

while (1)
{ if(IC1CON1bits.ICOV) //IC1 capture overflow
{ aa=0;
IC1CON2bits.TRIGSTAT=0; //tigger rest, timer 2 =0
// IC2CON2bits.TRIGSTAT=0; //tigger rest, timer 2 =0

while (IC1CON1bits.ICBNE) { Ic1Fifo[aa]=IC1BUF;aa++;}; // Ic2Fifo[ica]=IC2BUF; ica++;}; //when ICBNE=1 read buffer data
IC1CON1bits.ICM=0; // rest IC1TMR

while( aa==4)
{ icdata1.word.low=Ic1Fifo[0]; //4 rising capture once ,
icdata1.word.hi= Ic2Fifo[0]; //3 counter of capture is 12 pcs of rising ,
icdata2.word.low=Ic1Fifo[3];
icdata2.word.hi=Ic2Fifo[3];
};
IC1CON1bits.ICM=4; //ic1 start
IC1CON2bits.TRIGSTAT=1;
};





};

return 0;
}

發表於: 2021/6/23 9:18
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------