Searching \ for 'specific lookup table value ??' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/mems.htm?key=table
Search entire site for: 'specific lookup table value ??'.

Truncated match.
PICList Thread
'specific lookup table value ??'
1999\04\21@031954 by Glen

flavicon
face
hi & sorry again !
i don't know how to get around this problem !!
i still can't get the table to work properly !

the table puts the first value into strttmr regardless of the switch
settings

**how do i get the switch settings value to access the corresponding
value
in the lookup table & place it into strttmr? ***

eg     switch setting = 1 0  (rb0 = 1 , rb1 = 0 )
table value at 10 = d'75'
put d'75' into strttmr
the problem area is in the section 'select switch setup '
;************************ports setup****************************
;**********************************************************************
        clrf              STATUS
;============= prescaler setup ===pullups enabled===========
        movlw         b'00000111'         ;scale 1:256 , pullups
enabled
        OPTION
;**********************************************************************
;**********************************************************************
; ============= select switch 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
(table sw value)
        movwf     chksw             ;put rb0 & rb1 values in register
chksw

caltab CALL     table                 ; use look up table
        movwf     strttmr             ;move selected value from table
to strttmr
        xorwf       chksw              ;compare with chksw value
(switch value)
        btfsc         STATUS,Z         ;if same , skip next instruction

        GOTO     caltab
;******************TABLE TO GO IN SUB ROUTINES***********************
table addwf         PCL,f            ;sw value : time :
        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)
;**********************************************************************
;**********************************************************************
;       ============== program start =============
       movlw         0x00              ;move 00 hex to register w
        movwf         PORTB             ;move register w to PORTB
(clear PORTB)
;============= prescaler setup ===pullups disabled===========
        movlw         b'10000111'         ;scale 1:256 , pullups
disabled
        OPTION
; ============= initialise timer setup ==============
initmr movlw         .215          ;40 * .000256 = 10 ms
        movwf         TMR0

loop CALL         chcycs    ;check for zero crossing
        CALL         sttimer    ;call initial time delay
        CALL          tog        ;toggle outputs
; ============= 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-routines=======================
;
   end

thanks very much for your help because i'm LOST !!
glen

1999\04\21@041919 by Quentin

flavicon
face
Where is your Tris instruction for PortB?

Quentin

1999\04\21@045516 by Ray Gardiner

flavicon
face
Hi Glen,
I can't follow your code, It wraps around and the formatting
makes it hard to read.  But what little I can decipher I don't
understand what you are trying to do with the "xorwf chksw"

what you have looks like....

caltab
       CALL    table   ; use look up table
       MOVWF   strttmr ; move value from table to strttmr
       XORWF   chksw   ; compare chksw value (switch value)
       BZ      caltab

