PicBasic Lookup command


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108

    Default PicBasic Lookup command

    I have a little snippet of code where I lookup a value and send it to PortA (Lolite=PortA) of my PIC16F887. Here is the code:
    For d = 0 To 7
    Lookup d,[$1,$3,$7,$f,$1f,$3f,$7f,$ff],out
    Lolite=out
    pause 100
    Next d

    -My variables are declared
    Using the debugger in MicroCode Studio:
    -Var "out" has proper value inserted for each value of "d"
    -Lolite DOES NOT equal out.

    For the first 4 or 5 values of d, Lolite =0, then for the next value of d, it jumps to $10.

    Why, oh why, oh why?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Is Lolite a Byte or Word?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Lolite is a byte.

    I looked at that...but I don't see anything wrong. Lolite is a byte, out is a byte and all the values are bytes.

    What am I missing?

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Weird, have you tried on a stripped version of your codeÉ

    Could you post the whole thing here?

    Assuming Lolite is an alias to PORTA, have you disable the analog and/comparator on PORTA ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Here is the "complete" code. This is a test area where I have all my equates and variable declarations for a bigger code, but I check little pieces at a time. The piece I'm checking now is the "snippet" I showed in previous post.


    ; Define LOADER_USED to allow use of the boot loader.
    Define LOADER_USED 1

    ;Aliases use Var, symbols use = sign
    ;Code D,C,B, A in that order, from Snowflake to Arm to Light

    ;SNOWFLAKES
    East Var PortD.0 ;Use Port D for Snowflakes and background
    Cent var PortD.1 ;connect to enable line of 74373 latches
    West var PortD.2
    Back Var PortD.3 ;likely always set to "on" to keep background lit

    ;ARMS
    Blu var PortC.0 ;Use Port C bottom nibble for arms
    Org var PortC.1
    Red var PortC.2
    Grn Var PortC.3
    Armson var PortC
    Armsoff var PortC
    ;LIGHTS
    LoLite var PortA
    HiLite var PortB

    L0 Var PortA.0
    L1 var PortA.1 ;Low Lamps 0-7 Lo.0=first inside, using port A
    L2 var PortA.2
    L3 var PortA.3
    L4 var PortA.4
    L5 var PortA.5
    L6 var PortA.6
    L7 var PortA.7

    H0 VAR PortB.0
    H1 VAR PortB.1
    H2 VAR PortB.2
    H3 VAR PortB.3 ;High lamps 8-11 Hi.11=last outside, using port B

    x var byte ;index variable for low lamps 0-7
    y var byte ;index variable for high lamps 8-11
    del var byte ;use var Word if value>255
    d var byte
    out var byte


    ;****************Program Start******************
    Initialize:

    TRISA= %00000000 ;set portA to all output
    TRISB= %00000000 ;set PortB to all output
    TRISC = %00000000 ;Set PORTC to all output
    TRISD= %00000000 ;Set PortD to all output
    Low Blu
    Low Org
    Low Red
    Low Grn
    LoLite=0
    HiLite=0
    low east ;initialize
    low cent
    low west
    ;high east
    High Cent
    ;High West

    ;Armson=$0F ; all arms on, same as High Blu, High Red, etc
    ArmsOff=$00; all arms off
    d=0

    Main: Gosub growspin
    goto main

    ;*********************Subroutines***************** **********


    growspin:For d = 0 To 7
    Lookup d,[$1,$3,$7,$f,$1f,$3f,$7f,$ff],out
    Lolite=out
    pause 100 ;first 8 in about 2/sec for pause=100
    Next d ;entire snowflake in about 1 sec
    ;For d = 0 To 3
    ;Lookup d,[$1,$3,$7,$f],out
    ;Hilite=out ;
    ;pause 100 ;
    ;Next d
    ;pause 500 ;hold all at end for 1/2 second
    LoLite=0
    Return

  6. #6
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    I figured it out. Not having played with too many CPU/MPU/MCU that are multi purpose I was not aware that the port could be analog or digital
    Initializing Ansel to 0 fixed the problem. The code works now.
    Thanks for reading this and attempting to help me.
    Reading the spec sheet (all of it), triumphs again!!

  7. #7
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Okay, one problem solved...now another. I'm using RA6 and RA7 and want to use the internal oscillator. I think I have to set bit 2 of CONFIG1 to 1 in order to select INTOSCIO.
    I tried config1= config1|%00000100 (|= OR) but I get a compile error. I can't find anything via Google, via other programs on how to do this.
    I'm using PIC Basic Pro. I don't want to disturbe the other bits, which is why I'm using OR.

    anyone?

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command update: hardware problem

    I had tried everything to get RA6 and RA7 working and when they were not (by noting the lights connected to these pins were not lighting up) I started poking around first with my logic probe, and then my oscilloscope. Would you believe it? The two signals WERE coming out of the MCU to my breadboard, and through the interface chips, but not at the end of my 4 foot ribbon cable. That's right, the signals I was looking for were there, but I had a HARDWARE problem! I had tested the cable out previously, ringing it out with an ohmmeter, but by scoping it I could see the signal wasn't getting through the 16 pin ribbon connector cable. A couple quick squeezes with pliers fixed the problem.

    Long time ago a colleague would use the term "check the wiring" for every little problem that came up. I laughed at him...

    Thanks to those who responded. Oh, btw, I didn't need to change the config bits.

  10. #10
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    I have something strange with loockup command. I play with a RC transmitter...
    If I turn on the pic with signal>185 then duty = 0 ; then I reduce the signal value under 185 , then duty=divf
    If I move quickly the transmitter-stick (signal from 150 ) to maximum (200) I obtain random different values for duty, like 250 ,191, 90, 223 and sometime 255.
    If I move slow the transmitter-stick , then duty = divf all time, so work perfectly.

    Can somebody explain me whats happen here , please ? I'm very confused..!!

    Code:
    #CONFIG
        __config _CONFIG1, _FOSC_INTOSC & _MCLRE_OFF & _CP_ON & _CLKOUTEN_OFF
        __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
    #ENDCONFIG
    
    DEFINE OSC 4
    OSCCON = %01101000
    @ ERRORLEVEL -306   ; turn off crossing page boundary message
    include "lcd.bas"
    ADCON0 = %00000000   
    ADCON1 = %00000000     
    CM1CON0 = 0   ' COMPARATORS OFF
    CM1CON1 = 0
    CM2CON0 = 0   ' COMPARATORS OFF
    CM2CON1 = 0    
    CPSCON0 = 0   'CAPACTIVE SENSE MODULE OFF
    RCSTA.7 = 0   'SERIAL PORT OFF
    
    OPTION_REG.7 = 1 'DISABLE PULL UP
    
    TRISA  = %00000000
    TRISB  = %00000000
    TRISC  = %00000000
    
    ANSELA = %00000000
    ANSELB = %00000000
    
    PORTA  = %00000000
    PORTB  = %00000000
    PORTC  = %00000000
    
    WPUB   = %00000000 
    LATC   = 0
    
    divf   var byte : divf = 0
    signal var byte
    value  var byte : value =0
    duty   var byte : duty = 0
    
    gosub lcdrst:pause 300
    
    main:
    pulsin portb.0 , 1 , signal
    if signal > 185 then signal = 185
    
    if signal > 160 then
        value = (signal - 160) ' value max 25  
        lookup value ,[0,30,40,50,65,80,90,100,117,136,153,168,180_
                     ,191,201,209,217,223,233,237,241,244,247,250,255],divf                            	                     
    else                 
        divf  = 0
        value = 00
    endif
    if duty <> divf then duty = divf
         
    lcdout $fe, $80 , "Value = " , dec3 value
    lcdout $fe, $C0 , "DUTY =  " , dec3 DUTY
    
    goto main
    
    '-------------------------- LCD ----------------------------- 
    lcdrst:
    lcdout, $fe, 1
    pause 10
    return

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,569


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    If I turn on the pic with signal>185 then duty = 0 ; then I reduce the signal value under 185 , then duty=divf
    The first value in the LOOKUP table is returned when value is 0. You have 25 entries in the table so value should range from 0 to 24. When signal is >185 value is 25 which points outside of the table in which case divf remains unchanged - so if this is at startup it remains at 0.

    If I move quickly the transmitter-stick (signal from 150 ) to maximum (200) I obtain random different values for duty, like 250 ,191, 90, 223 and sometime 255.
    If I move slow the transmitter-stick , then duty = divf all time, so work perfectly.
    This I don't think has anything to do with the LOOKUP command. Have you looked at the actual pulses being measured by the PIC, is it possible that they actually ARE varying in widht (due to noise in the stick or whatever) and that the PIC is doing exactly as it should?

    /Henrik.

  12. #12
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Thank you very much for explanation , Henrik....
    .
    The pulses are 100% ok , I verified with a osciloscope,
    Last edited by midali; - 18th June 2016 at 21:35.

  13. #13
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    SOLVED !
    1000 x thanks , HENRIK

    I modified the the loockup table :

    Code:
    lookup value ,[30,40,50,65,80,90,100,117,136,153,168,180_
                     ,191,201,209,217,223,233,237,241,244,247,250,255,255,255],divf

  14. #14
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,569


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    OK, are you saying that the randomness when moving the stick quickly is gone as well? I didn't expect that....

    /Henrik.

  15. #15
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Now all are ok !

  16. #16
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: PicBasic Lookup command

    Now all are ok! The problems was from lookup table, was missing one value.

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts