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


Browsing this Thread:   1 Anonymous Users






Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#10
初級會員
初級會員


查看用戶資訊
DEAR SIR:

怪自己學藝不精,LEAPER-48燒錄時,在載入.HEX檔後必須在Paramerters/Device Option 中的WATCH DOG TIMER 與OCSIILATOR等(與MPLAB的Configuration Bits 相同)選項做勾選的動作,之後再按下燒錄鍵即可...

CODE載入F54後可以動作了,但當我利用BUTTON選擇其它PWM段數時,按下BUTTON的延遲時間(必須消除彈跳)太長會導致PWM訊號瞬間消失(約800ms).
晚輩想到的方法是在按下BUTTON時(輸入狀態)將PORTB設成輸出狀態,利用這個作法來消除彈跳問題, 但這種作法卻讓CODE無法動作.(執行完TRISB=0xff 指令後約400us再將
PORTB設定為TRISB=0x00; )

不知這樣的作法,是否需搭配其他的設定呢?
即執行完TRISB=0xff; 後約400us 再執行TRISB=0x00; PORTB=0x00; 來消除按鍵彈跳問題,是否需再搭配其他設定..

底下是晚輩的程式碼:
#include "c:pic16f54__switchhtc.h"

__CONFIG HS WDTDIS UNPROTECT);


void main(void){

    
unsigned int i;

    
TRISA=0x0;    
    
TRISB=0xff;
    
PORTA=0xf;

    while(
1)
    {

         goto  
flash4;

flash0:
            
TRISB=0xff;

            
asm("clrf   5") ;     
                
            if(
RB0==1) goto flash11;
            if(
RB1==1) goto flash55;

            goto 
flash0;

            
//-------------------------------------------------//

flash11:    
            
TRISB=0x00;
            
PORTB=0x00;
            
asm("nop");
flash1:            
            
asm("bsf   5,0") ; 
            
asm("bsf   5,1") ; 

            for(
i=1;i<=50;i++){    

                if(
i==15PORTA=0b0010;    
                if(
i==45asm("clrf   5") ; 

            }

            if(
RB4==1) goto flash0;
    
            if(
RB0==1)  goto flash22;            
            
            if(
RB1==1)  goto flash11;

            
TRISB=0xff;

            goto 
flash1;

            
//-------------------------------------------------//
flash22:
            
TRISB=0x00;
            
PORTB=0x00;
            
asm("nop");
flash2:
            
asm("bsf   5,0") ; 
            
asm("bsf   5,1") ; 

            for(
i=1;i<=50;i++){                
                  
                if(
i==20PORTA=0b0010;    
                if(
i==45asm("clrf   5") ;
            }

            if(
RB4==1) goto flash0;

            if(
RB0==1) goto flash33;            

            if(
RB1==1) goto flash11;
            
            
TRISB=0xff;

            goto 
flash2;


            
//-------------------------------------------------//
flash33:
            
TRISB=0x00;
            
PORTB=0x00;
            
asm("nop");
flash3:
            
asm("bsf   5,0") ; 
            
asm("bsf   5,1") ; 

            for(
i=1;i<=50;i++){                
                    
                if(
i==25PORTA=0b0010;    
                if(
i==45asm("clrf   5") ;             
            }



            if(
RB4==1) goto flash0;
            
            if(
RB0==1) goto flash44;
            
            if(
RB1==1) goto flash22;

            
TRISB=0x00;
            
            goto 
flash3;


            
//-------------------------------------------------//
flash44:
            
TRISB=0x00;
            
PORTB=0x00;
            
asm("nop");        
flash4:
            
asm("bsf   5,0") ; 
            
asm("bsf   5,1") ; 
            for(
i=1;i<=50;i++){                                        
                if(
i==30PORTA=0b0010;    
                if(
i==45asm("clrf   5") ; 
            }        



            if(
RB4==1) goto flash0;
            
            if(
RB0==1) goto flash55;

            if(
RB1==1) goto flash33;

            
TRISB=0xff;            

            goto 
flash4;


            
//-------------------------------------------------//        
flash55:
            
TRISB=0x00;
            
PORTB=0x00;    
            
asm("nop");
flash5:
            
asm("bsf   5,0") ; 
            
asm("bsf   5,1") ; 

            for(
i=1;i<=50;i++){                
                
                if(
i==35PORTA=0b0010;    
                if(
i==45asm("clrf   5") ;            
            }

            if(
RB4==1) goto flash0;            
            
            if(
RB0==1) goto flash55;

            if(
RB1==1) goto flash44;

            
TRISB=0xff;

            goto 
flash5;
    
    }        

}





發表於: 2007/11/30 15:41
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#9
初級會員
初級會員


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#8
初級會員
初級會員


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#7
版主
版主


查看用戶資訊
程式裡的 Configuration Bits 設定為 Code Protection OFF, WDT Off, HS Mode。
4MHz 請改為 XT Mode , 程式看起來沒有錯,再用 MPLAB SIM 軟體模擬跑一次看看。

發表於: 2007/11/28 14:04
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#6
初級會員
初級會員


查看用戶資訊
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
//PWM OUTPUT RA0  RA1 

#include "c:pic16f54htc.h"

__CONFIG (0xFFE 0xFFB 0xFF7);

void main(void){

    
unsigned char i;
   
       
TRISA=0b0000;    
    
PORTA=0b1111//RA0 ~ RA3 PWM output

    
while(1){
                
PORTA=0b1111;
                for(
i=1;i<=20;i++){                
                    if(
i==10PORTA=0b0000;                
                }
                
PORTA=0b1111;    
    }        

}


發表於: 2007/11/27 15:47
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#5
初級會員
初級會員


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#4
初級會員
初級會員


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#3
初級會員
初級會員


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#2
初級會員
初級會員


查看用戶資訊
請確認以下的設定 :

1. 振盪器選設要正確, 與電路板上的振盪器須一致.

2. 若有設定Watch Dog為Enable, 則程式碼當中就必須在每一個while迴圈中寫入此行指令 asm("clrwdt") ; // Clear WDT ;
否則程式會持續被重置無法正常執行.

3. 以上的設定在MPLAB IDE中, 即Configure / Configuration Bits.


發表於: 2007/11/22 17:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


用Hi-TECH 編寫PIC16F54 PWM輸出的問題
#1
初級會員
初級會員


查看用戶資訊
各位前輩好:

小弟第一次接觸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
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... ]

教育訓練中心

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