Re: Debug mode and Programmer mode output 結果不一樣
|
||||
---|---|---|---|---|
新會員
|
以下是我的code, 我用的晶片是PIC18F452, 基本上如果把 code 分別用debug 和 programmer mode 在MPLAB 7.10 上 run 一下, 然後量一下 RC2 (PortC Pin 腳 2) 在這兩個 modes 下的PWM輸出,我就可以看到波形的不一樣。
我是用PWM 通過 LPF 的訊號去控制一顆 npn的基極電流, 電流沒有過載的問題,謝謝。 #include <pic18.h> __CONFIG(1,HSPLL&OSCSDIS); __CONFIG(2,BORDIS&PWRTEN&WDTDIS); __CONFIG(3,CCP2RC1); __CONFIG(4,DEBUGEN&LVPDIS); #define UPDATE_H 254 #define UPDATE_L 12 interrupt void ISR( ){ TMR1IF=0; // clear interrupt TMR1H=UPDATE_H; TMR1L=UPDATE_L; // timeout after 500 Tcyc GODONE=1; // start ADC } void main( ){ //Timer 1 Initialization -- See Above TMR1H=UPDATE_H; TMR1L=UPDATE_L; // timeout after 500 Tcyc TMR1IE=1; // enable Timer 1 interrutps, otherwise when rollover, it can not update CCP1L value. //Timer 2 Initialization PR2=0b11111111; // max count for 0.82 millisecond period. This register set up the PWM period. T2CON=0b00000100; // Postscale 1:1, Timer 2 on, Prescale 1:1 // Prescaler 1:1 for Fpwm = 19.53 KHz // Prescaler 1:4 for Fpwm = 4.88 KHz // Prescaler 1:16 for Fpwm = 1.2 KHz TMR2IE=0; // disable Timer 2 interrupts //CCP Initialization CCP1CON=0b00001100; // Duty cycle low bits 00, PWM mode CCPR1L=0; // Duty cycle 0% TRISD=0x00; TRISC2=0; // PWM out as output CCP1IE=0; // Disable CCP1 interrupts ADCON1=0b00101110; ADCON0=0b10000001; ADIE=0; // disable interrupt from ADC //Enable Interrupts and turn on interrupt source PEIE=1; GIE=1; TMR1ON=1; //Turn on 100us spaced interrupts endless: while(GODONE); // wait for conversion to be done PORTD=ADRESH; // the variable is case-sensitive. Xk1 is not equal to xk1. CCPR1L=ADRESH; goto endless; }
發表於: 2005/7/12 0:49
|
|||
|
Re: Debug mode and Programmer mode output 結果不一樣
|
||||
---|---|---|---|---|
版主
|
1、把程式弄簡單一點,只控制PWM就好,看有沒有問題。如還是不行,就把程式放上來看看,大家參詳參詳。
2、有關於推動馬達的問題:PIC的I/O腳多只能SINCK/SOURCE 25mA。您有沒有OVER SPEC.在用啊!
發表於: 2005/7/8 9:29
|
|||
|
Re: Debug mode and Programmer mode output 結果不一樣
|
||||
---|---|---|---|---|
新會員
|
CCP1CON=0b00001100; // Duty cycle low bits 00, PWM mode
TRISC2=0; // PWM out as output ADCON1=0b00101110; ADCON0=0b10000001; 以上是我的設定,只有在AN0 腳的地方是 analog input, 其它都是 digital mode. 但是我還是看不出問題在哪? 請指教,謝謝。
發表於: 2005/7/8 2:46
|
|||
|
Re: Debug mode and Programmer mode output 結果不一樣
|
||||
---|---|---|---|---|
版主
|
在debug模式底下,MPLAB會把某些ANALOG 腳(以及COMPARATOR 腳)自動幫您設為DIGITAL MODE,以便ICD能正常運行。
但是在PROGRAMMER MODE時,MPLAB不會做這個修正。 建議查一下相關腳位是否設為DIGITAL MODE。
發表於: 2005/7/6 18:30
|
|||
|
Debug mode and Programmer mode output 結果不一樣
|
||||
---|---|---|---|---|
新會員
|
我現在用一顆 PIC18F452 PICmicro 做 PWM 控制,不知為何在debug mode 下看到的 PWM output 是正確的 (漂亮的方波),但是等我用 programmer mode program chip 後,output 卻是不正確的 ( 怪怪的波形) 。
而且在接有 ICD-2 的情況下,Vdd 腳輸出的電壓才夠。如果沒接 ICD-2, Vdd 就不夠力去驅動馬達。 請指教~ 謝謝 Jack
發表於: 2005/7/3 3:48
|
|||
|