Re: 如何使用dsPIC33FJ16GS502中的HIGH-SPEED ANALOG COMPARATOR應用
|
||||
---|---|---|---|---|
資深會員
|
祝你有好的開始~~!!
發表於: 2009/5/21 14:19
|
|||
Thanks,
Edward Lee |
||||
|
Re: 如何使用dsPIC33FJ16GS502中的HIGH-SPEED ANALOG COMPARATOR應用
|
||||
---|---|---|---|---|
初級會員
|
感謝edwardlee的解答
我重新檢查我所有的設定並對照data-sheet後發現問題了 就如同edwardlee的解答,一一對照修改後成功的達到我要的結果,對於我這個初學者有很大的幫助,寫到眼花了。 再次感謝啦
發表於: 2009/5/21 11:53
|
|||
|
Re: 如何使用dsPIC33FJ16GS502中的HIGH-SPEED ANALOG COMPARATOR應用
|
||||
---|---|---|---|---|
初級會員
|
您好,我照著你給的步驟去修改,還是沒有達到我要的結果
他出現的結果為PWM在過電壓後依舊存在,並無截斷的現象,我將我所有設定貼上,麻煩幫我指點一下迷津 /* Configuration Bit Settings */ _FOSCSEL(FNOSC_FRC) _FOSC(FCKSM_CSECMD & OSCIOFNC_ON) _FWDT(FWDTEN_OFF) _FPOR(FPWRT_PWR128 & BOREN_OFF) _FICD(ICS_PGD2 & JTAGEN_OFF) int main(void) { /* Configure Oscillator to operate the device at 40Mhz Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 Fosc= 7.37*(43)/(2*2)=80Mhz for Fosc, Fcy = 40Mhz */ /* Configure PLL prescaler, PLL postscaler, PLL divisor */ PLLFBD=41; /* M = PLLFBD + 2 */ CLKDIVbits.PLLPOST=0; /* N1 = 2 */ CLKDIVbits.PLLPRE=0; /* N2 = 2 */ __builtin_write_OSCCONH(0x01); /* New Oscillator FRC w/ PLL */ __builtin_write_OSCCONL(0x01); /* Enable Switch */ while(OSCCONbits.COSC != 0b001); /* Wait for new Oscillator to become FRC w/ PLL */ while(OSCCONbits.LOCK != 1); /* Wait for Pll to Lock */ /* Now setup the ADC and PWM clock for 120MHz ((FRC * 16) / APSTSCLR ) = (7.37 * 16) / 1 = ~ 120MHz*/ ACLKCONbits.FRCSEL = 1; /* FRC provides input for Auxiliary PLL (x16) */ ACLKCONbits.SELACLK = 1; /* Auxiliary Oscillator provides clock source for PWM & ADC */ ACLKCONbits.APSTSCLR = 7; /* Divide Auxiliary clock by 1 */ ACLKCONbits.ENAPLL = 1; /* Enable Auxiliary PLL */ while(ACLKCONbits.APLLCK != 1); /* Wait for Auxiliary PLL to Lock */ PTPER=9422; /*---SET UP TIMER1---*/ T1CON=0; TMR1=0; PR1=PTPER; /*---INTERRUPTS INITIALIZATION---*/ IPC23bits.PWM2IP=4; IFS5bits.PWM2IF=0; IEC5bits.PWM2IE=1; IFS0bits.T1IF=0; IEC0bits.T1IE=0; /*---PWM1 INITIALIZATION---*/ IOCON1bits.PENH=1; IOCON1bits.PENL=1; IOCON1bits.PMOD=0; PWMCON1bits.FLTSTAT=0; PWMCON1bits.CLSTAT=0; PWMCON1bits.TRGSTAT=0; PWMCON1bits.FLTIEN=0; PWMCON1bits.CLIEN=0; PWMCON1bits.TRGIEN=0; PWMCON1bits.ITB=0; PWMCON1bits.MDCS=0; PWMCON1bits.DTC=0; PWMCON1bits.XPRES=0; PWMCON1bits.IUE=0; IOCON1bits.FLTDAT=0; FCLCON1bits.FLTSRC=1; FCLCON1bits.FLTPOL=1; FCLCON1bits.FLTMOD=1; PDC1=4711; DTR1=283; ALTDTR1=283; /*---PWM2 INITIALIZATION---*/ IOCON2bits.PENH=1; IOCON2bits.PENL=1; IOCON2bits.PMOD=0; TRGCON2bits.TRGDIV=0; TRGCON2bits.TRGSTRT=0; TRIG2=2596; PWMCON2bits.FLTSTAT=0; PWMCON2bits.CLSTAT=0; PWMCON2bits.TRGSTAT=0; PWMCON2bits.FLTIEN=0; PWMCON2bits.CLIEN=0; PWMCON2bits.TRGIEN=1; PWMCON2bits.ITB=0; PWMCON2bits.MDCS=0; PWMCON2bits.DTC=0; PWMCON2bits.XPRES=0; PWMCON2bits.IUE=0; IOCON2bits.FLTDAT=0; FCLCON2bits.FLTSRC=1; FCLCON2bits.FLTPOL=1; FCLCON2bits.FLTMOD=1; PDC2=4711; DTR2=283; ALTDTR2=283; /*---ADC INITIALIZATION---*/ ADCONbits.ADSIDL=0; ADCONbits.FORM=0; ADCONbits.ORDER=0; ADCONbits.SEQSAMP=1; ADPCFGbits.PCFG5=0; ADSTATbits.P2RDY=0; ADCPC1bits.TRGSRC2=5; /*---CMP2D Configuration---*/ CMPCON2bits.INSEL=3; CMPCON2bits.EXTREF=0; CMPCON2bits.RANGE=1; CMPDAC2bits.CMREF=1023; CMPCON2bits.CMPPOL=1; /*---Configuring Analog Comparator---*/ __builtin_write_OSCCONL(OSCCON & ~(1<<6)); RPOR16bits.RP32R = 0b100111; RPINR29bits.FLT1R=32; __builtin_write_OSCCONL(OSCCON | (1<<6)); /*---Enable PWM and Timer---*/ PMD1bits.PWMMD=0; PMD1bits.ADCMD=0; PMD3bits.CMPMD=0; CMPCON2bits.CMPON=1; ADCONbits.ADON=1; T1CONbits.TON=1; PTCONbits.PTEN=1; while(1); } 附加檔案用不上去,只好貼在這哩,麻煩一下了
發表於: 2009/5/20 16:06
|
|||
|
Re: 如何使用dsPIC33FJ16GS502中的HIGH-SPEED ANALOG COMPARATOR應用
|
||||
---|---|---|---|---|
資深會員
|
1.首先"我要設定輸入超過1.8V時就截斷PWM"
這部份需要更正, 不同於PIC24, 最大運作範圍只有0~(3.3-1.65v), 所以1.8V不行! 2.你有一部份沒寫, 不知有無忘了設定, PMDx記得設定, 不然該比較器可能會被關掉!! 以及該PIN應為INPUT腳, 照理說會規劃為AD PIN. 3.我逐步說明你的設定: CMPCON3bits.INSEL=0;---------->使用CMP3A CMPCON3bits.EXTREF=0; ------->使用外部參考來源, 但最大只能AVDD-1.6, 所以建議使用內部即可. CMPCON3bits.RANGE=1; -------->同上 CMPDAC3bits.CMREF=1117; --->我不知你外部電壓多少? 但是CMREF才10BIT(0~1023), 1117過大了!!?? CMPCON3bits.CMPON=1; -------->最好設定完才ON!! CMPCON3bits.CMPPOL=1; ------->Normal High 4.再來就是設定PWM, 請參考: http://ww1.microchip.com/downloads/en/DeviceDoc/70323B.pdf page 43-18 ~ page 43-19兩種方式都可以, 但是請注意, 舊版Data sheet有錯, 此版才是對的, 也就是不直接支援比較器, 需要再設定一些方式才支援, 但是放心, 還是直接硬體動作, 速度還是快到抓不住~ 設定方式請參考:page 43-56 其中意思就是比較器輸出先設定到一虛擬空pin, 然後Faultx也設定到該虛擬空pin, 範例是都設應到RP32, 這樣就大功告成啦~~沒問題的, 我也是這樣使用!! 這部份設定不是只有比較器, 很多模組都要相對設定, 你要注意其他部份設定才是重點. 另外你說不成功, 但是沒說如何不成功法? PWM繼續輸出? OR 只是該動作沒產生 OR ..? 若還是有問題, 明天到台北研討會找我, 或是CALL ME #656
發表於: 2009/5/20 13:49
|
|||
Thanks,
Edward Lee |
||||
|
Re: 如何使用dsPIC33FJ16GS502中的HIGH-SPEED ANALOG COMPARATOR應用
|
||||
---|---|---|---|---|
版主
|
Edward 正在看你的設定,他會給你些建議的。
發表於: 2009/5/20 11:49
|
|||
|
Re: 如何使用dsPIC33FJ16GS502中的HIGH-SPEED ANALOG COMPARATOR應用
|
||||
---|---|---|---|---|
初級會員
|
請問要去哪裡找他?謝謝
發表於: 2009/5/20 11:43
|
|||
|
Re: 如何使用dsPIC33FJ16GS502中的HIGH-SPEED ANALOG COMPARATOR應用
|
||||
---|---|---|---|---|
版主
|
找 SMPS 專家 Edward 來回答你的問題。
發表於: 2009/5/20 11:24
|
|||
|
如何使用dsPIC33FJ16GS502中的HIGH-SPEED ANALOG COMPARATOR應用
|
||||
---|---|---|---|---|
初級會員
|
請問我想使用HIGH-SPEED ANALOG COMPARATOR來檢測電壓超過預期值時截斷PWM輸出,要如何設定
我要設定輸入超過1.8V時就截斷PWM,以下是我試著設定的部份 CMPCON3bits.INSEL=0; CMPCON3bits.EXTREF=0; CMPCON3bits.RANGE=1; CMPDAC3bits.CMREF=1117; CMPCON3bits.CMPON=1; CMPCON3bits.CMPPOL=1; 試過之後卻不成功,哪裡出問題呢?是不能這樣設定還是要搭配其他部分暫存器設定,請指點一下迷津
發表於: 2009/5/20 11:17
|
|||
|