Hi there
I'm using MPLAB-X with a PicKit 2 and it's demoboard [04-01831 Rev2] to turn on the first LED (of the four on the demo board) and rotate it left until it rotates off the fourth LED, at which point the First LED gets turned on again. This loops forever. So I end up with a rotating 'on' LED
Rotating the 'on' LED works when the 16F690 gets programed and run (all in one). One thing though, is that the first and second LEDs flicker (I assume this is normal when the program downloads) and the rotating sequence seems to start at the second LED.
If I cycle the power however, the program behaves differently.
After power cycling, LEDs 1 and 2 turn on immediately and then the third and fourth LEDs turn on in succession at the same rate as the good program and none of the LEDs (1-4) ever go off. So I end up with all the LEDs on.
I've read the datasheet and cannot figure out why there is a difference between power up and after programing
Can anyone help?
My code is as follows:
I'm using MPLAB-X with a PicKit 2 and it's demoboard [04-01831 Rev2] to turn on the first LED (of the four on the demo board) and rotate it left until it rotates off the fourth LED, at which point the First LED gets turned on again. This loops forever. So I end up with a rotating 'on' LED
Rotating the 'on' LED works when the 16F690 gets programed and run (all in one). One thing though, is that the first and second LEDs flicker (I assume this is normal when the program downloads) and the rotating sequence seems to start at the second LED.
If I cycle the power however, the program behaves differently.
After power cycling, LEDs 1 and 2 turn on immediately and then the third and fourth LEDs turn on in succession at the same rate as the good program and none of the LEDs (1-4) ever go off. So I end up with all the LEDs on.
I've read the datasheet and cannot figure out why there is a difference between power up and after programing
Can anyone help?
My code is as follows:
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Author : James Payne
;
; Title: Stepper 5
;
; Description:
;
;
; At the moment it should just move a stepper forward slowly
;
;
; Uses Port C to move the motor
;
; MOTION bit 0 Do a move = 1
; bit 1 Move Forward = 0
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF &_MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
;*****Set up the Constants****
cblock 0x20 ; Dynamically allocated registers
COUNT1 ; For first delay loop
COUNT2 ; For second delay loop
MOTION ; Motion/direction flag register
endc
cblock 0x70 ; Put these up in unbanked RAM
W_Save ; For saving the working and status registers during an ISR
STATUS_Save
endc
ORG 0x00 ; This is where we come on power up and reset
goto Setup ; After power-up / reset the registers need to be initialised
ORG 0x04 ; This is where we come on an interupt
goto ISR
ISR:
movwf W_Save ; Save the working register
movf STATUS,w
movwf STATUS_Save ; Save the Status register
btfsc INTCON,T0IF ; Was it a TMR0 interupt?
goto ServiceTMR0 ; yes, do the ISR for TMR0
goto ExitISR
ServiceTMR0:
bcf INTCON,T0IF ; Clear the interrupt flag. (must be done in software)
btfsc MOTION,0 ; Is a move required?
call Do_Motion ; yes, go to the motion controller
goto ExitISR ; no, return form inerrupt
ExitISR:
movf STATUS_Save,w ; Restore the Status register
movwf STATUS
swapf W_Save,f ; Restore the working register
swapf W_Save,w
retfie
;****Set up the port****
Setup bsf STATUS,RP0 ;Switch to Bank 1
bcf STATUS,RP1 ;
movlw b'00000111' ; Configure Timer0 to have the
movwf OPTION_REG ; Maximum Prescaler
clrf TRISC ; Tristate C port to outputs.
bcf STATUS,RP0 ; Switch to Bank 2
bsf STATUS,RP1 ;
clrf ANSEL ; Digitl outputs.
clrf ANSELH ; Digitl outputs.
bcf STATUS,RP0 ; Switch back to Bank 0
bcf STATUS,RP1 ;
movlw 0x01 ; Set the PORT to '10001000'
movwf PORTC ; ready for stepper control.
movlw b'10100000' ; Enable Timer 0 and global interrupts
movwf INTCON ;
movlw 0x01 ; Set to Do_Motion and Move Fwd
movwf MOTION ;b
;****Main routine****
Start
call Delay
; Main program goes here
goto Start ;go back to Start and run the program again
;**** End of the main program loop ********************************************
;**** Program sub-routines listed here ****************************************
;**** Motion sub-routine handles a call for robot movement *****
Do_Motion
btfss MOTION,1 ; Move Fwd?
call Step_Fwd ; Fwd = 0
btfsc MOTION,1 ; Move Rev?
call Step_Rev ; Rev = 1
return
;**** Move the robot forward one step *****
Step_Fwd
rlf PORTC,f ; Move motor to next winding (step once)
btfsc PORTC,4
bsf PORTC,0
call Delay ; Slow things down to see easier
call Delay ; (No particular time period)
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
return
;**** Move the robot forward one step *****
Step_Rev ; Never gets here at present
rrf PORTC,f ; Move motor to next winding (step once)
btfsc PORTC,3
bsf PORTC,7
return
;**** Delays the program manually *****
Delay
movlw 0xff ; Setup delay times each call of delay
movwf COUNT1
movlw 0xff
movwf COUNT2
Loop1 decfsz COUNT1,f ;This second loop keeps the LED
goto Loop1 ;turned off long enough for us to
movlw 0xff
movwf COUNT1
decfsz COUNT2,f ;see it turned off
goto Loop1 ;
return
;**** End of the program *****************************************************
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.
Last edited: