Menu

HPWM issues with 16f1825 and 16f1829

Help
2015-04-19
2015-04-21
  • tony golding

    tony golding - 2015-04-19

    i have recently been playing with a couple of different chips and have noticed an issue when using HPWM with the following code

     #chip 16F1829, 8
    
     dir PORTC.5 out  'hpwm1   'chip ccp1
     dir PORTC.3 out  'hpwm2   'chip ccp2
    
     do
    
      hpwm 1, 5, 127
      wait 500 ms
    
      hpwm 2, 5, 127
      wait 500 ms
    
      pwmoff
      wait 500 ms
    
     loop
    

    now the strange thing is that regardless of whether i use a pic12f1825 or pic12f1829 the pwmoff does not stop/turn off the hpwm2 output on pin RC.3 on either chip type.

    i can adjust its value up or down with no problems but when it comes to issuing a pwmoff command the hpwm1 will turn off but the hpwm2 will still stay on no matter what.

    i thought i had damaged my chip somehow so changed from a 12f1825 to a 12f1829 and still get the same behaviour.

    incidentally enough though if i just use hpwm1 and then use the pwm steering i can output the modulated hpwm1 signal on to pinRC.3 with no problems with the pwmoff command as the hpwm1 works fine but now im baffled as to why hpwm2 will not.

    also as this chip has ccp1-ccp4 can i use 4 different hpwmxx commands to get at each of them or is the gcb command only allowing the 1 or 2 as stated in the help files.

    thanks,

    tony

     

    Last edit: tony golding 2015-04-19
  • Anobium

    Anobium - 2015-04-19

    Tony, Can you confirm your release date of GCB?

     
  • tony golding

    tony golding - 2015-04-19

    darn it, i did download the hew release but yet to use it, ok ill swap over and report back, thanks evan :P

    tony

     
  • tony golding

    tony golding - 2015-04-19

    ok newer pwm.h file downloaded and copied into folder,

    but now when i build the hex it says INITpwm has not been defined,i have never used any command like that before when using hpwm.

    tony

     
  • tony golding

    tony golding - 2015-04-19

    tried compiling and running with newer gcb@syn release and still getting no change from hpwm2/ccp2, it just stays lit after a pwmoff command.

    tony

     
  • tony golding

    tony golding - 2015-04-19

    ok im very proud of myself as i have fixed it and now have all 4 ccp modules operating and switching off with the pwmoff command.

    after being brave and looking at the pwm.h file i noticed that pwmoff only included ccp1con=0, so adding the same command for the other 3 channels worked there and hpwm2 now responds along with hpwm3.

    there were only 3 hpwm settings in the file so after adding another set of the setting for the appropriate ccp4 ccpxcon registers it now is also working.

    i am pleased that i was able to be brave and tackle this fix and i have to say i am really enjoying the ability to tweak things with the compiler to get chip functions/features working as needed,

    so after all night of thinking i had blown my chips port somehow im happy to see it still lives for more abuse, at least the breadboard wiring got pulled and tidied up looking for problems their lol

     
  • Anobium

    Anobium - 2015-04-20

    Thank you for being brave. :-)

    You have added to Great Cow Basic! We need more like you! :-)

    I have posted to the committed code and added you name to the contributors pmw.h

    See https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/pwm.h

     
  • tony golding

    tony golding - 2015-04-20

    wow im glad i got it right lol, but thanks, its good to have actually contributed to something for once as opposed to needing help.

    your earlier post of the updated file gave my curiosity just enough of a nudge to look into it further after it still didnt work, but it was a worthwhile effort and im glad it came out correct, even though i dont need all 4 pwm at once it would have bothered me otherwise lol.

    but i am happy to hear that its been added, that adds to the happy feeling of getting it working lol thank you.

    tony

     
  • William Roth

    William Roth - 2015-04-20

    PWMOff and PWMOn were not really designed to turn on/ off all 4 PWM channels at once. What if you have 3 active pwms and only want to turn off PWM 2?

    PWMON/PWMOff are complementary commands designed as a way to toggle PWM on/off on a single CCP module (CCP1) to generate modulated PWM. PWMOFF was not intended to turn off ALL HPWM channels at once.

    To turn OFF an individual HPWM channel eg HPWM2. Simply set the duty cycle to zero. In Tony's code to turn off both channels:

        hpwm 1, 5, 0
        hpwm 2, 5, 0
    

    If we want to disable the CCP module and make the PIN a normal I/O then we need add a feature such as "HPWM x, OFF" to disable individual PWM channel(s)

    While I applaud Tony's work on this, I am not so sure that this change is appropriate.

     

    Last edit: William Roth 2015-04-20
  • Anobium

    Anobium - 2015-04-20

    @William. You are right. I should have asked you before I posted. :-)

    Should we/could we add the following to resolve? (code not tested)

    sub HPWMOFF (optional In PWMChannel = 0 )
    
        select case PWMChannel 
            case 1:     CCP1CON = 0
            case 2:     CCP2CON = 0
            case 3:     CCP3CON = 0
            case 4:     CCP4CON = 0
            case else
                CCP1CON = 0
                CCP2CON = 0
                CCP3CON = 0
                CCP4CON = 0
        end select
    end sub
    
     
  • Hugh Considine

    Hugh Considine - 2015-04-20

    On the PWMOn and PWMOff issue, these have always affected only one channel, and should stay this way for compatibility. (Suppose that someone already has a program that uses PWMOn/Off for channel 1, and HPWM to control channel 2 independently of this? We don't want to suddenly start turning off their channel 2 for no obvious reason when they install an update!) For controlling the other channels, we already have HPWM. Does adding another way to turn these channels on and off make things simpler or more complicated? I'll leave that up to others to decide.

    If the solution is to create a new version of PWMOn/PWMOff that can be used to control other channels, best to implement this as a new subroutine with a compulsory parameter for the channel. Then, the compiler can use overloading to call the new sub if a channel is given, or the old one if it isn't. Again, this helps with compatibility, won't suddenly increase the size of the user's program unless they use the new features.

    And also, don't forget the #ifdef Var(CCP2CON) lines. Without those, if the code runs on a chip with only 1 channel, the compiler will create variables for CCP2CON, CCP3CON and CCP4CON, and that will waste memory.

    (And Tony, thanks for bringing up the issue and posting the code! It's useful and will no doubt end up getting used, we might just have to tweak it a bit more here and there!)

     
  • Anobium

    Anobium - 2015-04-20

    OK. We have a way forward.

    WilliamR has offered to complete this task.

    I will not include pwm.h in a release until this work is completed.

     
  • viscomjim

    viscomjim - 2015-04-21

    Hi Tony, this is very interesting. Could you share your code (or a sample) as to how you are using 4 hardware pwm channels on the chip. I am assuming this only works on the 16f1829 or also the 16f1825? I appreciate it!!!

     
  • tony golding

    tony golding - 2015-04-21

    hi viscomjim,

    this chip has 2 each ECCP/CCP modules on board so im just using the default pin with the HPWM command

    the 12f1829 and 12f1825 are both from the same family one just having a few more pins, but it does have the same number of modules just different pin assignments from them.

    i was using that chip before changing over to the 1829 but should still work if i change them back.

    the pwm.h file is being reworked by william so once done that should give you what you need.

    tony

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.