• 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: 請問各位前輩有關於18F4431的問題
#5
新會員
新會員


查看用戶資訊
Dear,
kindly regarding assigning the freq of Crystal ?? where u set this 16 Mhz, I will Appreciate much if you could post this code with English comments,
have a good day..

發表於: 2008/12/22 19:07
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問各位前輩有關於18F4431的問題
#4
新會員
新會員


查看用戶資訊
Dear,
kindly regarding assigning the freq of Crystal ?? where u set this 16 Mhz, I will Appreciate much if you could post this code with English comments,
have a good day..

發表於: 2008/12/22 19:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問各位前輩有關於18F4431的問題
#3
新會員
新會員


查看用戶資訊
謝謝calvinho大哥...

發表於: 2005/12/8 21:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問各位前輩有關於18F4431的問題
#2
管理員
管理員


查看用戶資訊
你好 :

以下的範例是由 PIC18F4431 產生 20K PWM 信號的範例. 用 C18 寫成的啦 ! 但是改成組合與言應該不難.

PWM0/PWM1 固定產生 50 % 的 Duty , PWM2/PWM3 則為 75 %. 重點是 PWM4/PWM5 , 它的 Duty Cycle 會由 0% to 100% 變化. 主要就是要 Demo 如何改變 PWM Duty 啦 ::

//     Purpose of this demo                                                       *
//     > 使用 16 Mhz 的 Crystal 以及 HS 的震盪模式 , 來產生 PWM 的輸出          *
//   > 希望產生的 PWM 的 Period = 100 us
//     > 希望得到的 Duty Cycle : 50% 及 75%
//   > PWM Frequency = 20K ( when PTPER = 49 ) , PWM Prescaler = 1:4 
//   > Duty Cycle for PWM = 0 to 200 ( 四倍於 PTPER )
//******************************************************************************

#include <p18f4431.h>
#include <delays.h>

void    PowerPWM_Initialvoid );            // Prototype Declaration
void    IO_Initialvoid ) ;
void    Set_DCint int ) ;
void    Duty_Delay(void) ;

union                                        // Use this union to convert word value
    
{                                        // to "byte" value
        
int                Word ;
        
unsigned char     Byte[2] ;

    } 
Int2Byte ;
    
//***************************************
//*             Program Main ( )        *
//***************************************
void main(void)
{
    
int     PWM_Duty ;

    
PWM_Duty ;

    
IO_Initial( ) ;                            // Set direction for PWM Pins
    
PowerPWM_Initial( ) ;                    // Initial PWM module
 
    
while(1)                                  // Now , you can get the result 
    
{
         
Duty_Delay( ) ;
        
Set_DC(2,PWM_Duty) ;
        
PWM_Duty ++ ;

        if ( 
PWM_Duty 200 )    PWM_Duty ;
        
    }
    
//     1: 在 RB0 & RB1 , 可以得到互補的 PWM 輸出. Duty Cycle = 50%
    //    2: 在 RB2 & RB3 , 可以得到互補的 PWM 輸出. Duty Cycle 為 75%
    //  3. 在 RB4 & RB5 , 可以得到 Duty 由 0% to 100% 的遞增 , 歸零後繼續遞增的輸出
}

void    Duty_Delay(void)
{
    
int    Dely ;
    
    for ( 
Dely Dely 10000 Dely ++ ) ;    
    
}

void    PowerPWM_Initialvoid )
{

        
PTCON0  0b00000100 ;;        //    PWM Timer Control Register
                                     //    PTOPS3:0 = 0000    > Output Postscale = 1:1
                                    //  PTCKPS1:0 = 01     > PWM Time Base Input Clock Prescaler  , 1:4
                                    //  PTMOD1:0 = 00    > PWM time base operates in "Free Running Mode"

            
        
PWMCON0 0b01000000 ;        //    PWMEN2:0 = 100    > PWM0 to PWM5 pins enable for PWM output
                                    //    PMOD3:0 = 0000    > All PWM output Pair in "Complementary mode

        
PWMCON1 0b00000000 ;        //    SEVOPS3:0 =0000    > PWM Special Event Trigger Output Postscale = 1:1
                                    //    SEVTDIR = 0        > A Special Event Trigger occur when PWM Timebase is couting upward
                                    //    UDIS = 0        > Update from Duty Cycle and Period buffers are enables
                                    //    OSYNC = 0         > Output overrides via OVDCON register are asynchronous


        
OVDCOND 0b11111101 ;        //    POVD7:0 = 0        > All Output on PWM controlled by Duty Cycle
                                      //    register and PWM Time base
        
OVDCONS 0b11111111 ;

        
Int2Byte.Word 49 ;        //    PTPERH:L = 49        > Period will be 100uS when Fosc=16Mhz    
        
PTPERL     Int2Byte.Byte[0];
        
PTPERH     Int2Byte.Byte[1];

        
Set_DC(0,100);                //    Set Duty for PWM0,1 
        
Set_DC(1,150);                //     Set Duty for PWM2,3
        
Set_DC(2,0) ;                // Set Duty for PWM4,5
        
        
PTCON1bits.PTEN ;        // Finally , enable PWM

}

void    IO_Initialvoid )
{

    
TRISB &= 0b11000000 ;            // Set RB0 to RB5 as OUTPUT

}

void     Set_DCint DC_NO ,int    DC_Value )
{
        
Int2Byte.Word DC_Value ;

    switch(
DC_NO)
    {
        case 
:
            
PDC0L     Int2Byte.Byte[0] ;
            
PDC0H    Int2Byte.Byte[1] ;
            break ;

        case 
1:
            
PDC1L     Int2Byte.Byte[0] ;
            
PDC1H    Int2Byte.Byte[1] ;
            break ;

        case 
2:
            
PDC2L     Int2Byte.Byte[0] ;
            
PDC2H    Int2Byte.Byte[1] ;
            break ;
        
        default :
            break ;
    }
}


發表於: 2005/12/5 13:49
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請問各位前輩有關於18F4431的問題
#1
新會員
新會員


查看用戶資訊
各位前輩大家好:我用18F4431去做無刷馬達的控制,我有參考
網站上提供的18F4431的PWM範例程式去做。但我想要將PWM的週期改為20KHZ的時候總是無法達到,而且PWM的開度比例也無法去做調整,我找DATASHEET上的PWM頻率計算公式好像有將一個參數沒有定義,所以無法將實際控制頻率的暫存器值計算出來。我現在是用PWM0~PWM2這三個通道去做輸出,外部石英震盪頻率16MHZ。我想請問各位前輩在需求20KHZ的頻率的PWM訊號下,我需要去注意些什麼,在PWM開度的調整中我要去對應哪些暫存器的數據去做調整。謝謝各位前輩..

發表於: 2005/12/1 22:17
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... ]

教育訓練中心

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