PDA

View Full Version : Can some one please check my code out thanks



Jhdgkss
- 7th February 2006, 12:56
Hi there this is my first real bit of codeing for pic basic pro.
Can some one please look over it for me and see if there are any mistakes or have any advice regarding it thank you

The idea of the code is to control two pwm signals and output the result for a servo.
When input one is in use it will control the output but when not in use ie in the neutral position of 1.5ms pulses then input 2 controls the output.

when here is the code

'servo control prog

'set variables

ch1 var byte
ch2 var byte

s1 = 150

start:

if ch1 < s1 then output1
if ch1 > s1 then output1
if ch1 = s1 then output2


output1:

pulsout portb.3,ch1
pause 18
goto start

output2:

pulsout portb.3,ch2
pause 18
goto start

end

Jhdgkss
- 7th February 2006, 21:23
Any one?? care to look

Ioannis
- 8th February 2006, 08:15
I think you should find a way to give a value to var ch1. As it is it will get a random number on startup.

Ioannis

Jhdgkss
- 8th February 2006, 16:36
thanks for the reply i have just seen my mistake thanks really it shound look like this then?

'servo control prog

'set variables

ch1 var byte
ch2 var byte

s1 = 150

start:

pulsin portb,1,Ch1
pulsin portb,2,Ch2

if ch1 < s1 then output1
if ch1 > s1 then output1
if ch1 = s1 then output2


output1:

pulsout portb.3,ch1
pause 18
goto start

output2:

pulsout portb.3,ch2
pause 18
goto start

end


Secound question how do i subsitue ch2 for a pot instead of a pwm signal would it look like this

potportb.2,200,var

would this give me the correct value to output to a servo?

Ioannis
- 9th February 2006, 08:08
You may have to give us more details of what you are trying to accomplish. No one would "play" with you and build command by command your code or what evere.

Give more input. What is you input signal. Is it Pulse? Is it from a PC? Is it from a pot?

You are not clear. I said that your variable would need a value. Pulsin would give a value to ch1 but is it what you really want to do?

Ioannis

Jhdgkss
- 10th February 2006, 08:19
Hi there thanks for your help i have anouther thread running in this same fourm its called How would i write this in pic basic pro (Servo controller)

thanks