Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
初級會員
|
Dear Ryang & Willian:
很感謝您們的建議與指導... 晚輩能想的步驟都試過了, 傷腦筋... 首先: 1.在__CONFIG() 中試過XP HS RC(5.1K+20pf) 等, WATCH DOG 也設成 WDTDIS, 即 __CONFIG(XP & WDTDIS & UNPROTECT). 2.在FOR迴圈中的條件值會在20上下是考慮到PWM的頻率須大於1K HZ, 且當值越大佔的FLASH空間會越多, 所以才這麼小,目前晚輩寫的PWM輸出共有10種變化,用的又是C, 唯有如此才塞的進PIC16F54中. 3.我用的燒錄器是LEAPER-48 , 很擔心是不是這台的問題, 剛剛才跟我們的MCU供應商暫借一台ICD2, 希望可藉此釐清問題. 4.在MPLAB 的Configuration Bits 的設定我有勾選,設定值也跟__CONFIG()中的相同. 5.在MPLAB SIM 的功能中, 晚輩有開啟SIMULATOR LOGIC ANALYER PWM波形是正常的 , 頻率約3K. 晚上K完ICD2的用法後, 希望問題都能迎刃而解...
發表於: 2007/11/28 17:56
|
|||
|
Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
初級會員
|
1. 單晶片PIC16F54的第4支腳位為MCLR, 必須接至VDD.
2. 將 i 的值由 20 改為 250 , 部分程式碼如下: for(i=1;i<=250;i++){ if(i==125) PORTA=0b0000; } // 將i值加大可明顯看出PORTA是否有輸出變化. 3. 三用電錶不適合用來量測會瞬間變化的PWM時脈, 建議使用示波器或者邏輯分析儀去觀察PORTA每支腳的準位變化.
發表於: 2007/11/28 14:32
|
|||
|
Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
版主
|
程式裡的 Configuration Bits 設定為 Code Protection OFF, WDT Off, HS Mode。
4MHz 請改為 XT Mode , 程式看起來沒有錯,再用 MPLAB SIM 軟體模擬跑一次看看。
發表於: 2007/11/28 14:04
|
|||
|
Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
初級會員
|
Dear Sir:
晚輩的問題又來了, 感覺很簡單, 但就是搞不定...呵呵!!! 我在DEBUG模式下, 利用MPLAB中的邏輯分析儀來觀察PWM的動作十分正常, 但將PIC接到麵包板上就是動不了, 底下是我的檢測動作: 1. 確定 POWER 電壓 為+5V. 2. 震盪器 4MHZ 電容18PF, 震盪器上的電壓會在 2.4~1.8 V 間跳動. 3. 用電錶去量RA0 與RA1接腳一直沒有PWM輸出. 4.用Hi-tech Compiler是成功的. 不知到還有哪裡忽略掉了呢? 謝謝!!! 底下是測試的 CODE:
//OSC : 4MHZ
發表於: 2007/11/27 15:47
|
|||
|
Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
初級會員
|
Dear Willian:
Complier 成功, 真開心!!! 謝謝您的協助... CODE 如下: //OSC : 4MHZ //PWM OUTPUT RA0 RA1 //mini-switch RB0 RB1 RB2 //#define _HTC_H_ #include "c:\pic16f54\htc.h" //#define __CONFIG(x) asm("\tpsect config,class=CONFIG,delta=2");\ // asm("\tdw "___mkstr(x)) unsigned char i; unsigned char count=0; __CONFIG (0xFFE & 0xFFB & 0xFF7); void detectPort(void) { unsigned int delay=200000; //de-bounce while(delay--); //power off if(RB4==1) count=0; //increcement PWM if(RB0==1) { if(count==7) count=0; else count++; } //decrecement PWM if(RB1==1) { if(count==0) count=7; else count--; } } void main(void){ TRISB=0b11111111; TRISA=0b1100; while(1) { /*---------------------------------------------------------------*///pwm 0 while(count==0){ PORTA=0b0000; detectPort(); } /*---------------------------------------------------------------*///pwm 30 90 while(count==1){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==6) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 40 90 while(count==2){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==8) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 50 90 while(count==3){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==10) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 60 90 while(count==4){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==12) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 70 90 while(count==5){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==14) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 80 90 while(count==6){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==16) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 90 90 while(count==7){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==16) PORTA=0b0000; } PORTA=0b0011; detectPort(); } } }
發表於: 2007/11/26 14:17
|
|||
|
Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
初級會員
|
1. 先將MPLAB IDE中的Configure / Configuration Bits的選項Configuration Bits set in code給勾選.
2. 在程式碼加入一行指令, 如下: __CONFIG (HS & WDTDIS & CP) ; (將此行直接複製貼到你的程式碼比較快) 3. 執行Build All之後, Configure / Configuration Bits的設定,即會自動寫入 .HEX檔.
發表於: 2007/11/26 13:22
|
|||
|
Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
初級會員
|
Dear Willian:
如果用的是MPASM 那便可以加入這行來做宣告 __CONFIG _CP_ON & _WDT_OFF & _HS_OSC 但我用的是HI-TECH 所以只需要在IDE 中的Configure / Configuration Bits 設OSC 為HS 並關閉WATCH TIMER 就好那麼COMPLIER時會自動將這些設定值包進 .HEX檔嗎? 剛剛做了實驗發現我OSC選 HS 或XT 與 WDT 選 ON 或OFF .HEX檔的內容是乎都沒變化... 請問 HI-TECH 宣告 WDT OFF 與 OSC 選擇 HS 的指令為何呢(目前正尋找中)?
發表於: 2007/11/26 11:31
|
|||
|
Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
初級會員
|
請確認以下的設定 :
1. 振盪器選設要正確, 與電路板上的振盪器須一致. 2. 若有設定Watch Dog為Enable, 則程式碼當中就必須在每一個while迴圈中寫入此行指令 asm("clrwdt") ; // Clear WDT ; 否則程式會持續被重置無法正常執行. 3. 以上的設定在MPLAB IDE中, 即Configure / Configuration Bits.
發表於: 2007/11/22 17:39
|
|||
|
用Hi-TECH 編寫PIC16F54 PWM輸出的問題
|
||||
---|---|---|---|---|
初級會員
|
各位前輩好:
小弟第一次接觸PIC,為了好上手於是用HI-TECH 編寫PIC16F54, 並透過 LEAPER-48 燒錄到 F54 ,之後PIC 卻無法動作, 不知是不是我CODE寫錯了, 還是少了什麼設定呢? 請各位前輩指導? (消除彈跳我用的是RC電路 500K+1uf 所以CODE沒有寫消除彈跳的程式,震盪器電壓我用電錶量約2.4V) //OSC : 4MHZ //PWM OUTPUT RA0 RA1 //mini-switch RB0 RB1 RB2 #define _HTC_H_ #include <pic16f5x.h> unsigned char i; unsigned char count=0; unsigned int delay; void detectPort(void) { //power off if(RB4==1) count=0; //increcement PWM if(RB0==1) { if(count==6) count=0; else count++; } //decrecement PWM if(RB1==1) { if(count==0) count=6; else count--; } } void main(void){ #asm CLRWDT; #endasm TRISB=0b11111111; TRISA=0b1100; while(1) { /*---------------------------------------------------------------*///pwm 0 while(count==0){ PORTA=0b0000; detectPort(); } /*---------------------------------------------------------------*///pwm 30 90 while(count==1){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==6) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 40 90 while(count==2){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==8) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 50 90 while(count==3){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==10) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 60 90 while(count==4){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==12) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 70 90 while(count==5){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==14) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 80 90 while(count==6){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==16) PORTA=0b0010; if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } /*---------------------------------------------------------------*///pwm 90 90 while(count==7){ PORTA=0b0011;//ouput "H" for(i=0;i<=20;i++){ if(i==18) PORTA=0b0000; } PORTA=0b0011; detectPort(); } } }
發表於: 2007/11/22 10:18
|
|||
|