PicBasic Lookup command


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    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.

Members who have read this thread : 2

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