Menu

HPWM on PIC12F683?

Help
2008-01-04
2013-05-30
  • Nobody/Anonymous

    I am a newbie at these MCU's and GCBasic, and have been unable to find my answer on a forum search...

    I can only get "PWMon" to work with the PIC12F683, but not the "HPWM." This really bites because I need to change the duty cycle while the program is running, which PWMon doesn't seem to allow me to do. I have used the example code as reference from the online help article: http://gcbasic.sourceforge.net/help/hpwm.htm which doesn't work for me.

    I have set the GPIO.2 pin to OUT in my code, then used the code "HPWM 1, 40, 127" (and various other duty cycles and frequencies throughout my ordeal ;) ). The LED just doesn't light up at all. I have tried putting that code into a loop, put a delay afterwards, and neither light up the LED.

    What am I doing wrong?

     
    • justingra

      justingra - 2008-01-04

      I have the same problem, but I have been unable to even turn an LED on at all for GPIO.2.  Have you been able to see any output on that pin?  On another note can't you use

          #define PWM_Freq 76    'Set frequency in KHz
          #define PWM_Duty 80    'Set duty cycle to 80 %

      to set the PWMOn parameters?

       
    • Nobody/Anonymous

      I have used those PWMOn parameters, but the GCBASIC is only looking at my first set of parameters, (in this case, it would be the "low power" parameters, since I want varying power levels, starting at low). I have defined them in several different instances in my program, but it just uses the first one it sees in the code.

      I have been using the output pin GPIO.2 with all my coding experiments with out any issues.

      I start my program with this code when using the GPIO.2 output pin:

      #chip 12F683, 4
      DIR GPIO.2 out
      'normal use, no PWM

      'rest of the program....
      Start:   'etc

       
    • justingra

      justingra - 2008-01-05

      Alright, I see what you are saying now.  I have been able to resolve my output issues and now I am seeing the same problems you are when I try HPWM.  Have you tried the software version (PWMOut)?  Would that work for you? 

      On another note, I noticed that the PWM code is in GCBASIC/include/lowlevel/pwm.h.  I haven't taken a close look at this file, but if the software version doesn't work for you then you could try messing around with this file.  Sorry about the limited advice, I am a newbie too.

       
    • Jonny!!!

      Jonny!!! - 2008-01-06

      I took a look at the pwm.h file, and its beyond my understanding =D Thanks for the info tho. Does anyone else know?

       
    • Hugh Considine

      Hugh Considine - 2008-01-07

      There as a misplaced [word] in the pwm.h file. I completely changed the code in GCBASIC for handling calculations a while back, and did not move the [word] appropriately.

      For those interested, the offending line in pwm.h was:

      CCPR1L = (PWMDuty * PR2) / 255 [word]

      In the older version, this would make GCBASIC treat the whole calculation as a word. However, after the change to the calculation code it only makes GCBASIC treat the variable after the [word], and anything calculation which uses its value as a word. (This is the same behaviour as is seen in Java when casting a variable or object.)

      The result is that GCBASIC wasn't using the 16-bit multiply code, and so whenever PWMDuty * PR2 exceeded 255 the result would overflow, and end up as something 255 or under. So, CCPR1L would be set to 0 except when the result of (PWMDuty * PR2) & 255 = 255, when it would be 1 and the LED would turn on.

      The fixed line is:
      CCPR1L = ([word]PWMDuty * PR2) / 255
      which works fine and makes the whole calculation compile correctly.

      The update is at http://gcbasic.sourceforge.net/newfiles/update.zip or http://gcbasic.sourceforge.net/newfiles/update-nochipdata.zip depending on what chip data files you already have installed. Download the first one if your chip data files are older than 27/9/2007, otherwise download the second one.

       
    • Jonny!!!

      Jonny!!! - 2008-01-08

      Thanks Hugh! I owe ya a beer! It works now =D

       

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.