piersuk
Junior Member level 2
Sorry for being such a newbie and having no idea what I'm doing, but I'm trying to work things through.
What I'm trying to do is drive a DC motor at different voltages with a 2 second delay inbetween each step. I have tried the below which I hoped would be two steps 3.8v and 6v but alas no.
Any help with the code would be appreciated. In addition I would like to know what and where to add each voltage step piece of code.
This is my code
Thanks
A Slow Learner !
What I'm trying to do is drive a DC motor at different voltages with a 2 second delay inbetween each step. I have tried the below which I hoped would be two steps 3.8v and 6v but alas no.
Any help with the code would be appreciated. In addition I would like to know what and where to add each voltage step piece of code.
This is my code
Code:
LIST P=PIC16F819, r=hex, f=INHX8M
INCLUDE "p16f819.inc"
__CONFIG 3909H
;********* program proper starts here *************************************
ORG 00H ; reset vector
GOTO START
ORG 010H
START
; these 3 lines set the period of the pulsing (39 kHz)
MOVLW 01FH
BSF STATUS,RP0
MOVWF PR2
; make all ports outputs (only B1 is used)
CLRF TRISB
BCF STATUS,RP0
; configure as PWM mode
MOVLW B'00001100'
MOVWF CCP1CON
; the value of CCPRIL sets the duty cycle and therefore the voltage
;MOVLW 010H ; gives 2.52 V
MOVLW 018H ; gives 3.8 V
;MOVLW 022H ; 6v
MOVWF CCPR1L
; turn the PWM on
BSF T2CON, TMR2ON ;and start the timer running
; Delay = 2 seconds
; Clock frequency = 4 MHz
; Actual delay = 2 seconds = 2000000 cycles
; Error = 0 %
cblock
d1
d2
d3
endc
Delay
;1999996 cycles
movlw 0x11
movwf d1
movlw 0x5D
movwf d2
movlw 0x05
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;4 cycles (including call)
; these 3 lines set the period of the pulsing (39 kHz)
MOVLW 01FH
BSF STATUS,RP0
MOVWF PR2
; make all ports outputs (only B1 is used)
CLRF TRISB
BCF STATUS,RP0
; configure as PWM mode
MOVLW B'00001100'
MOVWF CCP1CON
; the value of CCPRIL sets the duty cycle and therefore the voltage
;MOVLW 010H ; gives 2.52 V
;MOVLW 018H ; gives 3.8 V
MOVLW 022H ; gives 6.0v
MOVWF CCPR1L
; turn the PWM on
BSF T2CON, TMR2ON ;and start the timer running
FIN NOP
GOTO FIN
END
Thanks
A Slow Learner !