hpwm more than 2 ch possible in pbp?????????


Closed Thread
Results 1 to 21 of 21
  1. #1
    oscar's Avatar
    oscar Guest

    Unhappy hpwm more than 2 ch possible in pbp?????????

    i am wondering if it is at all possible to have more than 2 ch of hpwm within pbp????????????? i am using a pic16f767 with 3 hpwn chs yet i can only seem to get 2 running?? ch 2 seems to be mixed/ shared with ch 3 for some reason.. ie ccp1 is fine but when i write a value to ccp2 it shows up on ccp3!!!!!!! im boggled.. i have tryed all the possible reg configs i can think of yet still no joy... has anyone got any pointers??? i am totally stuck here !! lol.

    thank you
    oscar..

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    i am wondering if it is at all possible to have more than 2 ch of hpwm
    within pbp?


    Nope. The HPWM command only supports 2 channels. CCP1 & CCP2. You
    would need to modify the 16F library to support CCP3. It's much easier to
    just configure hardware PWM manually.

    From the examples in your 16F767 datasheet;

    Setup 10-bit PWM for 1.22kHz with a 20MHz osc.

    ' Word vars for 10-bit value of each PWM duty cycle
    Duty1 VAR WORD ' Channel #1
    Duty2 VAR WORD ' #2
    Duty3 VAR WORD ' #3

    ' Set CCPx pins to outputs
    TRISC.2=0 ' CCP1 output
    TRISC.1=0 ' CCP2 output (could also be assigned to RB3)
    TRISB.5=0 ' CCP3 output

    ' Set CCP modules to PWM mode
    CCP1CON = %00001100 ' Mode select = PWM
    CCP2CON = %00001100 ' Mode select = PWM
    CCP3CON = %00001100 ' Mode select = PWM

    ' Set period up for 1.22kHz PWM freq
    PR2 = $FF

    ' Set TMR2 up for 1:16 prescale & turn it on
    T2CON = %00000110 ' TMR2 ON 1:16 prescale

    Duty1 = 512 ' 50% duty cycle. 1024/2 "10-bit resolution"
    CCP1CON.4 = Duty1.0 ' Setup 10-bit duty cycle as
    CCP1CON.5 = Duty1.1 ' a 10-bit word
    CCPR1L = Duty1 >> 2

    Duty2 = 512
    CCP2CON.4 = Duty2.0
    CCP2CON.5 = Duty2.1
    CCPR2L = Duty2 >> 2

    Duty3 = 512
    CCP3CON.4 = Duty3.0
    CCP3CON.5 = Duty3.1
    CCPR3L = Duty3 >> 2

    You have the same frequency on all three channels since all three channels
    share the same period register, but you have individual control of duty cycle
    on each channel using the corresponding CCPRxL & CCPxCON registers.

    With 10-bit resolution you can have from 0-1023 or 0%-100% duty cycles.

    Pretty simple don't you think?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    oscar's Avatar
    oscar Guest


    Did you find this post helpful? Yes | No

    Angry ccp3 dont exist????

    hi bruce, thanx for your reply.

    i have tryed in vain to get your code working cos when i try to compile it it says the following..

    error hwpm.asm 'ie name of project


    undefined symbol ccp3con


    it wont recognise the ccp3con setup for some reason.....

    hence it wont compile.!!

    i had another look at the pbp manual and its very misleading re hpwm as it makes referance to hpwm3 etc yet it does not state that a max of 2 x hpwm are available in pbp!!!! so one would assume that the ref to hpwm3 etc would mean it could use any available hpwm port on a particular chip !!!!!! arrrgggggggggggggggg

    oscar

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    A few things to look for;

    Never save your basic code file with the exact same name as a PBP
    command, or the same name as the PIC target.

    Try saving it with a name like PWM_F767.bas or something. It compiles
    fine for me with PM or MPASM assemblers with PBP v2.46.

    Be sure you're selecting the 16F767 before compiling, you have a version
    of PBP that supports this device (at least v2.45), and if you're using MPASM
    make sure you have a version of MPASM that supports this PIC.

    Some of the older 17C7xx PIC's had channel 3 which could use timer1. The
    PBP define in the manual shows how to assign timer1 to this channel instead
    of timer2. There are also defines to assign different pins to CCP outputs, but
    I don't see anything in the PBPPIC14.LIB file for the HPWM command that will
    support more than CCP1 & CCP2.

    I don't have one of the 16F767's to mess with, but that code example should
    work assuming you have a version that supports this PIC, you're saving your
    basic file with a name that doesn't clash with a PBP command, and you have
    all the device header files required for this target.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    oscar's Avatar
    oscar Guest


    Did you find this post helpful? Yes | No

    Red face oops my mistake...........

    im so duhhhhhhhhhh.. lol the no ccp3 mystery is sloved... i somehow had another chip type selected!!!!!

    question.... would their be any reason with the code u gave me bruce as to why ch2 hpwm2 that is flickers when at a low value?


    thanx

    oscar

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    What exactly do you mean by flicker?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    is this LED flickering happen only with channel2 ? what about if you change the frequency?
    Steve

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

  8. #8
    oscar's Avatar
    oscar Guest


    Did you find this post helpful? Yes | No

    Default re flicker

    hiya lads...

    hmmmmm ch3 ie the one i couldnt get to work in the firsr place works 100% nice smooth dimming etc.. ch2 flickers like mad !! the code is the exact same for all 3 ch's with the exception of register names etc.

    me thinks this is not possible...................... i have gone through everything here 10 times over.!!!

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    What happens if you enable only 1 channel at a time?

    I.E. CCP1CON=0 : CCP3CON=0

    Does channel 2 still flicker?

    Are you sure it's not the circuit channel 2 is connected
    to that's causing the flicker?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  10. #10
    oscar's Avatar
    oscar Guest


    Did you find this post helpful? Yes | No

    Default found the problem

    yet again tis me thats at fault.... many thanx to bruce for his code example. the mistake i was making was that i was calling the hpwm routine which seemed to be causing a conflict. instead i just wrote the duty val directly to the port ie portb.5=duty5 ... simple! lol this took many hours of hair loss and alcohol !!!!!!. only 1 teeny weeny prob left lol... i cant get the ch's to go to full off . they get to say 9% and stay there. so a faint glow is visible but apart from that everything is aok. dimming is as smooth as a babys ass and im a happy bunny.( irish saying).. many many thanks to bruce n the rest of u guys.. slainte...

    thanx
    oscar.

  11. #11
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Im refloating this thread because I have a question:

    I tried the example provided by Bruce succesfully, but now I want to use ON Interrupt on portb changes.

    The problem I encounter is that CCP3 uses RB5 and the interrupt is triggered by changes in the portb.4 to portb.7

    What can be done?

    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Help us a litle bit Pic model?

    How bad/good it is if in the INT routine you test the PORTB and if it's just related to the HPWM, it goes out of there ?
    Steve

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

  13. #13
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Sorry Im using the same pic as Bruce example: 16F767

    but Im having more basic problems, when I wasnt able to run the program as desired I started to remove parts of it, and now I see it does not work at all, so I may be missing some register configuration.

    Here is the header of my program:


    Code:
    @ device pic16F767, wdt_on, intrc_osc_noclkout, mclr_off, protect_off
    
    
    trisb   =%11000000
    trisa   =%00000001
    cmcon   =%00000111  'Comparators Off
    intcon  =%10001000  'interrupts enable    
    
    ; Set CCP modules to PWM mode
    CCP1CON = %00001100 ' Mode select = PWM
    CCP2CON = %00001100 ' Mode select = PWM
    CCP3CON = %00001100 ' Mode select = PWM
    
    PR2 = $20    ; Set period 
    
    pie2.1=0    ;disable interrupts on CCP3 (I think this should work)
    
    ; Set TMR2 up for 1:1 prescale & turn it on
    T2CON = %00000100 ' TMR2 ON 1:1 prescale
    
    porta=0:portb=0:portc=0
    
    pause 100
    
    
    high porta.1
    pause 200
    low porta.1
    pause 200
    high porta.1
    pause 200
    low porta.1
    
    end
    As you can see very basic, and I dont even started with the pwm/interrupts stuff.

    I program the pic via ICSP and power it, it seems to run at turtle speed , the 200ms pause takes 28seconds...


    What I am missing? Thanks

  14. #14
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by peu
    I program the pic via ICSP and power it, it seems to run at turtle speed , the 200ms pause takes 28seconds...


    What I am missing? Thanks

    What is about a DEFINE OSC ?
    At what speed does the PIC work ?
    What speed did you tell the PBP-Compiler ?

    ;-)
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  15. #15
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Oh I didnt post it in my previous post sorry, there is a define osc 4 below the @device statement

    but it still goes slow...


    Pablo

  16. #16
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    any idea? Thanks

  17. #17
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    I could use some help Thanks in Advance

  18. #18
    Join Date
    Jan 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    This seems to be a very popular comment. Bruce mentioned that you could modify the 16F library to accomodate for the 3rd HPWM channel. Could any of the advanced members take on this project and post the library? Seems that it would solve many repeat posts for the same problem.

  19. #19
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by docwisdom
    This seems to be a very popular comment. Bruce mentioned that you could modify the 16F library to accomodate for the 3rd HPWM channel. Could any of the advanced members take on this project and post the library? Seems that it would solve many repeat posts for the same problem.

    If someone has just a tip on what to look, I will really appreciate it. Thanks!

  20. #20
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Clicked two times sorry

    The post is the next one
    Last edited by sougata; - 10th March 2006 at 07:33. Reason: Double post

  21. #21
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Sneek into PBPPIC14.LIB in your PBP folder

    Hi,

    That's the library bruce was talking about. This contains the PBP function which is used by the compiler to extract and create codes and fits into the target processor. So portions only needed by your code are compiled according to PIC and placed in the top part of your compiled prog.

    The problem with the HWPM command is that it calculates the PR2 (Freq) and CCP1CON + CCPCON (Duty Cycle) every time you use it in your code. That's the reason why changes do not take place immediately. So it is always a better idea to modify the duty cycle registers directly. To make life easy use the HPWM once then go on varying the duty cycle yourself. Depending on the PR2 values (read the datasheet for the Math) you should have a limit on the max duty cycle value to ensure smooth rollover.

    It was Bruce's code found in a thread which gave me the wayout. Thanks bruce. I should have thanked you much earlier for showing the path.

    I do not have a chip lying around that has 3 channels HPWM. I would sure like to give a try modifying the library. No commitments however (My firm is a design house and basically one man army on the development front!!!)
    Regards

    Sougata

Similar Threads

  1. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:05
  2. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  3. Replies: 2
    Last Post: - 10th July 2006, 01:05
  4. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  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 : 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