音影先锋亚洲天堂网|电影世界尽头的爱完整版播放|国产 熟女 91|高清无码免费观看欧美日韩|韩国一区二区三区黄色录像|美女亚洲加勒比在线|亚洲综合网 开心五月|7x成人在线入口|成人网站免费日韩毛片区|国产黄片?一级?二级?三级

登錄 免費注冊 首頁 | 行業(yè)黑名單 | 幫助
維庫電子市場網(wǎng)
技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng)
驅(qū)動編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機 | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計 | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe

請問張工:軟件模擬PWM?

作者:fineasy 欄目:單片機
請問張工:軟件模擬PWM?
產(chǎn)品選型時,不能用貴的MCU,但要有PWM功能(不很好也行),請問PIC是否有軟件模擬的PWM例程.多謝!

2樓: >>參與討論
martin
兩個軟件PWM例程
以前在網(wǎng)上找到的兩個軟件PWM的例程,32級和256級的,我沒有測試過,可參考其原理。
list    p=16C64,t=ON,c=132,n=80
        title   "An all SOFTWARE PWM with 32 states"
        radix   dec
;********************************************************************************
;
; T. Scott Dattalo
;
; 25APR97 - Initial version
;
;  The purpose of this program is to generate a PULSE Width Modulated
;square wave with SINGLE instruction cycle resolution. This version ONLY
;supports 32 PWM levels. 14 cycles are available every iteration for
;other tasks.
;
;  The algorithm is a state machine based on indirect goto's and tables.
;The 32 PWM levels are divided into 4 GROUPs of 8. For each GROUP,
;there are three states through which the state machine will pass. The
;states contain the addresses to where the goto's branch. The tables
;provide a convenient way to create a variable delay.
;
;  As an example, consider the execution sequence required to generate a
;10-cycle wide PULSE. The state initialization is:
;
;PW10    MOVLW   PULSE_on2off+7
;        MOVWF   state_3
;        MOVLW   variable_delay+1
;        MOVWF   state_1
;        MOVLW   pw9_16
;        MOVWF   state_2
;        nop
;        goto    pw9_16
;
;This puts the addresses of the start of the three tasks into the three
;state variables. Then code like this:
;
;        MOVF    state_n,W
;        MOVWF   PCL
;
; will branch to that state. The offsets added to the program lables
;provide the variable delay needed to adjust the PULSE width. For
;example, when the contents of state_3 are placed into PCL, execution
;will begin 7 instructions after the label 'PULSE_on2off'.
;
;  The sequence of execution for the PW10 PULSE is this:
;
;   PULSE_on2off+7  -> variable_delay+1  ->  pw9_16  ---+
; ^-------<-----------------<---------------------------|
;
;This sequence executes in exactly 32 cycles. On the 0'th the PWM
;OUTPUT is driven high and on the 10'th cycle it's driven low.
;The "0'th" cycle is 'BSF' instruction in the pw9_16 code segment.
;the 10'th cycle is the 'BCF' instruction in the PULSE_on2off code
;segment.
;

        include "P16C64.INC"
  __CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF& _HS_OSC

START_OF_RAM_LO equ  0x20
END_OF_RAM_LO   equ  0x7f
START_OF_RAM_HI equ  0xa0
END_OF_RAM_HI   equ  0xbf


;***********************************************************************
;PWM Equates

PWM_PORT        EQU  PORTA
PWM_BIT         EQU  0


  cblock  START_OF_RAM_LO

    state_1,state_2,state_3

  endc

;***********************************************************************
        ORG     0               ;Reset Vector

        GOTO    Main


;***********************************************************************

    ;This segment will drive the PWM OUTPUT high (or KEEP it high if it
    ;was driven earlier) and then 1 to 8 cycles later drive it low. It then
    ;branches to the address contained in state_1.
PULSE_on2off
        BSF     PWM_PORT,PWM_BIT
        BSF     PWM_PORT,PWM_BIT
        BSF     PWM_PORT,PWM_BIT
        BSF     PWM_PORT,PWM_BIT
        BSF     PWM_PORT,PWM_BIT
        BSF     PWM_PORT,PWM_BIT
        BSF     PWM_PORT,PWM_BIT
        BSF     PWM_PORT,PWM_BIT

        BCF     PWM_PORT,PWM_BIT
        MOVF    state_1,W
        MOVWF   PCL


    ;This segment will drive the PWM OUTPUT low (or KEEP it low if it
    ;was driven earlier) and then 1 to 8 cycles later drive it high. It then
    ;branches to the address contained in state_1.
PULSE_off2on
        BCF     PWM_PORT,PWM_BIT
        BCF     PWM_PORT,PWM_BIT
        BCF     PWM_PORT,PWM_BIT
        BCF     PWM_PORT,PWM_BIT
        BCF     PWM_PORT,PWM_BIT
        BCF     PWM_PORT,PWM_BIT
        BCF     PWM_PORT,PWM_BIT
        BCF     PWM_PORT,PWM_BIT

        BSF     PWM_PORT,PWM_BIT
        NOP
        MOVF    state_1,W
        MOVWF   PCL


variable_delay
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP

        MOVF    state_2,W
        MOVWF   PCL


delay16         ;(actually, a delay of 17 cycles...)

        goto    $+1             ;These 14 free cycles will be executed
        goto&nb
3樓: >>參與討論
fineasy
謝謝了!martin!
 
參與討論
昵稱:
討論內(nèi)容:
 
 
相關(guān)帖子
關(guān)于程序頁面0和頁面1,造成程序亂跳!請教張工和各位高手!
我發(fā)現(xiàn)了一個好軟件
求助:ds1302程序問題
PIC單片機通訊例程(2)---雙機同步通訊
恭喜張工成功獨享江蘇分時表
免費注冊為維庫電子開發(fā)網(wǎng)會員,參與電子工程師社區(qū)討論,點此進(jìn)入


Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號