HPWM10 Frequency Updating


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146

    Default HPWM10 Frequency Updating

    Hi

    This week I are been mostly working on HWPM.......... to produce undetermined fixed frequencies on CCP1 between approx 10,000Hz and 500,000Hz for durations of approx 10 seconds. For the moment the dutycycle is a secondary consideration. I am testing using a 16f628A at the moment but I may have to change to an 18 series. It must use HPWM

    As this is a broad range and to achieve better resolution at the higher frequencies I am running at 16mhz and introducing prescaling at the lower frequencies.

    The frequency required is received HSER as a WORD and the code calculates PR2 etc. My own code sort of works Ok but it is very ugly and limited ( I upgraded to 2.5 to use LONGS etc but have yet to been unable to get PBL to compile with anything significant )


    However,

    I have also had an constant eye on HPWM10 By Darrell Taylor (Peu and Mister E whose Pic multi-Calc I use as de facto: thankyou Mister E) considering that I may have certain frequency ranges dedicated to different channels.

    HPWM10 works beautifully to update the dutycycle of given frequencies, smooth and glitch free and very easy to use. However I would be using it the other way round ie to update the frequency for a given dutycycle. Given the fact that 10Bit resolution is not always available over the ranges I am working with, I set the variable _DutyCycle = 100.

    There are stages in my frequency range when the BYTE value of PR2 overflows and the prescaler is incremented. For the purpose of this post I have the prescaler set 1:1

    A bit long winded but I have captured the value of PR2 with respect to frequency as output from HPWM10 and inconsistencies start to occur around 35940Hz , PR2 recovers at 36140Hz but as can be seen in capture1.txt the trend occurs more regularly thereafter. The inconsistencies are as compared to Mister E's Pic multi-Calc.

    I should be able to work out why this is happening rather than just observing, however I am confused......... could this be to do with parsing during the maths calculation?

    Duncan
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I don't know if it will help you, but some time ago I wrote a little routine for an 18F8722 running at either 20 or 40Mhz that lets you enter the PWM frequency and then increment and decrement the duty cycle with the UP and DOWN arrow keys on a keyboard.

    It doensn't allow for infinite frequencies, but is a good test tool.

    <CODE>

    HSEROUT [13,10,10,"1. Test PWM ",13,10]



    HSEROUT [13,REP 10\4]
    HSEROUT ["Pick PWM Frequency 1 = 312Khz,2 = 156Khz, 3 = 78Khz, 4 = 39Khz "]
    HSERin [Char]
    IF Char < "1" or Char > "4" THEN
    HSEROUT [13,10,10]
    GOTO SpecialUse
    ENDIF

    IF Mhz40 = 1 THEN
    Select CASE Char

    CASE "1"
    PWMFREQ = $1F
    NumBits = 7
    MaxPWM = 127

    CASE "2"
    PWMFREQ = $3F
    NumBits = 8
    MaxPWM = 255

    CASE "3"
    PWMFREQ = $7F
    NumBits = 9
    MaxPWM = 511

    CASE "4"
    PWMFREQ = $FF
    NumBits = 10
    MaxPWM = 1023
    END SELECT

    ELSE
    Select CASE Char

    CASE "1"
    PWMFREQ = $F
    NumBits = 6
    MaxPWM = 63

    CASE "2"
    PWMFREQ = $1F
    NumBits = 7
    MaxPWM = 127

    CASE "3"
    PWMFREQ = $3F
    NumBits = 8
    MaxPWM = 255

    CASE "4"
    PWMFREQ = $7F
    NumBits = 9
    maxPWM = 511
    END SELECT
    ENDIF


    CCP1CON = %00001100
    CCPR1L = %00010000
    CCPR1H = %00000000 ' Initialize to 0, PWM register
    PR2 = PWMFREQ
    T2CON = %00000100 ' Prescale 1, Timer2 ON - Needed for PWM
    PORTC.2 = 0
    TRISC.2 = 0
    PWMVal = 0
    Gosub WritePWMreg
    HSEROUT [13,10,10]

    HSEROUT ["PWM Value (",#MaxPWM," Max)",13,10]
    HSEROUT ["0",8]
    NewChar:
    HSERIN [Char]
    If Char = 27 THEN
    HSERIN 50,NoArrow,[Char2,Char3]
    IF Char3 = 65 AND PWMVal < MaxPWM tHEN
    PwmVal = PWMVal + 1
    ENDIF
    IF Char3 = 66 AND PWMVal > 0 tHEN
    PwmVal = PWMVal - 1
    ENDIF
    HSEROUT [#PWMVal," ",REP 8\7]
    GOSUB WritePWMReg
    ENDIF

    goto NewChar
    NoArrow:
    Break = 1
    PWMVal = 0
    Gosub WritePWMReg
    CCP1CON = 0 ; Shut off the PWM controller
    GOTO Begin



    WritePWMReg:
    CCPR1L = PWMVal >> 2
    CCP1CON.5=PWMVal.1
    CCP1CON.4=PWMVal.0
    RETURN

    </CODE>
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Hi Duncan,

    I'm not sure how you're getting frequencies between 10,000 and 500,000 in a word var, but for sure, the HPWM10 macro will have problems with frequencies greater than 32,767.

    The calculation from frequency to TimerTicks uses the DIV32 command, and the Divisor has a 15-bit maximum (32,767). The limitation is the same for PBP's HPWM.

    Since you have PBPL, it's possible to modify the macro to use LONG's.
    Then it won't have the DIV32 problem anymore.

    But if you're having problems getting PBPL to work. That may not help out either.
    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default HPWM10 macro

    I need a ten bit HPWM so I searched for "HPWM10 macro" as mentioned in the prior post.

    No joy.

    Here is the error message.........

    Did you mean: HPM 10 macro

    No standard web pages containing all your search terms were found.

    Your search - HPWM10 macro - did not match any documents.

    Suggestions:
    Make sure all words are spelled correctly.
    Try different keywords.
    Try more general keywords.
    Try fewer keywords..........

    Where can I find a 10 bit HPWM command?

    Cheers
    BrianT

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


    Did you find this post helpful? Yes | No

    Default

    I'd like to be able to explain the search engines..... but I can't.

    Good thing there's People around.

    https://www.picbasic.co.uk/forum/showthread.php?p=37805
    <br>
    DT

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    The code that I posted does a 10bit HPWM.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    The code that I posted does a 10bit HPWM.
    Glitch Free to 500khz ?

    Yeah, mine neither.
    <br>
    DT

Similar Threads

  1. Advice on frequency measurement to 30MHz
    By Andy Wood in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th March 2009, 04:23
  2. HPWM command and oscillator frequency
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2009, 22:41
  3. inaccurate frequency using TMR1 PI18F452
    By nkarpovich in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 14th October 2006, 16:22
  4. frequency measurement
    By big-x in forum General
    Replies: 2
    Last Post: - 25th November 2005, 00:53
  5. Low frequency output
    By barkerben in forum General
    Replies: 5
    Last Post: - 16th November 2004, 15:25

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