Menu

HPWM on 18F8722

2021-01-27
2021-01-27
  • Daniel Nielsen

    Daniel Nielsen - 2021-01-27

    Hello All,
    I could use some help, please. I'm having issues compiling a program to use two PWM channels simultaneously. I get the error:
    Error: GCASM: Symbol INITPWM has not been defined Message AT not defined in
    messages.dat! CALL INITPWM
    I'm using:
    GCB Compiler Version
    0.98.06
    2019-06-12
    (Windows 32 bit)
    The program is as follows:

    'Chip model and speed
    #chip 18F8722, 4
    #include <lowlevel/pwm.h>
    
    'Configs
    #config osc = intio67     'Use the internal clock
    #config mclr = off    'Reset handled internally
    #config wdt = off     'Give the dog a rest
    
    'Directions
    #define PORTC.2 Out 'PWM1, pin 43
    #define PORTC.1 Out 'PWM2, pin 35
    
    'Dimensions
    dim Ch1DC as Byte 'Duty Cycle 1
    dim Ch2DC as Byte 'Duty Cycle 2
    
    'Initialization
    Ch1DC = 1
    Ch2DC = 255
    
      Do
          For Ch1DC = 1 to 255
            HPWM 1, 1, Ch1DC
            HPWM 2, 1, Ch2DC
            Ch2DC = Ch2DC - 1
              If Ch2DC <= 1 Then
                Ch2DC = 1
              End If
            Wait 10 mS
          Next
    
          For Ch1DC = 255 to 1
            HPWM 1, 1, Ch1DC
            HPWM 2, 1, Ch2DC
            Ch2DC = Ch2DC + 1
              If Ch2DC >= 255 Then
                Ch2DC = 255
              End If
            Wait 10 mS
          Next
      Loop
    
    End
    

    Am I doing something wrong?

     

    Last edit: Chris Roper 2021-01-27
  • Daniel Nielsen

    Daniel Nielsen - 2021-01-27

    Sorry for the appearance of the program. I just copied and pasted from the editor and it pasted really strangely.

     
    • Chris Roper

      Chris Roper - 2021-01-27

      Fixed the Formatting for you .

       
  • Anobium

    Anobium - 2021-01-27

    OK.

    Try the basics. Does this work? This will show the CCP/PWM is operational. You dont need anything else in this test.

    #chip 18F8722, 4
    
    dir portc.2 out
    PWMOn
    
    do
    loop
    
     
  • Daniel Nielsen

    Daniel Nielsen - 2021-01-27

    Hi Anobium!
    Yes, that works fine.

     
    • Anobium

      Anobium - 2021-01-27

      Now rebuild your code from this.

      You know now CCP/PWM1 works. So, focus on that.

      NOT NEEDED #include <lowlevel/pwm.h>
      
      'NOT NEEDED  Configs until later... get the basics working
      #config osc = intio67     'Use the internal clock
      #config mclr = off    'Reset handled internally
      #config wdt = off     'Give the dog a rest
      
      'Directions
      WRONG.....  #define PORTC.2 Out 'PWM1, pin 43
      use DIR
      WRONG..... #define PORTC.1 Out 'PWM2, pin 35
      use DIR
      

      :-)

       

      Last edit: Anobium 2021-01-27
  • Chris Roper

    Chris Roper - 2021-01-27

    This:

    #define PORTC.2 Out 'PWM1, pin 43'
    #define PORTC.1 Out 'PWM2, pin 35'
    

    should be

    Dir PORTC.2 Out 'PWM1, pin 43'
    Dir PORTC.1 Out 'PWM2, pin 35'
    
     

    Last edit: Chris Roper 2021-01-27
  • Daniel Nielsen

    Daniel Nielsen - 2021-01-27

    Oops, that's what it was originally. I messed up the syntax during the heat of battle. I changed it back and still get the same error when I try to compile.

     
  • Daniel Nielsen

    Daniel Nielsen - 2021-01-27

    Well, how about that. The two LED's are cycling perfectly now. Were the CONFIGS messing it up?

     
    • Chris Roper

      Chris Roper - 2021-01-27

      Were the CONFIGS messing it up?
      Quite possibly.

      GCBASIC generally takes care of all the config for you.
      The #Config derivatives are only there to force specific configs that are not normally used and are Device specific.

      I also suggest that you use the Release Candidates if you hit a problem as many bugs get fixed in the background.

      That latest is here:
      https://sourceforge.net/projects/gcbasic/files/Release%20Candidates/

       
  • Daniel Nielsen

    Daniel Nielsen - 2021-01-27

    Thanks much Chris and Anobium. I'll bookmark that link for future reference. I spend a lot of time in the Forums and can usually find solutions to issues I'm having there. I'm sure the Release Candidates will be a powerful resource.

     

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.