I need help


Closed Thread
Results 1 to 6 of 6

Thread: I need help

  1. #1
    Join Date
    Aug 2008
    Posts
    81

    Default I need help

    Hello
    I need help
    I need to send temperature data to the PC
    And receive PC data to drive 2 relays
    More when I send the data the program crashes
    I'm using timerout
    When I send data to relay to it hangs
    Thank you


    Code:
    LOOP_PRINCIPAL:
      
    
    Serin2 RX_IN,84,1000,TIMEOUT,[WAIT("CMD"),RX]
    
    SELECT CASE RX
    CASE "A"                        
        HIGH RELE1        
    CASE "B"
        LOW RELE1
    CASE "C"
        HIGH rele2
    CASE "D"
        LOW rele2
    END SELECT
    PAUSE 300
    GOTO LOOP_PRINCIPAL   
    
    
    TIMEOUT:
      
    'DS18B20 
        'OWOUT DQ,1,[$CC, $44] 'Start temperature conversion
        'pause 1000
        'OWOUT DQ,1,[$CC, $BE]  'Read the temperature
        'OWIN DQ,0,[temperature.LOWBYTE,temperature.HIGHBYTE]
        'temperature = temperature*/1600
        'Serout2 XT_OUT,84,[DEC2 (temperature/100),".",DEC2 temperature,13,10] 
    'GOTO LOOP_PRINCIPAL   
    '----------------------------------

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: I need help

    When it times out, it will fall straight through to whatever garbage is in the chip, you have remmed out any code after the label "TIMEOUT", you need to un-remark 'GOTO LOOP_PRINCIPAL at the bottom of your code you show.

  3. #3
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: I need help

    Hello Aerostar all right
    IM sorry
    I fix the program even so it hangs when they procure I send commands to the relay of the drive has time to work and time not
    thank you

    [CODELOOP_PRINCIPAL:

    Serin2 RX_IN,84,1000,TIMEOUT,[WAIT("CMD"),RX]

    SELECT CASE RX
    CASE "A"
    HIGH RELE1
    CASE "B"
    LOW RELE1
    CASE "C"
    HIGH rele2
    CASE "D"
    LOW rele2
    END SELECT
    PAUSE 300
    GOTO LOOP_PRINCIPAL


    TIMEOUT:

    'DS18B20
    OWOUT DQ,1,[$CC, $44] 'Start temperature conversion
    pause 1000
    OWOUT DQ,1,[$CC, $BE] 'Read the temperature
    OWIN DQ,0,[temperature.LOWBYTE,temperature.HIGHBYTE]
    temperature = temperature*/1600
    Serout2 XT_OUT,84,[DEC2 (temperature/100),".",DEC2 temperature,13,10]
    GOTO LOOP_PRINCIPAL

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: I need help

    I've already said in other posts that I'm no expert, but I'm sure I'm missing something here...

    The manual states
    SERIN2 DataPin{\FlowPin},Mode,{ParityLabel,} {Timeout,Label,}[Item...]
    Taking your line of code
    Serin2 RX_IN,84,1000,TIMEOUT,[WAIT("CMD"),RX]
    So RX_IN is the pin, 84 is mode (which equates to 9600 baud rate ?), and then your have the optional parity and time out labels.

    The manual states
    An optional Timeout and Label may be included to allow the program to continue if a character is not received within a certain amount of time. Timeout is specified in units of 1 millisecond. If the serial input pin stays idle during the Timeout time, the program will exit the SERIN2 command and jump to Label.
    So I'm guessing that the code loops through your LOOP_PRINCIPLE main program, reads the serial pin, if it finds no data, jumps out to the timeout subroutine to read the temperature and send that via serial (which I'm guessing is connected somehow to a PC running a terminal applications ?), then jumps back to the main loop. However if the code detects an A,B,C,D it then sets or releases a relay connected to the pins RELE1 and RELE2.

    I'm just wondering if the code is running too fast.. I use HSERIN on my projects, but I'm sure that's not relevant to this, and the code can be used with a SERIN pin / command

    Code:
    FOR TempWD = 0 TO 500
        IF RCIF=1 THEN GOSUB coms                   ; Check to see if PC application connected
        PAUSE 1
    next TempWD
    This is the routine I use to check for a character from the PC application sent to the com port.

    Prior to this I have a flag variable
    Code:
    RCIF                VAR PIR1.5                    ' USART receive flag
    The case select is then handled by

    Code:
    coms:
    
    HSERIN [nTest]
        SELECT CASE nTest
        CASE "Q"                    ; if Q then send data to PC
        Goto Term_TX 
        CASE "S"                    ; if S then receive data from PC
        goto Term_RX
    return
    This is basically the reverse of your code, in that you can have the main loop running the read temperature and sending the results out, but each time the loop runs it checks the serial port, and only jumps to the relay section if it finds an ABC or D in the buffer and placed into the RX variable...

    Like I said, I'm no expert, and your code may need to run at a higher speed than the projects I've worked on, but maybe you can pull something from the suggestions and it will stop it locking up

  5. #5
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: I need help

    Probably a stupid question but in the following lines temperature is broken into a lowbyte and highbyte. Assuming you've got temperature defined as a WORD, does PBP automatically meld these two bytes together to make a WORD? I thought you had to kinda build the word or specify which byte you want to use.

    OWIN DQ,0,[temperature.LOWBYTE,temperature.HIGHBYTE]
    temperature = temperature*/1600

    Hoping I'm not too far out in left field.

  6. #6
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: I need help

    Hello thanks for the reply
    I made a modification to the program for USART 9600
    I made a correction in the temperature of the program now everything is normal functioning
    Thank you

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