WHILE WEND and SHIFTIN


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136

    Default WHILE WEND and SHIFTIN

    I'm using: PBPL on a PIC18F1220 and reading data from a SHT15 temperature/humidity sensor. Two issues:

    1. I want the PIC to keep going in the main loop even if the SHT15 is not connected. However, the code includes:

    while DataPin = 0 .... wend
    .........
    while DataPin = 1 .... wend

    So, the loop halts if the sensor does not set/clear the DATAPIN. I guess there is a simple way to fix this - but it escapes me at the moment. Any ideas?

    2. And a speed issue. All works OK with a 20MHz xtal and 'HS' compile. But with an 8MHz xtal and 'HSPLL' the SHT15 gives bad results. All the other routines work OK at 32Mhz and I have tried DEFINE SHIFT_PAUSEUS 1000; this puts the SHIFT clock at <1KHz and the SHT15 is rated to 50KHz - but no luck. Any ideas?

    Regards Bill Legge

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    1. When you are in the while loop, have a time out routine.
    For example, have your PIC timer module set to the time you need. For example, IF TMR1IF THEN Exitloop. TMR1 is preloaded with your required time.

    2. Need to see the code.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    2.
    Do you have
    DEFINE OSC 32
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    Quote Originally Posted by Bill Legge View Post
    I'm using: PBPL on a PIC18F1220 and reading data from a SHT15 temperature/humidity sensor. Two issues:

    1. I want the PIC to keep going in the main loop even if the SHT15 is not connected. However, the code includes:

    while DataPin = 0 .... wend
    .........
    while DataPin = 1 .... wend

    So, the loop halts if the sensor does not set/clear the DATAPIN. I guess there is a simple way to fix this - but it escapes me at the moment. Any ideas?
    How about a pull-up resistor on DataPin?

    2. And a speed issue. All works OK with a 20MHz xtal and 'HS' compile. But with an 8MHz xtal and 'HSPLL' the SHT15 gives bad results. All the other routines work OK at 32Mhz and I have tried DEFINE SHIFT_PAUSEUS 1000; this puts the SHIFT clock at <1KHz and the SHT15 is rated to 50KHz - but no luck. Any ideas?

    Regards Bill Legge
    Need to investigate on that, maybe the PAUSEUS accept up to byte value, if so...mmmm... if this PIC allow to switch to the internal OSC, do it before SHIFTIN, and go back to the external after Shiftin.

    EDIT: The DEFINE should allow you a range of 0-65,535 uSec... so that's strange...
    Last edited by mister_e; - 14th July 2011 at 19:31.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    I suspect the lenght of the clock pulse not being long enough, the frequency should be ok... but the pulse too short for a 50KHz decvice. Maybe one of those roll-your-own thing... or using the OSC switchover thing would work.
    Steve

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

  6. #6
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    Thanks for all your replies.

    1. Mackrackit. Yes, there is a 10k pull-up on the data line.
    2. Mr_e. Yes, OSC 32 is in the code.
    3. Mr_e. OSC switchover to use a slower internal oscillator - how do you do this?

    4. Sayzer. Use a timer interrupt to kill the WHILE. I think this is the best way to go but I'm not clear how to make the interrupt jump over the necessary lines. Can an interrupt direct the execution of the code to a label later in the program? I'd appreciate some advice. I am happy with both PBP and assembler coded interrupts.

    The code bit causing the problem is:
    Code:
     
    ' *****************************************************************************
    ' *                                                                           *
    ' *  READ SHT15. Using default setting of 12 bit humidity,14 bit temperature  *
    ' *  Because of the WHILE statemets, this hangs if the SHT15 is not conected  *
    ' *                                                                           *
    ' *****************************************************************************
    ReadSensor:
     gosub Initialise_SHT15
     gosub Start_Sequence
        shiftout DataPin,Clk,1,[SHTCommand\8]     ' Send command byte %0000000011 or %000000101
        input DataPin                             ' Wait for acknowledge
        low Clk
        while DataPin = 1                         ' Sensor ACK by making Data = 0
        wend
        pulsout Clk,10                            ' Send acknowledge
        while DataPin = 0
        wend
        while DataPin = 1                         ' Wait for conversion to complete
        wend
        low Clk
        shiftin DataPin,Clk,0,[RawData.byte1\8]   ' Get the first byte, 8 bits
        low DataPin
        pulsout Clk,10                            ' Send acknowledge
        shiftin DataPin,Clk,0,[RawData.byte0\8]   ' Get the second byte, 8 bits
        low DataPin
        pulsout Clk,10                            ' Send acknowledge
        shiftin DataPin,Clk,0,[CRCsensirion\8]    ' Get third byte, 8 bits, CRC
        high DataPin
        pulsout Clk,10                            ' Send acknowledge
        input DataPin                             ' End of Transmission
        input Clk
        return
    If anyone is interested, I'm happy to post all the SHT15 code?

    Regards Bill Legge

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


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    check this out
    http://www.picbasic.co.uk/forum/showthread.php?t=4093

    still, an home made shiftin is well under 20 lines of code.
    Steve

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

  8. #8
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    Mister_e
    Thanks for that, I didn't know it was possible.
    Another solution to prevent the code hanging has just occured to me.
    Replace the WHILEs with fixed delays that are equal to the longest conversion time of the SHT15 sensor. I think this will be OK but it seems a crude solution compared with an interrupt?

    Regards Bill Legge

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


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    well if you build your own shiftin routine... you could check the state at each clock pulse... neat too.
    Steve

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

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