2 PWM in 16F690 problems


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2008
    Posts
    4

    Default 2 PWM in 16F690 problems

    I am working in a 2 DC motor control project. I'am making tests with the HPWM in a 16F690, but i'm having problems to generate 2 diferent signals... I generate without problems a PWM signal in the channel 1, but i can't drive a signal in the channel 2..

    I need to know if its possible to drive 2 diferrent dutty cycles in the channel 1 and 2, and how to do this.. I'am using Microcode studio and picbasic pro..

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


    Did you find this post helpful? Yes | No

    Default

    This PIC have only 1 CCP channel, which mean you can't use HPWM for more tha 1 channel. If you need another channel, there's serveral way to do it: Change your PIC for one having 2 CCP module, or keep the existing one but create a Timer interrupt based PWM, or do the same in a tight loop... but you will be limited to do anything else, or Darrel Taylor's Multi_SPWM routine ( http://www.pbpgroup.com/modules/wfse...p?articleid=12 ).

    Depending your DC moto spec.. the Timer based or else low frequency PWM may work... or not. HPWM will produce higher frequency and run in background.
    Last edited by mister_e; - 8th April 2008 at 03:53.
    Steve

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

  3. #3
    Join Date
    Apr 2008
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    Thankyou for your fast answer.. can you recommend me a mid range micro that can be used on this application?, dont you know if any dip 20 pin have 2 ccp modules? These will be a critical application so I need to do it with HPWM.. not with software..

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


    Did you find this post helpful? Yes | No

    Default

    As far as i remember, the smallest one with 2 CCP have 28 pins.
    Steve

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

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by ciendavila View Post
    Thankyou for your fast answer.. can you recommend me a mid range micro that can be used on this application?, dont you know if any dip 20 pin have 2 ccp modules? These will be a critical application so I need to do it with HPWM.. not with software..
    If you are willing to step up to the 18F family, I believe there are a couple of 18 pin options (e.g., 18F1230 and 18F1330).
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

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


    Did you find this post helpful? Yes | No

    Default

    problem with most single ECCP module is that you're restricted with only 1 duty cycle... but many output type, half-bridge, full-bridge etc etc.

    But yeah, Microchip have tons of PIC model, i just didn't found one Flash type with 2 CCP under 28 pins. Sure there's chance that i missed a couple of models.
    Last edited by mister_e; - 9th April 2008 at 01:42.
    Steve

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

  7. #7
    Join Date
    Apr 2008
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    I already find a solution, as you say 18F1330 looks like the best model for PWM aplications. It have 18 pins and ADC, perfect for my project, but the microcode doesnt works with it as well as the other micros, when you try to use the HPWM, many errors occur..

    I have been working on the project today, and finally it works, working directly with the registers, you can drive 3 different PWM at the time.

    Lets see how the ADC works and if i can finish my project without any other problem.

    Thankyou for all..

  8. #8
    Join Date
    Aug 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Hi.

    Did you get anywhere with the PWM code for the 18F1330?

    I don't think that you can use HPWM with this device as it's PWM module is completely different to the normal PWM module found in 16F chips. It requires many registers to be set manually.

    Am currently working on this, but experiencing problems...

    Andy

  9. #9
    Join Date
    Apr 2008
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Working with 18F1330 PWM

    You have to acces direct to the registers, and configure the internal OSC to work with it..
    The pwm duty cycle works with 14 bits, so you have to write directly the value on the PDC0L register for the less significant bits and the PDC0H for the more significant bits of the PWM 0 channel..

    I hope these can help you, if you download the datasheet you will understand more the code that I wrote.. These is part of the code of my program:

    OSCCON.6 = 1 'configure the internal oscilator to work at 4 MHz
    OSCCON.5 = 1
    OSCCON.4 = 0
    OSCCON.1 = 1

    PTCON0 = $00 ' configure frequency and the PWM sets
    PTCON1 = $C0
    PWMCON0 = $37
    PWMCON1 = 0
    PTPERL = $AA
    PTPERH = $01

    PDC0L = $FF ' Set the duty cycle for PWM 0
    PDC0H = $00
    PDC1L = $FF ' Set the duty cycle for PWM 1
    PDC1H = $01

  10. #10
    Join Date
    Aug 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Hi, thanks for the reply.. I got it working in the end.

    The thing that I was doing wrong was having a larger duty cycle value in PDC0L and PDC0H than the value in PTPERL and PTPERH. Since the PWM module counts upwards until it reaches the duty cycle value, and then continues to count upwards to the end of the frequency cycle as determined by the values in PTPERx registers, PDCxx must be lower than PTPERx.

    Thanks again,

    Andy

Similar Threads

  1. 12F683 2 x PWM Outputs
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 23rd July 2021, 20:20
  2. 16f877 generate pwm according 2 analog input
    By madxice in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th July 2009, 14:47
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Variable PWM on 2 Channels using software.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2006, 01:34

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