PDA

View Full Version : serial program and sensor problem



win_832001
- 7th April 2006, 10:18
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

Acetronics2
- 7th April 2006, 13:30
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

win_832001
- 8th April 2006, 06:38
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..

Acetronics2
- 8th April 2006, 09:34
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

win_832001
- 10th April 2006, 04:16
oooo...really..TQ for the reply..i'll try the value for the servo..