Updating HPWM frequently, safe?


Results 1 to 40 of 79

Threaded View

  1. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    try this
    Code:
    <font color="#000000">        <font color="#008000">'
            '       Pic Configuration
            '       =================
            </font>@ __CONFIG _INTRC_OSC_NOCLKOUT &amp; _WDT_ON &amp; _PWRTE_ON &amp; _MCLRE_OFF &amp; _BOD_ON         
            
            <font color="#008000">'
            '       Hardware configuration
            '       ======================
                    '
                    '       I/Os
                    '       ----
            </font>TRISIO = %00010010        
                    <font color="#008000">'
                    '       ADC's
                    '       -----
            </font>ANSEL = %00000010  
            <font color="#000080">DEFINE </font>ADC_BITS 10     <font color="#008000">' ADCIN resolution  (Bits)
            </font><font color="#000080">DEFINE </font>ADC_CLOCK 1     <font color="#008000">' ADC clock source  (Fosc/8)
            </font><font color="#000080">DEFINE </font>ADC_SAMPLEUS 11 <font color="#008000">' ADC sampling time (uSec)                      
            </font>ADCON0.7 = 1           <font color="#008000">' Right justified results
         
                    '
                    '       Comparator
                    '       ----------
            </font>CMCON0 = 7             <font color="#008000">' Disable comparator
            </font>VRCON = 0              <font color="#008000">' CVreff = OFF
                    '
                    '       CCP
                    '       ---
                            '   PWM Freq=4KHz
                            '   Initial duty cycle set to 50%
                            '   PICMultiCalc says
                            '   10 Bit resolution when prescaler = 1:1
                            '   MAX duty value 1000
                            '   PR2 = 249
            </font>CCP1CON = %00001100     <font color="#008000">' PWM mode
            </font>PR2 = 249               <font color="#008000">'         
            </font>T2CON = %00000100       <font color="#008000">' Start Timer2, Prescaller 1:1
          
            '   
            '       Software variables
            '       ==================
            </font>Duty    <font color="#000080">VAR WORD
            
            </font><font color="#008000">'
            '       Software constants
            '       ==================
            </font>PWM_ON  <font color="#000080">CON </font>%00001100
            PWM_OFF <font color="#000080">CON </font>0
            
            <font color="#008000">'
            '       Software/Hardware initialisation
            '       ================================
            </font>GPIO = 0
            <font color="#000080">PAUSE </font>50    <font color="#008000">' OSC settle delay
            </font>Duty = 0
            <font color="#000080">GOSUB </font>SetPWMDuty
            
            <font color="#008000">'------------------------------&lt; Main program &gt;-----------------------------------
            '
    </font>Start:
            <font color="#000080">ADCIN </font>1,Duty                    <font color="#008000">' read pot
            </font><font color="#000080">IF </font>Duty&gt;1000 <font color="#000080">THEN </font>Duty =1000    <font color="#008000">' avoid results &gt;1000
            </font><font color="#000080">GOSUB </font>SetPWMDuty                <font color="#008000">' Set PWM duty cycles
            </font><font color="#000080">PAUSE </font>1                         <font color="#008000">' allow few PWM cycles
            </font><font color="#000080">GOTO </font>Start
            <font color="#008000">'
            '---------------------------------------------------------------------------------
    
            '-------------------------------&lt; Subroutines &gt;-----------------------------------
            '
    </font>SetPWMDuty:
            <font color="#008000">'       Datasheet recommend to stop PWM, load duty cycles vale
            '       to avoid possible glitches.
            '
                    '
                    '       stop PWM
                    '       --------
            </font>CCP1CON = PWM_OFF  
                    <font color="#008000">'
                    '       load Duty values
                    '       ----------------
            </font>CCPR1L = Duty &gt;&gt;2   
            CCP1CON.5 = Duty.1
            CCP1CON.4 = Duty.0
                    <font color="#008000">'
                    '       Start PWM
                    '       ---------
            </font>CCP1CON = CCP1CON | PWM_ON              
            <font color="#000080">RETURN
            </font><font color="#008000">'
            '---------------------------------------------------------------------------------
    </font>
    things to remember, disable the PWM mode, update the duty cycle, start PWM mode and allow few PWM freq cycle.. unless results could be weird.
    Last edited by mister_e; - 6th May 2007 at 02:14.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. need help on hpwm
    By helmut in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 15:49
  2. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:05
  3. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  4. HPWM and A to D interaction question 18F252
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th May 2006, 03:50
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts