Menu

HPWM Frustration

Help
2025-01-01
2025-01-01
  • Sam Carriere

    Sam Carriere - 2025-01-01

    Hello, I am an on and off PIC user and I've always been able to troubleshoot my way to a solution but trying to use the HPWM has finally broke me. I've looked at all the forum posts, the documentation, demo code, I've even tried ChatGPT with nothing to show for it. So here goes, will keep it as simple as possible: I'm using an MPLABXpress board with a PIC18F46K42 and it's a great little board. I want to output a pulse on RC0 using the HPWM at 16KHz with a 50% DC. If I could get this to work I pretty sure I can figure the rest. Any help will be greatly appreciated.

    ; ----- Configuration
    #Chip 18F46K42, 64
    
    #CONFIG CLKOUTEN=OFF
    #CONFIG CP=OFF
    #CONFIG CSWEN=ON
    #CONFIG FCMEN=ON
    #CONFIG FEXTOSC=OFF
    #CONFIG LVP=OFF
    #CONFIG MCLRE=INTMCLR
    #CONFIG MVECEN=OFF
    #CONFIG RSTOSC=HFINTOSC_64MHZ
    #CONFIG WDTCCS=SOSC
    #CONFIG WDTCPS=WDTCPS_11
    #CONFIG WDTE=OFF
    #CONFIG WRTB=OFF
    #CONFIG WRTD=OFF
    #CONFIG WRTSAF=OFF
    #CONFIG XINST=OFF
    
    
        // PIC PPS Tool version: 0.0.6.5
    
        #startup InitPPS, 85
        #define PPSToolPart 18F46K42
    
        Sub InitPPS
    
                // Module: CCP1
                RC0PPS = 0x0009    // CCP1 > RC0
                CCP1PPS = 0x0010    // RC0 > CCP1 (bi-directional)
    
            End Sub
        // Add this code segment to your GCBASIC source program
    
    #define USE_HPWMCCP1 TRUE       ' This is not used so optimise
    #define USE_HPWMCCP2 FALSE        ' This is used so include in the compiled code
    #define USE_HPWMCCP3 FALSE       ' This is not used so optimise
    #define USE_HPWMCCP4 FALSE       ' This is not used so optimise
    DIM i AS Integer
    i = 124
    
    DIR PORTC.0 out     ' This the CCP2 pin for HPWM
    DO
    HPWM 2, 16, i      '  Send to the HPWM
    WAIT 10 MS
    LOOP
    
     

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.