I can not a reading sensor lm35


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2008
    Posts
    81

    Default I can not a reading sensor lm35

    I can not a reading sensor lm35
    could someone help me out here the code I'm using
    I must read 4 sensor lm35

    'USB CDC DEMO sample program for PIC18F4550 CDC serial port emulation
    'Compilation of this program requires that specific support files be
    'available in the source directory.You may also need to modify the
    'file USBDESC.ASM so that the proper descriptor files are included. For
    'detailed information, see the file PBP\USB18\USB.TXT.
    asm
    __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
    __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
    __CONFIG _CONFIG2H, _WDT_OFF_2H
    __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
    __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L

    endasm
    DEFINE OSC 48
    DEFINE LOADER_USED 1
    DEFINE RESET_ORG 1000h 'For Microchip USB Bootloader

    buffer Var Byte[16]
    cnt Var Byte
    sw var byte
    ch var byte
    adval var word 'ADC values 10 bit
    led var portb.0

    'ADC parameters
    DEFINE ADC_BITS 10 'Number of bits in ADCIN result
    DEFINE ADC_CLOCK 3 'ADC clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 'ADC sampling time in microseconds

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00001010 ' Set PORTA analog and right justify result, PORTE digital

    '***** MAIN PROGRAM ******
    START:
    'Initialize
    USBInit
    'Wait for USB input
    idleloop:
    USBService 'Must service USB regularly
    cnt = 16 'Specify input buffer size
    USBIn 3, buffer, cnt, idleloop
    sw = buffer[0]
    'Message received
    Toggle LED

    select case sw
    case "1"
    'Read and send ADC values
    ADCIN 0,adval
    adval = adval*48
    adval = adval/100+1
    pause 50
    ch = "1"
    gosub adc2buff
    case "2"
    'Read and send ADC values
    ADCIN 1,adval
    adval = adval*48
    adval = adval/100+1
    pause 50
    ch = "2"
    gosub adc2buff
    case "3"
    'Read and send ADC values
    ADCIN 2,adval
    adval = adval*48
    adval = adval/100+1
    pause 50
    ch = "3"
    gosub adc2buff
    case "4"
    'Read and send ADC values
    ADCIN 3,adval
    adval = adval*48
    adval = adval/100+1
    pause 50
    ch = "4"
    gosub adc2buff
    end select
    outloop:
    USBService 'Must service USB regularly
    USBOut 3,buffer,15,outloop
    Goto idleloop 'Wait for next buffer
    '*************************************************
    'Subroutines
    Adc2Buff:
    buffer[0]="A"
    buffer[1]="d"
    buffer[2]="c"
    buffer[3]= ch
    buffer[4]="="
    buffer[5]=(adval dig 2)
    buffer[6]=(adval dig 1)
    buffer[7]=(adval dig 0)
    buffer[8]=13
    buffer[9]=10
    buffer[10]=0
    return

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


    Did you find this post helpful? Yes | No

    Default Re: I can not a reading sensor lm35

    So what's the problem, more specifically?
    Does the program and communication work but the ADC does not?
    Is it the math that's the problem?
    Is it a binary/ASCII thing when you're sending the data?

    Posting a chunk of code with a problem description basically saying "it doesn't work" isn't of much use to those taking their time trying to help you - of course it doesn't work, if it did you wouldn't be posting, right?

    So, I'm going to take one shot at it:
    The documentation for USBService says that it needs to be, and I quote, executed at least every 10ms throughout the program. In your Select Case block you have 50ms pauses which violates that requirement straight up.

    But then again, perhaps the communication is working fine and the problem is with the math - what do I know...

    /Henrik.

  3. #3
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: I can not a reading sensor lm35

    Hello
    I think my problem is in the upstream buffer will modify the codes
    Thank you

  4. #4
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: I can not a reading sensor lm35

    Please tell me how to deal with the problem. I can not figure out how to transfer data from USB via variables.As a result, data is received as such, irrespective of the position of the variable resistor connected to the ADC input.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: I can not a reading sensor lm35

    So at this point you know that the USB coomunication is working and that the PIC is sending something, just not the correct stuff? Can you send "Hello World" and have it show up in whatever application it is you're using on the PC?

    I'm not sure the DIG operator returns the ASCII code for the digit. I'd try ArrayWrite Buffer, ["Adc", Ch, "=", DEC3 adval, 13,10,0]

    /Henrik.

  6. #6
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: I can not a reading sensor lm35

    Thanks for the answer
    more still send wrong data
    the PC is receiving a yes "Adc1=[05][06][04]
    [00]|[00]ÿÿ"

    Adc2Buff:
    ArrayWrite Buffer,["Adc","=",DEC3 adval,13,10,0]
    return

Similar Threads

  1. Reading a speed sensor best method?
    By davewanna in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 27th January 2012, 02:37
  2. Tilt Sensor Reading
    By sincity337 in forum Serial
    Replies: 6
    Last Post: - 20th September 2010, 05:23
  3. Need help for reading I2C Sensor
    By Omalik in forum Serial
    Replies: 13
    Last Post: - 10th June 2008, 04:24
  4. Reading a linear hall sensor
    By peu in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd October 2006, 22:31
  5. Sensor reading Program Help Required
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd May 2006, 16:05

Members who have read this thread : 1

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

Posting Permissions

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