trying to use the HPWM command


Closed Thread
Results 1 to 5 of 5
  1. #1
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest

    Default trying to use the HPWM command

    I have been reading up on this and finding that everybody has there two cents to this. The code to follow is what I assume to use:

    ' I am using this program to see if I can get a PWM to work on channel 1
    CMCON = 7 ' Turns the Ports to Digital
    TRISB = 0
    pause 500
    loop:
    HPWM 1,128,721 'This command is to try and get the PWM to modulate.
    goto loop

    But the thing to it is that I am not getting anything to work. I would like to use this for something more complex of course and I thought that if I could generate frequencies between 700 and 750 I would be good, but I can not even get one out of that range to work. The pic that I am using is the 16f648a and I have changed it out frequently to get nothing. is there any help out there.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Rhatidbwoy,

    PBP assumes that the CCP1 port is on PORTC.2, but on the 648A it's on PORTB.3

    You can correct for this with ...
    DEFINE CCP1_REG PORTB
    DEFINE CCP1_BIT 3

    However, since you had already set PORTB to all output's, that will not solve the problem.

    You didn't mention what Oscillator freq you are using, but if it's more than 10mhz, you won't be able to get that low of frequency out of the CCP. For instance, at 20mhz, 1221hz is the minimum.
    <br>
    DT

  3. #3
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    I am using the internal osc. That is 4MHz. The funny thing to the whole is that I thought since I have to put 16f648a in MCStudio that would have changed this little delema that I have with the port, but I guess wrong.

    I will have to try that and see if it works. It should because I have seen this setup before.

    For the code below, what is the meaning to all of this. I do not get the PR2 = 49 making this 40k for the PWM period. What is the calculation and also this must be based to xtal size.

    'register setup (this is for a 16F684, so it may need to be modified slightly for your chip)

    PR2 = 49 'PWM Period 40K=49
    CCPR1L = 10 'PWM Duty Cycle
    T2CON = 4 'Timer2 = ON; Prescale = 1:1
    CCP1CON = 0 'PWM module off

  4. #4
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    All the terminology is very well defined in the manual for each chip. You should look at the appropriate chapters for the CCP module under the PWM section. This should help you configure the CCP modules properly.

    Here is an example :
    for the PIC16F777 Since there are 3 pwm pins available for programmers to use:

    Step1: make sure that the each pins are configured correctly, (INPUT/OUTPUT)

    Step2:
    Set the PR2 Value: This will depend on the oscillator speed and the desired frequency you want to run your pwm channels your duty cycle is 4x the PR2 value. if you want your pwm to go from 0% to 100% in 255 steps, than your pr2 value must be 64. because 64X4 = 255.

    Step3: Make sure that you are storing the value for the duty cycle in the appropriate CCPRxL (x represnts the CCP channel you are using 1, 2, or 3)


    If you are still confused there is a equation in the Manual under the CCP section that explains everything in more details of what I just mentioned here. So refer to this please. I basically summarized what steps you need to take. to fulfill this.

    if you are stuck, respoond here with a snip of your code and we can work something out for you.

    Srig

  5. #5
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    ok I think that clarifies everything. I was more looking to understand that of the HPWM because that is simple enough and works for hte application that I want to use it for.

    I just wanted to learn more on the other method that I was talking about earlier were I did the setup myself and have the chip do what it can do for that higher freq. So in most part I can setup anything that I want to do in base of what xtal I am using for my timing sequence for the micro controller. So for 4MHz the time base I would use is 1/4MHz for that base time right?

Similar Threads

  1. My code for TV remote and MIBAM for RGB control
    By idtat in forum Code Examples
    Replies: 4
    Last Post: - 12th January 2013, 20:52
  2. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  3. HPWM command and oscillator frequency
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2009, 22:41
  4. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 18:57
  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