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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
Check out https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/Vendor_Boards/Great_Cow_Basic_Demo_Board/18F25K42_ChipRange_Demonstrations/120_Use_PWM_via_CCP_and_ADC_to_control_LED_brightness.gcb
Clearly, CPP was working when I posted this program. Examine the program and see if you resolve.
Let me know what happens
Evan