12f683 variable HPWM and fixed pulse tick thickness


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2006
    Location
    North of France
    Posts
    18

    Question 12f683 variable HPWM and fixed pulse tick thickness

    Hello.

    I'm pretty sure someone already post something like I need.
    I did a very simple program to sweep a frequency from 900Hz to 12KHz (Code below)
    But, I need my pulse thickness to be fixed at 5µs everytime.

    With my code, I use duty in percentage so the thickness of the pulse change everytime.
    It's okay only when frequency reach 2KHz but it's too long before and too short after because I didn't took the right way to setup my HPM.
    Yes, I know my mistake and I know too I don't have enough knowledge about Timers I'm not very familiar with.
    Then, I'm stupidly looking for an example with "fixed pulse thickness".

    I did some search with many keywords but I didn't found what I need.

    Could someone give me a way to follow ?
    (And sorry for my bad English).

    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF
    
    TRISIO   = %000001
    OSCCON   = %01110000           ' 8Mhz
    ANSEL    = %001011             ' AN0 and AN1 and AN3 ANALOG
    ADCON0.7 = 1                   ' Right justify result      (Pour l'ADCin)
    CMCON0   = 7                   ' Analog comparators off    (Pour l'ADCin)
    
    '-------------------------------------------------------------------------------
    
    FREQmax         VAR WORD
    FREQmax         = 12000
    FREQmin         VAR WORD
    FREQmin         = 900
    HPWMfreq        VAR WORD
    HPWMfreq        = FREQmin      
    HPWMduty        VAR WORD
    HPWMduty        = 3           ' 1% = 3 à 100% = 254
    
    '-------------------------------------------------------------------------------                                                       
    
    Up              VAR BIT
    Up              = 1
    
    GPIO            = 0                         
    
    ;----[Main Program Loop]--------------------------------------------------------
    MAIN:
    
    HPWM 1, HPWMduty, HPWMfreq    ' Start HPWM
    
    PAUSE 10                      ' 10mS between each steps
    
    IF Up = 1 and HPWMfreq <= FREQmax THEN   'Going UP from 900 to 12KHz
    HPWMfreq = HPWMfreq + 1
    
    Else                         ' Here we are at freq maxi
    Up = 0
    
    ENDIF
    
    IF Up = 0 and HPWMfreq >= FREQmin THEN    'Going DOWN from 12K to 900Hz
    HPWMfreq = HPWMfreq - 1
    Else                         ' Here we are at freq mini
    Up = 1
    ENDIF
    
    IF HPWMfreq = FREQmin THEN 
    Boucle = Boucle + 1
    Toggle LED
    ENDIF
    
    GOTO Main
    
    '-------------------------------------------------------------------------------
    
        
    FIN:
        END

  2. #2
    Join Date
    Jan 2006
    Location
    North of France
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: 12f683 variable HPWM and fixed pulse tick thickness

    For those who could need it, i've just found (thanx to Excel) a basic mathematical solution by adding this simple calc :
    Code:
    HPWMduty = (500/(1/HPWMfreq*10000))*254/10000
    to recalculate each cycles the new duty.
    Not tested but it should be okay.
    Resolution could probably be better by another way...
    Last edited by RCtech; - 20th February 2015 at 01:29.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: 12f683 variable HPWM and fixed pulse tick thickness

    Hi,

    With the internal osc , even @ 8Mhz, HPWM definitly is not what to use ... so is pure basic ...

    with 10ms steps ... you'd better use PAUSEUS to generate the pulse ( need 16 Mhz ext osc ! ... or 8 asm NOP's @ 8Mhz ), and a timer to generate an interrupt every 10 ms that will change the pause beetween pulses ...

    see Darrel's Instant Interrupts for easy interrupts ...

    May be also a very very smart solution with the COMPARE mode of the CCP that can change the CCP outpin and set the CCPIF just when pause ends ...

    Alain
    Last edited by Acetronics2; - 20th February 2015 at 08:24.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: 12f683 variable HPWM and fixed pulse tick thickness

    One of many possible approaches. Here the way I have done this.

    First I generated my adjustable frequency using HPWM set to approximately 50% duty. Next I fed the output from CCP1 pin
    to Portb.0 pin. Using DT interupts "INT_INT" set to trigger on the rising edge of my pwm signal. In the ISR the output pin was toggled

    Basic concept
    Code:
    Setup HPWM
    Set INTCON to trigger on rising edge
    Main:
     Read Buttons or ADC
     Set HPWM Frequency
     Goto main
    
    
    Interupt Service Routine:
    gpio.x = 1
    pauseus 5
    gpio.x = 0
    INT_RETURN
    Not sure if you have enough pins using a 12f683 to do this and what ever else you need?

  5. #5
    Join Date
    Jan 2006
    Location
    North of France
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: 12f683 variable HPWM and fixed pulse tick thickness

    Thanx a little bit late for your both replies.
    Not as easy as I expected, I'll have to learn more and will start seeing Darrel's Instant Interrupts.

    ... and will be back again if I need help with these interrupts.

    Thank you.

Similar Threads

  1. Measuring a variable freq/length pulse and generating more pulses.
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 18th September 2014, 09:10
  2. AND HPWM with variable
    By dnyanesh in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th March 2013, 10:55
  3. Maximum HPWM freq. 12F683
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th August 2008, 15:55
  4. 12F683 HPWM Usage
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th November 2007, 02:16
  5. Time delay by incrementing a variable using incoming pulse
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 28th October 2005, 03:50

Members who have read this thread : 1

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