Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
we definitely Thank you as you are rehearsing our knowledge.Hello everyone,
I am not a pro electrical and this might be a simple question.
Is placing 2 capacitor 0.1uf necessary between Vdd and ground?
Q1> If yes why?
Q2> If yes shall i place 1 or 2 capacitors?
See attachment to understand more.
;*******************************************************************
; 16F877 PWM Program
;*******************************************************************
include "p16f877.inc"
errorlevel -302
radix dec
__CONFIG _CP_OFF & _DEBUG_ON & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF & _CPD_OFF
cblock 20h
OnTime:2
OffTime:2
endc
cblock 71h
int_work
int_status
int_pclath
endc
org 0h
nop
goto start
nop
nop
org 04h
interrupt movwf int_work
swapf STATUS,W
movwf int_status
bcf STATUS,RP0
bcf STATUS,RP1
movfw PCLATH
movwf int_pclath
clrf PCLATH
btfsc PORTB,0
goto TurnOff
; turn on the output and write the on time
nop; delay to make both path identical
bsf PORTB,0;<<<<<<<<<< Break Point
movfw OnTime+1
movwf CCPR1H
movfw OnTime
movwf CCPR1L
goto DonePWM
TurnOff bcf PORTB,0;<<<<<<<<<< Break Point
movfw OffTime+1
movwf CCPR1H
movfw OffTime
movwf CCPR1L
DonePWM
bcf PIR1,CCP1IF; reset special event trigger interupt
movfw int_pclath
movwf PCLATH
swapf int_status,W
movwf STATUS
swapf int_work,F; swap to file
swapf int_work,W; swap to work
retfie
start bsf STATUS,RP0
bcf STATUS,RP1
bsf STATUS,IRP; all indirest access is to 100h - 1ffh
movlw (0<<NOT_RBPU|0<<INTEDG|0<<T0CS|0<<T0SE|0<<PSA|B'000'<<PS0)
movwf OPTION_REG
movlw b'11111110'
movwf TRISB
bcf STATUS,RP0
movlw (b'01'<<T1CKPS0|0<<T1OSCEN|0<<NOT_T1SYNC|0<<TMR1CS|1<<TMR1ON)
movwf T1CON; enable timer 1
movlw low(5000)
movwf CCPR1L
movwf OnTime
movlw high(5000)
movwf CCPR1H
movwf OnTime+1
movlw low(45000)
movwf OffTime
movlw high(45000)
movwf OffTime+1
movlw (0<<CCP1X|0<<CCP1Y|b'1011'<<CCP1M0); enable special event trigger on CCP1
movwf CCP1CON;
bsf STATUS,RP0
bsf PIE1,CCP1IE; enable CCP1 interupt
bcf STATUS,RP0
movlw (1<<GIE|1<<PEIE|0<<T0IE|0<<INTE|0<<RBIE|0<<T0IF|0<<INTF|0<<RBIF)
movwf INTCON; enable Peripheral interupts
Loop
goto Loop
END
list p=p16F877 ; list directive to define processor
#include <p16F877.inc> ; processor specific variable definitions
cblock 0x20
d1
d2
d3
endc
org 0x00
movlw (0<<T0CS)
movwf OPTION_REG
bsf STATUS, RP0
bcf STATUS, RP1
movlw 0x00
movwf TRISB
bcf STATUS,RP0
START movlw 0x00
movwf PORTB
call Delay1sec
movlw 0x01
movwf PORTB
call Delay5sec
goto START
Delay1sec
;4999993 cycles
movlw 0x2C
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
Delay1sec_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay1sec_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
Delay5sec
;4999993 cycles
movlw 0x2C
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
Delay5sec_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay5sec_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
END
The problem in the codes is I didn't set the internal clock to 20Mhz. Anyknow what i should do?
You don't set the clock speed anywhere, you write the code to use the clock speed you choose. In particular the delay routines in the posted code need to be written specifically for the clock speed - and if generated by the PICList delay code generator you have to input the clock speed.
I did it with a PIC delay generator and specified the 20Mhz frequency value.
My question is how I can tell the PIC that I am using 20MHz internal crystal?
OMG, I think what is going wrong PIC16F877 doesn't have an internal clock! I see why the servo didn't rotate. Tommorrow I will go get 20Mhz oscillator. What a discovery .
You need a 20MHz crystal, two small capacitors, and to set the oscillator config fuses to HS.
Or a 16F887 (has built in osc)
what is OP?This OP
what is OP?
You have a pulldown on MCLR. That's backward. Put a pullup - the resistor should connect to VCC/5V.Hello again,
Here is my new diagram I only added 20Mhz crystal and 2X22pf capacitor, I am trying to control a servo motor from pin RB0 of the PIC16F877. Nothing happen, You think my diagram is wrong? or the codes? I posted already?
Thanks in advance
start
movlw b'00000011'
movwf PORTB
call delay1ms450us
movlw b'00000000'
movwf PORTB
call delay18ms550us
goto start
;*******************************************************************
; 16F877 PWM Program
;*******************************************************************
include "p16f877.inc"
errorlevel -302
radix dec
__CONFIG _CP_OFF & _DEBUG_ON & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF & _CPD_OFF
cblock 20h
OnTime:2
OffTime:2
endc
cblock 71h
int_work
int_status
int_pclath
endc
org 0h
nop
goto start
nop
nop
org 04h
interrupt movwf int_work
swapf STATUS,W
movwf int_status
bcf STATUS,RP0
bcf STATUS,RP1
movfw PCLATH
movwf int_pclath
clrf PCLATH
btfsc PORTB,0
goto TurnOff
; turn on the output and write the on time
nop; delay to make both path identical
bsf PORTB,0
bsf PORTB,1;<<<<<<<<<< Break Point
movfw OnTime+1
movwf CCPR1H
movfw OnTime
movwf CCPR1L
goto DonePWM
TurnOff bcf PORTB,0
bcf PORTB,1;<<<<<<<<<< Break Point
movfw OffTime+1
movwf CCPR1H
movfw OffTime
movwf CCPR1L
DonePWM
bcf PIR1,CCP1IF; reset special event trigger interupt
movfw int_pclath
movwf PCLATH
swapf int_status,W
movwf STATUS
swapf int_work,F; swap to file
swapf int_work,W; swap to work
retfie
start bsf STATUS,RP0
bcf STATUS,RP1
bsf STATUS,IRP; all indirest access is to 100h - 1ffh
movlw (0<<NOT_RBPU|0<<INTEDG|0<<T0CS|0<<T0SE|0<<PSA|B'000'<<PS0)
movwf OPTION_REG
movlw b'11111100'
movwf TRISB
bcf STATUS,RP0
movlw (b'01'<<T1CKPS0|0<<T1OSCEN|0<<NOT_T1SYNC|0<<TMR1CS|1<<TMR1ON)
movwf T1CON; enable timer 1
movlw low(5000)
movwf CCPR1L
movwf OnTime
movlw high(5000)
movwf CCPR1H
movwf OnTime+1
movlw low(45000)
movwf OffTime
movlw high(45000)
movwf OffTime+1
movlw (0<<CCP1X|0<<CCP1Y|b'1011'<<CCP1M0); enable special event trigger on CCP1
movwf CCP1CON;
bsf STATUS,RP0
bsf PIE1,CCP1IE; enable CCP1 interupt
bcf STATUS,RP0
movlw (1<<GIE|1<<PEIE|0<<T0IE|0<<INTE|0<<RBIE|0<<T0IF|0<<INTF|0<<RBIF)
movwf INTCON; enable Peripheral interupts
Loop
goto Loop
END