Updating HPWM frequently, safe?


Closed Thread
Results 1 to 40 of 79

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    first you'll have to match the calc values to suit your need. With your current code example (which seems to be one of mine, the calc will give you...
    <IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1593&stc=1&d=117840872 7">

    look at this section of the code
    Code:
            duty = 52                           ' duty value for 50% duty cycle
            PR2 = 25                            '
            T2CON = %00000100                   ' timer2 on, prescale 1:1
            CCPR1L = duty>>2                    ' MSB of duty cycle value
            CCP1CON=%00001100 | (dUTY<<5)       ' set PWM mode and store the 
                                                '   2 LSB of duty
    52 is showned in the result section and it's to set the duty cycle to 50% as selected in the duty cyle section.

    Now if you want to update the duty cycle, you could use this section
    Code:
            CCPR1L = duty>>2                    ' MSB of duty cycle value
            CCP1CON=%00001100 | (dUTY<<5)       ' set PWM mode and store the 
                                                '   2 LSB of duty
    in your code you just need to change the value of Duty variable.

    The example was for a 16F877, you should have a look at the 12F683 to see if they work the same way.

    post your whole code, maybe some register need to be set in a different way. I'll put some effort and open my datasheet as well
    Attached Images Attached Images  
    Last edited by mister_e; - 6th May 2007 at 00:52.
    Steve

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

  2. #2
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    it seems we posted at the same time, yes the post I used is from an old post of yours I used for reference. Please read my last post and tell if if you have an idea that may help me. Thanks!

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


    Did you find this post helpful? Yes | No

    Default

    mm, you didn't disable the analog comparator.. maybe it worth to do it first?

    i'm about to do something here to see what's happen.
    Steve

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

  4. #4
    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.

  5. #5
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    post your whole code, maybe some register need to be set in a different way. I'll put some effort and open my datasheet as well
    mmm I oversought this statement, THANKS!, I will tidy it up a little, Im kinda messy compared to your code postings

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