Menu

16F1789 16 bit PWM

Help
Mikam
2018-12-19
2018-12-21
  • Mikam

    Mikam - 2018-12-19

    Hi all
    i'm getting an 8 bit output but not 16bit.
    `

     ;Chip Settings
    #chip 16F1789,32
    
    '------------------------
    'GCB v0.98.03  2018-10-20
    '------------------------
    'cccp1 out
    dir portc.2 out
    
    #define HPWM16_1_Freq 10
    #define HPWM16_1_Duty 50
    HPWM16On ( 1 )
    
    'HPWM 1, 10, 255
    
    Main:
    goto Main
    

    `

     

    Last edit: Anobium 2018-12-19
  • Anobium

    Anobium - 2018-12-19

    You have a bit of mixtur of commands... hence the confusion.

    This code will work. But, as the CCP duty constant is essentially a 8-bit number in the range of 0 to 100 I am not sure the revalance of the 16bit.

    ;Chip Settings
    #chip 16F1789,32
    'cccp1 out
    dir portc.2 out
    
    #define PWM_Freq 10       'Frequency of PWM in KHz
    #define PWM_Duty 50       'Duty cycle of PWM
    PWMOn
    
    Main:
    goto Main
    

    This device is not really 16bit PWM module, they simply compare a 16bit timer. There is is a specific 16bit PWM that is really 16bit. The 16f1789 is CCP fixed on the imer 2 - not a true 16bit PWM module.

    For this device this works for variable PWM and duty.

    'Main code
    'freq 40khz
    'variable duty from 0% to 100%
    do
        'Turn up brightness over 2.5 seconds
        For Bright = 1 to 255
            HPWM 1, 40, Bright
            wait 10 ms
        next
        'Turn down brightness over 2.5 seconds
        For Bright = 255 to 1
            HPWM 1, 40, Bright
            wait 10 ms
        next
    loop
    

    end

     

    Last edit: Anobium 2018-12-19
  • Mikam

    Mikam - 2018-12-19

    Thanks for clearing up.

     
  • Anobium

    Anobium - 2018-12-19

    And, the datasheet is 100% incorrect.

    High-Performance PWM Controller:
    • Four Programmable Switch Mode Controller
    (PSMC) modules:
    - Digital and/or analog feedback control of
    PWM frequency and pulse begin/end times
    - 16-bit Period, Duty Cycle and Phase
    - 16 ns clock resolution
    - Supports Single PWM, Complementary,
    Push-Pull and 3-phase modes of operation
    - Dead-band control with 8-bit counter
    - Auto-shutdown and restart
    - Leading and falling edge blanking
    - Burst mode

    Should read....not PWM but PSMC

    High-Performance PSMC Controller:
    • Four Programmable Switch Mode Controller
    (PSMC) modules:
    - Digital and/or analog feedback control of
    PWM frequency and pulse begin/end times
    - 16-bit Period, Duty Cycle and Phase
    - 16 ns clock resolution
    - Supports Single PWM, Complementary,
    Push-Pull and 3-phase modes of operation
    - Dead-band control with 8-bit counter
    - Auto-shutdown and restart
    - Leading and falling edge blanking
    - Burst mode

    As later in the datasheet .. it states...

    Two Capture/Compare/PWM modules (CCP):
    - 16-bit capture, maximum resolution 12.5 ns
    - 16-bit compare, max resolution 31.25 ns
    - 10-bit PWM, max frequency 32 kHz

    No wonder.. people get confused.

     

    Last edit: Anobium 2018-12-19
  • Anobium

    Anobium - 2018-12-19

    And, in the very latest release we have included the PSMC software... so, if you have a year or two to learn PSMC then you could generate a 16bit PWM signal via the PSMC module.

     
  • William Roth

    William Roth - 2018-12-21

    I tried the PSMC tool and got an exception error when I tried to change a value. Using Win 10
    Will investigate further

     

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.