Menu

PWM Setup and coding for PIC16F1455

Help
2023-03-09
2023-03-13
  • David Abrames

    David Abrames - 2023-03-09

    Hello,
    I have been trying to figure out how to code the PWM feature of the PICF1455. I was under the impression that all I have to do is enter the line #CHIP 16F1455 and GCBasic would do its magic and configure everything so I could then start using the hardware PWM routines. This does not seem to be working. I have been reading the data sheet and then setting the various registers to enable PWM but so far I have had no luck. Since I don't find anyone else having all the issues that I am having, my thinking is that there is some secret to using GCBasic?

    I've been trough all the readme files and other information I can find but I just don't seem to be able to get even the DEMO programs to work.

    I did give the GCStudio a try and that seems to be an even bigger problem to tackle so I switched back to GCBasic for now. If there is a set by step document or guide that is for complete idiots like me I would be grateful to be pointed in the correct direction

    Please don't think I am being critical of GCBasic I really would like to learn this environment and make it work for me but I just don't seem to "get it" whatever "it" is.

    David

     
  • mmotte

    mmotte - 2023-03-10

    David,
    Welcome to GCB. I have been using it for a long time and it works.

    PWM has changed to accommodate the upgrade of the PIC chips.
    I assume you want the Hardware PWM
    So first , I had to look your PIC16F1455
    PWM1 is on RC5
    PWM2 is defaut on RC3 But has an alternate using PPS but is not on the list of the pps tool in GCB
    The pin must be set to output

    Looking in sect 24 - PWM of the pdf of 16F1455
    PIC16F1455 has 10 bit resolution PWM so you need to use a word variable
    Also see that PWM uses timer 2

    In the great cow help https://gcbasic.sourceforge.net/help/_hpwm_10_bit.html
    see this code

    Syntax:

    HPWM channel, frequency, duty cycle, timer [, resolution]
    
    'This program will alter the brightness of an LED using
        'hardware PWM.
    
        'Select chip model and speed
        #chip 16F1455, 32
    
           'Set the PWM pin to output mode
        DIR PORTC.5 out
    
        dim Bright as word
    
        'Main code
        do
            'Turn up brightness over the range
            For Bright = 0 to 1023
                HPWM 1, 40, Bright, 2
                wait 10 ms
            next
            'Turn down brightness over the range
            For Bright = 1023 to 0 Step -1
                HPWM 1, 40, Bright, 2
                wait 10 ms
            next
        loop
    

    I have not tested this but think this should work.

    It sound like you are having trouble getting around in GCStudio?

    Please give more details in your questions. Operating system, gcb version, which demo you tried, have you been able to program a chip and flash an LED?
    We kind need to know where you are.
    You will find good help on this forum.

    GL
    Mike

     
    👍
    1
    • David Abrames

      David Abrames - 2023-03-13

      Dear Mike your sample worked alone with the change provided by Anobium
      Thank you VERY much

      David

       
  • Anobium

    Anobium - 2023-03-10

    Here is an improved PWM.H library. This will detect that CCP/PWM is not available and it will issue a warning, and, advice on how to resolve.

    Replace the existing pwm.h in the ..\greatcowbasic\include\lowlevel folder. Download here This file woll be included in build 1222.

     
    • David Abrames

      David Abrames - 2023-03-13

      Thank you that changed helped a lot.
      David

       
  • David Abrames

    David Abrames - 2023-03-11

    Dear Mike,
    Thank you very much I will give your suggestion a try and let you now what happens

    I think I am going to focus on GCBasic for now and then look at GCStudio later.

     

    Last edit: David Abrames 2023-03-11
  • David Abrames

    David Abrames - 2023-03-11

    Dear Anobium,

    Thank you I will try that. Thank you

     
  • David Abrames

    David Abrames - 2023-03-11

    Dear Anobium,

    Thank you I will try that. Thank you

     

Log in to post a comment.