serial program and sensor problem


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

    Post serial program and sensor problem

    i need a help here..i have a project that require serial program.the input is from visual basic. so i guess i have to use SERIN command. but then my project has to use as a switch.so,after that there is not require a input from serial but the input is from the switch as a input sensor.i give the program condition IF to run the program. but the program has do not working like that i want.need help please...

    the program should working as above :
    1)initially red LED flashed
    2)after vb send =1 and IRswitch=0 (servo pen and green LEd flashed)
    3)after IRswitch =1 (servo close and green LED-->RED led)- do not require serial input.

    the program that i wrote :

    INCLUDE "modedefs.bas"
    DEFINE OSC 4

    GreenLED VAR PORTB.4
    RedLED VAR PORTB.5
    SerialIn VAR PORTA.4 'serial programming
    IRSwitch VAR PORTB.1 'sensor
    PinState VAR BYTE
    val VAR WORD

    Main:

    val = 0
    SerIn SerialIn,4,[255],PinState

    High GreenLED 'start condition
    Low RedLED 'start condition
    IF PinState=1 AND IRSwitch= 0 Then OpenGate 'when the vb send '1' and the sensor is = 0 (this part working)

    IF IRSwitch =1 Then
    Pause 1000
    GoSub CloseGate 'when the sensor =1 (this part is not working)
    EndIF
    GoSub Main

    OpenGate
    Pause 1000
    Low GreenLED
    High RedLED
    val=0
    For val=0 TO 80 'servo rotation (working)
    PulsOut PORTB.3,150
    Pause 20
    Next val
    GoSub Main

    CloseGate
    Pause 1000
    High GreenLED
    Low RedLED
    For val=0 TO 80 'servo rotation (not working)
    PulsOut PORTB.3,50
    Pause 20
    Next val
    GoSub Main



    -need help here please.TQ

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


    Did you find this post helpful? Yes | No

    Red face RTFM First ...

    Hi, Win

    First :

    Have a closer look to subroutines writing:

    Sub1:

    - what you want
    -
    -

    RETURN

    looks much Better ...

    " For val=0 TO 80 'servo rotation (not working)
    PulsOut PORTB.3,50 "

    are you sure of the 50 value ??? ... I don't really think so.


    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
    win_832001's Avatar
    win_832001 Guest


    Did you find this post helpful? Yes | No

    Question

    TQ for the reply. actually i wrote this program for servo turn from 0 degree-90 degree. and the from 90 degree to 0 back. so the servo is only have to turn like that. so i'm not to modified the servo instead using standard servo.

    for the instruction :
    val=0
    For val=0 TO 80
    PulsOut PORTB.3,150 ' - servo rotate from 0 degree-90 degree

    the problem came on this:
    IF IRSwitch =1 Then
    Pause 1000
    GoSub CloseGate 'when the sensor =1 (this part is not working)
    EndIF
    GoSub Main


    For val=0 TO 80
    PulsOut PORTB.3,50 'servo rotation - servo rotate from 90 degree-0 degree:

    this instruction is working with servo is rotate but the problem is i need to send the data to make the servo run.

    actually, the things that i want is to the sensor =1 and no serial input to make the servo turn.

    tq for help me..

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Unhappy Servo command common values

    Hi, Win

    Servos pulses HAVE to respect those values ...

    700 to 2300 µS high level @ 20 to 60 Hz

    Not to create mechanical or electrical damage.

    Sometimes it's possible to try a wider range, but it doesn't fit all brands ...

    Your 50 value is out of range !!!

    Just try a value in the 70 - 230 range ...

    Note also the " @ 20 to 60 Hz " ... the pulse has to be sent every 50 to 15 ms ...

    Alain

    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 " !!!
    *****************************************

  5. #5
    win_832001's Avatar
    win_832001 Guest


    Did you find this post helpful? Yes | No

    Default

    oooo...really..TQ for the reply..i'll try the value for the servo..

Members who have read this thread : 0

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