The "HPWM" Command only works with CCPx Modules, not PWMx. This should get you functional:
Code:#CONFIG CONFIG PPS1WAY = OFF ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence) #ENDCONFIG Value VAR BYTE Init: ; -=- NOTE: This is merely example code. There are no SFRs for OSC and other Important Registers!! -=- TRISC.2 = 1 ;Initialize PWM4 Output as an Input, will change later ANSELC.2 = 0 ;Make PWM4 Output Digital PIE4.1 = 0 ;Ensure TMR2 Interrupt is Disabled PIR4.1 = 0 ;Clear TMR2 Interrupt Flag ; -=- NOTE: Section 20 of the Data Sheet Covers Pre/Post Scalers for Timer 2 -=- T2CON = %00100000 ;1:4 Prescaler, note ON = 0 T2CON.7 = 1 ;Turn Timer 2 ON in Separate Operation WHILE PIR4.1 = 0 ;Wait Until Timer2 is Running WEND PIR4.1 = 0 ;Timer 2 is Now Running TRISC.2 = 0 ;Now Change RC2 to Output PPSLOCK = $55 ;Peripheral Pin Select PPSLOCK = $AA ; Unlock Sequence PPSLOCK.0 = 0 ; PPS = UNLOCKED RC2PPS = $08 ;PWM4 Output on RC2 ; -=- NOTE: You can Lock PPS when you're done (Optional, but Recommended) PPSLOCK = $55 ;Peripheral Pin Select PPSLOCK = $AA ; Unlock Sequence PPSLOCK.0 = 1 ; PPS = LOCKED PWM4DCL = 0 PWM4DCH = 100 ;THIS IS YOUR DUTY CYCLE REGISTER, 0 >> 255 (8-bit) PWM4CON = $80 ;Turn PWM4 ON Main: DO 'GOSUB Get_PWM4 ; -=- Determine Value for PWM4 DC% PWM4DCH = Value LOOP




Bookmarks