table
       ADDWF   PCL,f   ; sw value : time :
       RETLW   d'25'   ; 00    : 250ms (switch
       RETLW   d'50'   ; 01    : 500ms (switch
       RETLW   d'75'   ; 10    : 750ms (switch
       RETLW   d'100'  ; 11    : 1000ms (switch

What this will do is as follows, first time correct
lookup value will be returned, and the table will
be re-entered with the return value instead of the
switch value, this will result in a jump past the
end of the table with unpredictable results! :-(

I would suggest the following.

1. Get the hardware working correctly first, you
might have to put a pull down on RB3.

2. Constrain W as follows
table   ANDLW   0x03    ;
       ADDWF   PCL,f   ; sw value : time :
       RETLW   d'25'   ; 00    : 250ms (switch
       RETLW   d'50'   ; 01    : 500ms (switch
       RETLW   d'75'   ; 10    : 750ms (switch
       RETLW   d'100'  ; 11    : 1000ms (switch

3. Check for TMR0 overflow flag rather than looking
at the timer value directly. Better yet handle the
TMR0 overflow in an interrupt.

==============[ original message ]================

{Quote hidden}

Ray Gardiner spam_OUTrayTakeThisOuTspamhdc.com.au

1999\04\21@055435 by Glen

flavicon
face
Quentin wrote:

> Where is your Tris instruction for PortB?
>
> Quentin

thanks for your quick reply Quentin .sorry i didn't put the top part
in.(trisa)
this code works with a single value
"believe it or not "
i just can't get it to select a value in lookup table.
EMAIL ME IF THIS IS BETTER TO READ,USED VAR. WIDTH BEFORE SORRYHERE'S
THE FULL
CODE;**********************************************************************

;   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     ;
chksw        equ     0x12     ;
strttmr      equ     0x13     ; no of counts
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 ===pullups enabled===========

          movlw      b'00000111'       ;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 bits 0,1 PORTB (strttmr sw
value)
         movwf        chksw      ;put rb0 & rb1 values in register
chksw


caltab    CALL         table         ; use look up table
         movwf        strttmr   ;move selected value from table to
strttmr
         xorwf        chksw              ;compare with chksw value
         btfsc        STATUS,Z             ;if yes,skip next
instruction
         GOTO         caltab

;**********************************************************************
;       ============== program start =============

          movlw       0x00      ;move 00 hex to register w
          movwf       PORTB    ;move reg w to PORTB (clear PORTB)

;============= prescaler setup ===pullups disabled===========

          movlw       b'10000111'     ;scale 1:256 , pullups disabled
          OPTION
; ============= 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
          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)

;                       =================
;=============  check start cycle / check finish cycle =============

chcycs      btfsc     PORTB,3   ;check AC input at port b pin 2 for 0
           GOTO      chcycs      ;check again if still high
lw          btfss     PORTB,3     ;check AC input at port b pin 2 for 1
           GOTO      lw          ;check again if still low
           RETURN                 ;found zero crossing - rising edge

;********************* delay sub-routines
*******************************
;
;       ============== start timer =============

sttimer     movlw     0x10         ;move 00 hex to register w
           movwf     souter        ;move register w to "outer"
sout        movlw     0x10         ;move 00 hex to register w
           movwf     sinner       ;move register w to "inner"
sinn        decfsz    sinner,f   ;decrement "inner" each scan, scan for
0
           GOTO      sinn         ;loop "inner" until it = 0
           decfsz    souter,f    ;decrement "outer" each scan, scan for
0
           GOTO      sout         ;loop "outer" until it = 0
           RETURN

;       ==============toggle outputs =============

tog         bsf       PORTB,4      ;set PORTB bit 4 high      }
           bsf       PORTB,5     ;set PORTB bit 5 high      }
           CALL      togs        ;CALLs toggle sub-routine  } Toggle
4/5
           bcf       PORTB,4     ;set PORTB bit 4 low       }
           bcf       PORTB,5     ;set PORTB bit 5 low      }
           CALL      togf        ;CALL the delay sub-routine
           btfsc     PORTB,3     ;skip next if 0
           GOTO      tog
           RETURN

;       ============== ontime delay =============

togs       movlw      0x2         ;move 00 hex to register w
           movwf     outers      ;move register w to "outer"
outs        movlw     0x2         ;move 00 hex to register w
           movwf     inners      ;move register w to "inner"
inns        decfsz    inners,f    ;decrement "inner" each scan, scan for
0
           GOTO      inns        ;loop "inner" until it = 0
           decfsz    outers,f    ;decrement "outer" each scan, scan for
0
           GOTO      outs        ;loop "outer" until it = 0
           RETURN

;       ============== offtime delay =============

togf        movlw      0x1          ;move 00 hex to register w
           movwf      outerf             ;move register w to "outer"
outf        movlw      0x1          ;move 00 hex to register w
           movwf      innerf       ;move register w to "inner"
innf        decfsz     innerf,f    ;decrement "inner" each scan, scan
for 0
           GOTO       innf       ;loop "inner" until it = 0
           decfsz     outerf,f   ;decrement "outer" each scan, scan for
0
           GOTO       outf       ;loop "outer" until it = 0
           RETURN
;**********************************************************************
           END                     ; directive 'end of program'

THANKS FOR YOUR PATIENCE & TIME
glen

1999\04\21@064550 by Glen

flavicon
face
thanks for your quick reply Ray .

I REALLY APPRECIATE IT & YOUR EFFORT TO HELP !!
i,ve answered your questions & the full code is below
i was using variable width before which i think is the prob.
let me know if it isn't
==========================================
Ray Gardiner wrote:

{Quote hidden}

==============================with xorwf     i was trying to get the switch
value into chksw ( get switch value)& the corresponding table value into
strttmr ( start timer)
compare if correct and use that correct value in strttmr for the timer
============================

{Quote hidden}

if i remove everything from caltab to table ( all above ) & put in
movlf     d'25'        :counter value
       movwf    strttmr

the program works ' believe it or not ' !
==========================

> I would suggest the following.
>
> 1. Get the hardware working correctly first, you
> might have to put a pull down on RB3.
> =====================================

** this code works with a single value in "strttmr"
"believe it or not "tested on simstick" - dontronics

** i turn the pullups on to get the switch settings then off again
at powerup because once i get that setting i don't need the switch anymore

===============================
i didn't know how to do it !
==============================

{Quote hidden}

************************i don't know how to do interupts .
i haven't been doing this for very long !
******************************
HERE'S THE FULL CODE

{Quote hidden}

1999\04\21@114804 by Ray Gardiner

flavicon
face
Hi Glen,  Seeing the full code clarifies a few things, that
were confusing before. I walked through the code and inserted
alternative bits and pieces, there a number of potential
gotcha's..

<snip>
{Quote hidden}

I would insert the following here as a matter of course...

              GOTO      start
              org       0x04
              GOTO      start
              org       0x10

>> start       movlw     0xff   ;ff hex moved to w register
>>             tris      PORTA  ;porta set as inputs
>> ;***********************************************************
>> ; PORTB set-up
>>             movlw      0x0f     ;00001111
>>             tris       PORTB    ;PORTB
>> ;***********************************************************
>>            clrf          STATUS

At this point I would also add initialization of PCLATH

             CLRF       PCLATH

This may be part of your problem since when a computed goto is
used like "ADDWF PCL" the top few bits of the calculated address
come from PCLATH.. could be worth checking further..

>> ;============= prescaler setup ===pullups enabled===========
>>
>>            movlw      b'00000111'    ;scale 1:256 , pullups enabled
>>            OPTION

I would have just done...
             MOVWF    OPTION_REG

{Quote hidden}

You could insert a hardware test here to confirm the actual values
being read by on RB0,RB1 copy the bits actually read to the LEDS on
RB4 and RB5

            BCF       PORTB,4   ; default to off
            BCF       PORTB,5

            BTFSC     chksw,0   ; copy 0 to RB4
            BSF       PORTB,4

            BTFSC     chksw,1   ; copy 1 to RB5
            BSF       PORTB,5

hang         goto      hang

Obviously, once you get this part correctly reading the switches
you can delete the test code.

>>
>>
>> caltab    CALL      table     ; use look up table
>>           movwf     strttmr   ;move selected value from table to strttmr
>>           xorwf     chksw     ;compare strttmr with chksw value
>>           btfsc     STATUS,Z  ;if yes,skip next instruction
>>           GOTO      caltab
>>

Rewriting this, I would prefer something simpler like...

            CALL  table
            movwf strttmr

Repeatedly looping around ain't going to change the lookup table!


{Quote hidden}

This is a very unreliable way of checking TMR0 overflow, why not
something like..

             BTFSS       INTCON,T0IF
             GOTO        loop
             DECFSZ      strttmr,f
             GOTO        inittmr

>>  ;drop thru to stop
>>
>> stop       GOTO        stop

>> ;=======================================================================
>> ;                       delay sub-routine
>>
>> table

Insert the following belts and braces code....

             ANDLW       0x03
             CLRF        PCLATH   ; just being paranoid!

Be carefull if this code is assembled in some page other than page 0
There a better ways of doing tables that take care of paging problems


             addwf       PCL
{Quote hidden}

I assume the hardware interface to the AC input works, if it doesn't then
the above code will of course hang!  A more robust version would perhaps
measure the time between successive zero crossings and do something
sensible if it waited too long? Kind of depends on the exact application.

{Quote hidden}

For readability and generality why not make it a 16 bit countdown
rather than inner/outer loop presets.


{Quote hidden}

It would be a bit nicer to make use of a generic TMR0 delay, but
no reason why that code shouldn't work..



Ray Gardiner .....rayKILLspamspam@spam@hdc.com.au

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...