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
Bookmarks