Truncated match.
PICList
Thread
'lookup table ???'
1999\04\20@131318
by
Glen
|
hi & thanks for sparing the time
between the ******
is the code with a single value that works in a counter routine in
an16f84
;******************test value ***********************
; movlw 25 ;one single counter value
; movwf strttmr ;load 25 into strtmr reg.
;****************************************************
i am stuck with trying to use the lookup table below to replace the
above value
with selectable values
i am using 2 switches to give one of four possible values
this switch code is to be passed upon power up
swA
-----/ -----| rb0
gnd |
|--------\/\/\/------------/ -----| rb1
10k swB
; ============= new select values for counter setup ==============
;code below is used for the 2 switches
; initiate strttmr from input pins & lookup table
movf PORTB,w ;get values of RB0 & RB1
andlw 0x03 ; extract out bits 0,1 of PORTB
(strttmr value)
CALL table ; use look up table
movwf strttmr ;move selected value from table to
strttmr
table addwf PCL,f
retlw d'25' ; 00 = 250ms (switch position
1)
retlw d'50' ; 01 = 500ms (switch position
2)
retlw d'75' ; 10 = 750ms (switch position
3)
retlw d'100' ; 11 = 1000ms (switch position
4)
where am i going wrong please ?
thanks very much for your help
i appreciate it
glen
1999\04\20@151259
by
Ray Gardiner
<snip>
>
>where am i going wrong please ?
>
>thanks very much for your help
>i appreciate it
>glen
Hi Glen,
I assume that your code does something after the "movwf strttmr"
and doesn't just run off into the "table" subroutine. .. :-)
Otherwise your code looks ok, I suspect that you problem lies in
the way you have connected the switches. The quickest way to confirm
if this is the problem is to measure the voltage when the switches
are operated. You should see less than 0.8V for low and greater than
2.0V for high. Preferably a bit more either way.
Also, to have any chance of that circuit working you would have to
have the "weak-pullups" enabled in the OPTION register.
I would prefer pull up resistors rather than pull down anyway.
And another thing, why have you got the 10k resistor there anyway?
it is not needed for switches. (assuming the weak-pull-ups are enabled).
Ray Gardiner spam_OUTrayTakeThisOuT
hdc.com.au
1999\04\20@222056
by
Glen
|
Ray Gardiner wrote:
> <snip>
>
> >
> >where am i going wrong please ?
> >
> >thanks very much for your help
> >i appreciate it
> >glen
>
> Hi Glen,
> I assume that your code does something after the "movwf strttmr"
> and doesn't just run off into the "table" subroutine. .. :-)
yes ray , "movwf strttmr" does continue on in the program.
> the "weak-pullups" enabled in the OPTION register.
yes they are enabled
> And another thing, why have you got the 10k resistor there anyway?
> it is not needed for switches. (assuming the weak-pull-ups are enabled).
>
i have removed the 10k res.& checked the following
vdd= 5v
low= 0v
high= 1.75v
i have tried the different switch settings but still no change !
" stop press "
i think i've found the problem.
the circuit works when the single strttmr value & no pullups are used.
i am using rb3 to sense the ac line i/p.& synchronise
(i am testing with 16vac till i get the code to work correctly)
but when i get to using the 240v line voltage the same problem would arise,
can't read zero crossing due to pullups!
when i use pullups the prog won't work , because the ac i/p (rb3) doesn't go
down to read a zero
goes no lower than 1.8v
*****************
with this modification using selectable switch values via lookup table
& since i need pullups to work the two switches.
is their a way to code other than to enable pullups to get the switch values
&
then disable rb3 pullup
so rb3 can sense line & synchronise(able to read zero crossing)
heres the code (lookup table only included in sub routines)
; vars
PORTA equ 0x05 ;CPU equates (program memory map)
PORTB equ 0x06 ;CPU equates (program memory map)
souter equ 0x0c ;
sinner equ 0x0d ;
inners equ 0x0e ;
outers equ 0x0f ;
innerf equ 0x10 ;
outerf equ 0x11 ;
chkcnt equ 0x12 ;
strttmr equ 0x13 ; no of counts
switch equ 0x14 ;
STATUS equ 0x03 ;CPU equates (program memory map)
w equ 0 ; destination designators
f equ 1 ; destination designators
;**********************************************************************
; porta set-up
org 0x000 ;address 000 program start
start movlw 0xff ;ff hex moved to w register
tris PORTA ;porta set as inputs
;
;**********************************************************************
; PORTB set-up
movlw 0x0f ;00001111 hex moved to w register
tris PORTB ;PORTB set o/p's 4,5,6,7,inputs 0,1,2,3
;
;**********************************************************************
clrf STATUS
; ============= prescaler setup ==============
movlw b'01000111' ;scale 1:256 , pullups enabled
OPTION
; ============= counter setup ==============
;code below is used for 2 switches
; init strttmr from input pins
movf PORTB,w ;get values of RB0 & RB1
andlw 0x03 ; extract out bits 0,1 of PORTB
(strttmr value)
CALL table ; use look up table
movwf strttmr ;move selected value from table to
strttmr
;**********************************************************************
; ============== program start =============
movlw 0x00 ;move 00 hex to register w
movwf PORTB ;move register w to PORTB (clear PORTB)
; ============= initialise timer setup ==============
initmr movlw .215 ;40 * .000256 = 10 ms
movwf TMR0
loop CALL chcycs ;check for zero crossing
CALL sttimer
CALL tog
; ============= check timer ==============
movf TMR0,w ;move f reg to w
btfsc STATUS,Z ;if !0 ,GOTO loop
GOTO loop
decfsz strttmr,f ;decrement strttmr by 1
GOTO initmr ;go around for next delay
;drop thru to stop
stop GOTO stop
;=======================================================================
; delay sub-routine
table addwf PCL,f
retlw d'25' ; 00 : 250ms (switch position 1)
retlw d'50' ; 01 : 500ms (switch position 2)
retlw d'75' ; 10 : 750ms (switch position 3)
retlw d'100' ; 11 : 1000ms (switch position 4)
thanks for your help ray
it's very kind of you
glen
More... (looser matching)
- Last day of these posts
- In 1999
, 2000 only
- Today
- New search...