Change Chip to p12f683
wanted PWM frequency at 5KHz
Set: clock speed to 4MHz.
Clock source to clk/1
period register
Compile to hex
load complied hex into a simulator
Within simulator ran scope on port a,2
When simulator running, I was watching Microcontroller View and scope.
At first port a,1 was showing A for analogue input, so set for 2.5V
then just after ADC sampling port a,2 changed to Digital input, then back to analogue with default of 0V.
Ran simulator disassembler which displayed:
Code: Select all
;-----------------------------------
;PIC DISASSEMBLER LISTING
;Label Instruction
;-----------------------------------
GOTO L1
ADDLW 0xFF
ADDLW 0xFF
ADDLW 0xFF
MOVWF 0x07F
SWAPF STATUS,W
BCF STATUS,RP0
MOVWF 0x020
SWAPF PCLATH,W
MOVWF 0x021
SWAPF FSR,W
MOVWF 0x022
BCF PCLATH,3
BCF PCLATH,4
GOTO L2
ADDLW 0xFF
L9: DECF 0x025,W
BTFSS STATUS,Z
RETURN
MOVF 0x026,W
MOVWF CCPR1L
RETURN
L6: MOVLW 0xC7
BSF STATUS,RP0
MOVWF T2CON
MOVLW 0x04
BCF STATUS,RP0
MOVWF T2CON
DECF 0x025,W
BTFSS STATUS,Z
RETURN
MOVLW 0x0C
MOVWF CCP1CON
BSF STATUS,RP0
BCF GPIO,2
RETURN
L7: BSF STATUS,RP0
MOVF GPIO,W
BCF STATUS,RP0
MOVWF 0x025
MOVLW 0x02
BSF STATUS,RP0
IORWF GPIO,W
MOVWF GPIO
MOVLW 0x22
MOVWF ADCON0
MOVLW 0x05
BCF STATUS,RP0
MOVWF ADCON0
CLRF 0x026
L4: MOVLW 0x28
SUBWF 0x026,W
BTFSC STATUS,C
GOTO L3
INCF 0x026,F
GOTO L4
L3: MOVLW 0x02
IORWF ADCON0,W
MOVWF ADCON0
L5: BTFSC ADCON0,GO_DONE
GOTO L5
[b]MOVF 0x025,W
BSF STATUS,RP0
MOVWF GPIO
MOVLW 0x20
MOVWF ADCON0
BCF STATUS,RP0
CLRF ADCON0 [/b]
RETURN
L8: BCF STATUS,RP0
MOVF ADRESH,W
MOVWF 0x025
RETURN
L11: MOVLW 0x07
BCF STATUS,RP0
MOVWF CMCON0
MOVLW 0xC0
BSF STATUS,RP0
MOVWF TMR0
MOVLW 0x01
BCF STATUS,RP0
MOVWF 0x025
CALL L6
L10: CALL L7
CALL L8
MOVF 0x025,W
MOVWF 0x023
MOVLW 0x01
MOVWF 0x025
MOVF 0x023,W
MOVWF 0x026
CALL L9
MOVF 0x023,W
SUBLW 0xFF
MOVWF 0x024
MOVLW 0x02
MOVWF 0x025
MOVF 0x024,W
MOVWF 0x026
CALL L9
GOTO L10
L1: BCF PCLATH,3
BCF PCLATH,4
GOTO L11
L2: BCF STATUS,RP0
SWAPF 0x022,W
MOVWF FSR
SWAPF 0x021,W
MOVWF PCLATH
SWAPF 0x020,W
MOVWF STATUS
SWAPF 0x07F,F
SWAPF 0x07F,W
RETFIE
END
Code: Select all
MOVF 0x025,W
BSF STATUS,RP0
MOVWF GPIO
MOVLW 0x20
MOVWF ADCON0
BCF STATUS,RP0
CLRF ADCON0
RETURN
My questions are:
1) why was code I removed,in place to start with?
I'm unsure why ADC i/p was required to change to digital i/p since I have already got a pic programmed and running with pwm variable form 0 to 100% without ADC i/p changing to digital i/p
2) How do I change flowchart or settings so PWM% = ADC%?
Currently 50% ADC = 64% PWM
3)If target chip is changed to p12F615 why can only one PMW component be use when data sheet shows 1 or 2 output channels?
is it 1 component per ccp?