DarkSilver
Newbie level 4
- Joined
- Jul 23, 2010
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Linkoping, Sweden
- Activity points
- 1,322
Hi
I'm currently working on a little macro/subroutine library for PIC microcontrollers, so that I can work more fluently in the future. However, I've run into an issue that I just can't solve.
What I want to do is to read the value from an analogue to digital conversion, use that value to blink LEDs at various speeds(just for testing purposes). The thing is that it keeps blinking at a constant rate, no matter what value my ADC has. I've tried to replace the ADC reading with a normal variable instead and it worked flawlessly. I also know that the ADC works, since I can display it's value on PORTC.
The thing is that I just can't figure out what is wrong, so I can't fix it.
Here is the Assembly code:
I use the PicKit 2 as programmer and I use the low pin board that comes with it as a testing platform.
Any help is gladly accepted.
Regards, DarkSilver
I'm currently working on a little macro/subroutine library for PIC microcontrollers, so that I can work more fluently in the future. However, I've run into an issue that I just can't solve.
What I want to do is to read the value from an analogue to digital conversion, use that value to blink LEDs at various speeds(just for testing purposes). The thing is that it keeps blinking at a constant rate, no matter what value my ADC has. I've tried to replace the ADC reading with a normal variable instead and it worked flawlessly. I also know that the ADC works, since I can display it's value on PORTC.
The thing is that I just can't figure out what is wrong, so I can't fix it.
Here is the Assembly code:
Code:
;**********************************************************************
; Project name: Basics
; Author: Dennis Fredriksson
; Creation date: 2010-07-09
; Project stage: Alpha
;**********************************************************************
; Processor: PIC 16F690
; Pin-assignment:
; - None
;**********************************************************************
; Comments:
; None so far
;**********************************************************************
;**********************************************************************
; Compiler setup
;**********************************************************************
list p=16F690
#include <p16F690.inc>
errorlevel -302
;**********************************************************************
; Pic configuration
;**********************************************************************
__CONFIG _CP_OFF & _CPD_OFF & _BOR_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _FCMEN_OFF & _IESO_OFF
;**********************************************************************
; Variables
;**********************************************************************
INT_VAR UDATA_SHR
vDC1 res 1
vDC2 res 1
vDC3 res 1
vAdc res 1
vTest res 1
;**********************************************************************
; Macros/functions
;**********************************************************************
; RegSet - Sets a specific register bit to 1
; reg: the destination register
; bit: the bit to be set to 1 in the destination register
RegSet MACRO reg, bit
banksel reg
bsf reg, bit
endm
; RegClear - Sets a specific register bit to 0
; reg: the destination register
; bit: the bit to be set to 0 in the destination register
RegClear MACRO reg, bit
banksel reg
bcf reg, bit
endm
; RegEdit - Gives a specific register some data
; reg: the destination register
; dat: the 8-bit data going to the destination register
RegEdit MACRO reg, dat
banksel reg
movlw dat
movwf reg
endm
; RegEditF - ; Gives a specific register some data from another register
; regD: the destination register
; regO: the origin register, which data is sent to the destination register
RegEditF MACRO regD, regO
banksel regO
movfw regO
banksel regD
movwf regD
endm
; DelayMs - Adds a delay for X micro seconds
; ms: the amount of micro seconds
DelayMs MACRO ms
movlw ms
call sDelay10
endm
; DelayMsF - Adds a delay for X micro seconds, data taken from a register
; reg: origin register, in which the amount of micro seconds is stored
DelayMsF MACRO reg
movfw reg
call sDelay10
endm
; A2DConv - Preforms an A/D conversion
; Requires hardware setup prior to usage(see ADCON0, ADCON1 and ANSEL), PIC specific
A2DConv MACRO
call sAdcCon
endm
; IfEqual - Do an if A = B check
; reg: the origin register (A)
; cmp: the number to compare to (B)
; sub: the subroutine to call if true
IfEqual MACRO reg, cmp, sub
movfw reg
sublw cmp
btfsc STATUS, Z
call sub
nop
endm
; IfNotEqual - Do an if A != B check
; reg: the origin register (A)
; cmp: the number to compare to (B)
; sub: the subroutine to call if true
IfNotEqual MACRO reg, cmp, sub
movfw reg
sublw cmp
btfss STATUS, Z
call sub
nop
endm
; IfGreater - Do an if A > B check
; reg: the origin register (A)
; cmp: the number to compare to (B)
; sub: the subroutine to call if true
IfGreater MACRO reg, cmp, sub
movfw reg
sublw cmp
btfss STATUS, C
call sub
nop
endm
; IfLesser - Do an if A < B check
; reg: the origin register (A)
; cmp: the number to compare to (B)
; sub: the subroutine to call if true
IfLesser MACRO reg, cmp, sub
movfw reg
sublw cmp
btfsc STATUS, C
call sub
nop
endm
;**********************************************************************
; Main program starts here
;**********************************************************************
org 0
;**********************************************************************
; Main program setup
;**********************************************************************
Start
RegEdit TRISC, 0x00
RegEdit TRISA, 0xFF
RegEdit ADCON1, 0x10
RegEdit ANSEL, 0xFF
RegEdit ADCON0, 0x01
RegEdit vTest, .10
;**********************************************************************
; Main loop
;**********************************************************************
MainLoop
A2DConv
RegEdit PORTC, 0xFF
DelayMsF vAdc
RegEdit PORTC, 0x00
DelayMsF vAdc
goto MainLoop
;**********************************************************************
; Subroutines
;**********************************************************************
sDelay10 ; Adds a delay that lasts X times 10 milliseconds
movwf vDC3
sDelay2
movlw .13
movwf vDC2
clrf vDC1
sDelay1
decfsz vDC1, f
goto sDelay1
decfsz vDC2, f
goto sDelay1
decfsz vDC3, f
goto sDelay2
return
sAdcCon ; The A/D conversion subroutine
nop
nop
nop
nop
nop
bsf ADCON0, GO
btfss ADCON0, GO
goto $-1
banksel ADRESH
swapf ADRESH, w
movwf vAdc
return
;**********************************************************************
; End directive
;**********************************************************************
end
I use the PicKit 2 as programmer and I use the low pin board that comes with it as a testing platform.
Any help is gladly accepted.
Regards, DarkSilver