PDA

View Full Version : 12F1572 HPWM issue



midali
- 27th March 2021, 21:01
Hi,

HPWM work right on PORTA.1 . Also , the PORTA.5 work well like a digitall port.
I want to move the PWM1 from PORTA.1 to PORTA.5 . Theoretically is very simple, must set APFCON.0 =1 .
Now I have a problem because on pin A5 I have nothing, also, the HPWM is missing on pin A.1 .
I changed the PIC from another lot , but the same !
If I set APFCON.1 = 1 , the PWM2 is moved from A.0 to A.4, so the APFCON have an effect.
Something is missing or chip have some trouble ?



#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _BOREN_OFF & _CLKOUTEN_OFF
__config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LPBOREN_OFF & _LVP_OFF
#ENDCONFIG


DEFINE OSC 4 ' system clock at 4MHz
OSCCON = %01101010




DEFINE HPWM_OSC 16000000 ' PWM clock at 16MHz
APFCON.0 = 1


ANSELA = %00000000
PORTA = %00000000


main:
hpwm 1 , 100, 16000 'PORTA.5


goto main

richard
- 29th March 2021, 12:00
try

DEFINE CCP1_REG PORTA 'Channel-1 port
DEFINE CCP1_BIT 5 'Channel-1 bit

and maybe

trisa.5=0

midali
- 30th March 2021, 10:40
Now is working...

Was necesary only to set the port RA.5 as output . Its iteresting that portA5 work well as digitall output pin but did'n work as PWM pin only if its set to output.

Thank you very much Richard !