Updating HPWM frequently, safe?


Closed Thread
Results 1 to 40 of 79

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32


    Did you find this post helpful? Yes | No

    Default 10 bit HPWM command on both CCP modules

    Hello,

    I would have two different frequency on CCP1 and CCP2 pin the first is 100HZ and second is 20Khz-40KHz. I use 1MHz quartz for clock and HPWM10 command from D.T. I use PIC16F876.
    I have on both CCP pin HPWM10 command with frequency 100hz and different duty. This working ok. When changed frequency on CCP1 to 1KHz then is frequency on both pin unchanged and very unstable
    When change one HPWM10 command to normal 8 bit HPWM then stay result unchanged.
    what I did wrong?

    here is first part of my program:




    INCLUDE "ALLDIGITAL.pbp"

    Cifra var byte
    Cifra1 var byte
    Maska1 var byte
    Maska2 var byte
    W var byte
    i var byte
    time var byte
    PR var byte
    VU var word
    VD var word
    Duty VAR word
    Duty1 VAR word
    FREQUENCY var word
    FREQUENCY1 var word

    LED var PORTC.4
    LEDDis1 var PORTA.0
    LEDDis2 var PORTA.1
    tipka1 var porta.2
    tipka2 var porta.3
    tipka3 var porta.4
    BUZ var porta.5
    enable1 var portc.0
    b0 var byte
    b1 var byte
    b2 var byte
    b3 var byte
    impulz var WORD
    minuta var byte
    key var byte
    pavza var word

    bp var byte

    TRISA=%11111100
    TRISB=%00000000
    TRISC=%00000000


    clear
    include "HPWM10.pbp"
    LOW PORTC.1
    LOW PORTC.2
    PWM_ON CON %00001100
    PWM_OFF CON 0
    time=6
    FREQUENCY=93 '
    FREQUENCY1=1000
    low led
    gosub zvok
    eeprom 0,[31]
    eeprom 2,[55]
    high enable1
    high led
    pause 100
    low led




    INTCON = %00100000
    OPTION_REG = %10001000

    On Interrupt Goto ISR
    INTCON = %10100000
    w=0


    Main:

    gosub tipka
    gosub timing
    read 0,b2
    gosub tpwm
    @ HPWM10 2,_IMPULZ,_FREQUENCY
    read 2,b0
    gosub ppwm
    @ HPWM10 1,_duty,_FREQUENCY1
    Gosub Priprava
    goto Main

    ppwm: b1=b0-50
    lookup2 b1,[100,200,300,400,500,600,700,800,900,1000],duty
    return

    tpwm: b3=b2-30
    lookup b3,[0,31,16,6,21,46],duty1
    return

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    With 16F876's, both CCP modules use the same Timer in PWM mode (TMR2).
    If you change the frequency of one, the other one changes too.

    With a 4 Mhz crystal, the minimum HPWM frequency is 245 Hz.
    Since you are using a 1 Mhz crystal, you can get down to 62 Hz, but you have to specify the frequency as if it were running at 4 Mhz.

    If you want 100 Hz, then specify 400 Hz in the HPWM10 command.
    93 is way below the minimum.
    <br>
    DT

  3. #3
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Frequency of 100 Hz is not a problem. In the case that I use PIC16F886 asking whether the command HPWM10 set timer TMR1 and TMR2 for each channel?
    Can you write the registry settings for the PIC16F886?

    tnx
    Samo

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Even on a PIC16F887, the CCP modules can only use Timer2 in PWM mode.
    So both PWM channels will operate at the same frequency.

    So I guess the answer to your question is ...
    HPWM10 only changes Timer2, not Timer1.
    <br>
    DT

  5. #5
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Whats required to have 'glitch free' operation but with 8 bit PWM, can the include file be easily modified for 8 bit, or should i just multiply my desired 8 bit dutycycle by 4?

  6. #6
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Also, just testing on 16F887, at 4mhz,

    @ HPWM10 1,_OUTDUTY,300 results in a PWM frequency of 10khz according to my o'scope ???
    I see the duty cycle changing, but the freq is around 9-10khz?

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The frequency must be a variable.
    You can't pass a constant as the parameter.

    And just shift left 2 (<<2) to use 8-bit values.

    hth,
    DT

Similar Threads

  1. need help on hpwm
    By helmut in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 16:49
  2. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 16:05
  3. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 15: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, 04:50
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 03: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