Device Compatibility: Sensirion Parallax sensor


Closed Thread
Results 1 to 5 of 5
  1. #1
    embdfreak's Avatar
    embdfreak Guest

    Default Device Compatibility: Sensirion Parallax sensor

    Hi all,
    Im new to this forum and dont have much experience with PBP. Im working on a Sensirion SHT11 Parallax Sensor for temperature/Humidity acq. The problem is, the code gives perfect results when ran on PIC16f84a but gives weird readings if same code is run on a PIC16f877a.
    Following is the code. Please give suggestion to get over this problem.
    Ive modified the code actually presented with the Application note.




    INCLUDE "modedefs.bas"

    DEFINE OSC 4
    ' ------------------------------------------------------------------------------
    ' I/O Definitions
    ' -------------------------------------------------------------------------

    ShtData VAR PORTd.0
    Clock VAR PORTd.1
    ' ------------------------------------------------------------------------------
    ' Constants
    ' -------------------------------------------------------------------------
    ShtTemp CON %00011 ' read temperature
    ShtHumi CON %00101 ' read humidity
    ShtStatW CON %00110 ' status register write
    ShtStatR CON %00111 ' status register read
    ShtReset CON %11110 ' soft reset (wait 11 ms after)

    Ack CON 0
    NoAck CON 1

    No CON 0
    Yes CON 1

    MoveTo CON 2 ' for DEBUG control
    ClrRt CON 11 ' clear DEBUG line to right

    DegSym CON 186 ' degrees symbol for DEBUG

    ' ------------------------------------------------------------------------------
    ' Variables
    ' ------------------------------------------------------------------------------

    ioByte VAR Byte ' data from/to SHT1x
    ackBit VAR Bit ' ack/nak from/to SHT1x
    toDelay VAR Byte ' timeout delay timer
    timeOut VAR Bit ' timeout status

    soT VAR Word ' temp counts from SHT1x
    tC VAR Word ' temp - celcius
    tF VAR Word ' temp - fahrenheit

    soRH VAR Word ' humidity counts from SHT1x
    rhLin VAR Word ' humidity; linearized
    rhTrue VAR Word ' humidity; temp compensated

    PWMvalue VAR WORD


    ' -------------------------------------------------------------------------'Initialization
    ' -------------------------------------------------------------------------

    Initialize:
    GOSUB SHT_Connection_Reset ' reset device connection
    PAUSE 250 ' let DEBUG window open

    GOTO Main ' skip heater demo

    ' ------------------------------------------------------------------------------
    ' Program Code
    ' ------------------------------------------------------------------------------

    Main:
    SEROUT2 PORTA.0,16572,["SHT11 DEMO",13,10] ' 16572 = value for 4800bps

    Main2:
    GOSUB SHT_Measure_Temp
    SEROUT2 PORTA.0,16572,["Temp(C)=",DEC tc/10,".",DEC tC//10," "]
    GOSUB SHT_Measure_Humidity
    SEROUT2 PORTA.0,16572,["Hum(Lin)=",DEC rhLin/10,"%"," "]

    rhTrue=rhTrue/10
    SEROUT2 PORTA.0,16572,["Hum(True)=",DEC rhTrue,"%",10,13]

    GOTO Main2

    END


    ' ------------------------------------------------------------------------------
    ' Subroutines
    ' ------------------------------------------------------------------------------

    ' connection reset: 9 clock cyles with ShtData high, then start sequence
    '
    SHT_Connection_Reset:
    SHIFTOUT ShtData, Clock, LSBFirst, [$FFF\9]

    ' generates SHT1x "start" sequence
    ' _____ _____
    ' ShtData |_______|
    ' ___ ___
    ' Clock ___| |___| |___
    '
    SHT_Start:
    INPUT ShtData ' let pull-up take line high
    LOW Clock
    HIGH Clock
    LOW ShtData
    LOW Clock
    HIGH Clock
    INPUT ShtData
    LOW Clock
    RETURN


    ' measure temperature
    ' -- celcius = soT * 0.01 - 40
    ' -- fahrenheit = soT * 0.018 - 40
    '
    SHT_Measure_Temp:
    GOSUB SHT_Start ' alert device
    ioByte = ShtTemp ' temperature command
    GOSUB SHT_Write_Byte ' send command
    GOSUB SHT_Wait ' wait until measurement done
    ackBit = Ack ' another read follows
    GOSUB SHT_Read_Byte ' get MSB
    soT.HighByte = ioByte
    ackBit = NoAck ' last read
    GOSUB SHT_Read_Byte ' get LSB
    soT.LowByte = ioByte

    ' Note: Conversion factors are multiplied by 10 to return the
    ' temperature values in tenths of degrees

    tC = soT / 10 - 400 ' convert to tenths C
    SEROUT2 PORTA.0,16572,["Temp Form(C)=",DEC tc,10,13]
    tC = soT **$1999 - 400

    RETURN


    ' measure humidity
    '
    SHT_Measure_Humidity:
    GOSUB SHT_Start ' alert device
    ioByte = ShtHumi ' humidity command
    GOSUB SHT_Write_Byte ' send command
    GOSUB SHT_Wait ' wait until measurement done
    ackBit = Ack ' another read follows
    GOSUB SHT_Read_Byte ' get MSB
    soRH.HighByte = ioByte
    ackBit = NoAck ' last read
    GOSUB SHT_Read_Byte ' get LSB
    soRH.LowByte = ioByte


    rhLin= (soRH ** $67AE) - (soRH ** $83 * soRH ** $5B) - 40
    rhTrue = (tC-250) * (soRH ** $34) + rhLin

    RETURN

    ' sends "ioByte"
    ' returns "ackBit"
    '
    SHT_Write_Byte:
    SHIFTOUT ShtData, Clock, MSBFirst, [ioByte] ' send byte
    SHIFTIN ShtData, Clock, LSBPre, [ackBit\1] ' get ack bit
    RETURN

    ' returns "ioByte"
    ' sends "ackBit"
    '
    SHT_Read_Byte:
    SHIFTIN ShtData, Clock, MSBPre, [ioByte] ' get byte
    SHIFTOUT ShtData, Clock, LSBFirst, [ackBit\1] ' send ack bit
    INPUT ShtData ' release data line
    RETURN



    SHT_Wait:
    INPUT Shtdata
    timeout = NO
    For toDelay = 1 TO 250
    if (ShtData = 0) THEN RETURN
    PAUSE 1
    NEXT
    IF ( toDelay = 250 ) THEN timeout = Yes
    RETURN

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink Rtfm ....

    Hi, freak

    You just have to configure the extra registers in your 16F87x ... i.e. choose for digital inputs instead of analog, etc. etc.

    Everything in the chip Databook.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    embdfreak's Avatar
    embdfreak Guest


    Did you find this post helpful? Yes | No

    Default

    well, i dont see anything like analog being used here. or rather i havent understood your answer properly. Can u please explain a bit further on. I truly dont know what to set cuz i have only two lines (data & clock ) to communicate with the sensor and nothing analog. plz have a look at the code and reply

  4. #4
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default By default the inputs are Analogue

    Hi,

    PICs which feature ADC have multiplexed inputs. That is either they go to the ADC or the digital I/O. By default (POR) the inputs are analogue. There are registers to set this according to your app. For your PIC it is the ADCON1

    ADCON1 = %xxxx0110 ' where the x is your own setting turns of the ADC inputs and configures all as Digital I/O.

    Read page 129-130 of your datasheet.
    Regards

    Sougata

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi, SOUGATA

    My inputs work well ... ( set to 7F ... as datasheet tells )

    only the EEPROM is running bad.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42
  2. Watchdog Timers
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th August 2014, 18:03
  3. RF Modules
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 44
    Last Post: - 26th June 2010, 17:42
  4. Sensirion humidity sensor
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 7th October 2008, 15:48
  5. @ Device Parameters
    By Randy_Suwanee in forum General
    Replies: 2
    Last Post: - 11th August 2004, 14:40

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