Hi, I am fairly new to the GCBASIC compiler, and am having some trouble calling a sub procedure with parameters. I keep getting a missing bit in SET command error, and I am certain it is coming form my sub procedure call.
dir PORTC.2 OUT
Dim pulseAdd As Byte
Dim sethome As Byte
Dim Pulses(10)
Dim Voltage(10)
Dim Index As Byte
Dim inSort As Byte
Dim wait As Byte
pulseAdd = 50
wait=0
Main:
pulseAdd = 50
wait=0
While wait=0
For count=1 To 200 'Set Servo to -45 degree position
PULSEOUT PORTC.2, pulseAdd 10us
Wait 15 ms
Next
Wait 50 10ms
For i=1 To 10 'Set Servo in ten evenly spaced positions From 500us-1900us
ServoPos(ch1, pulseAdd) 'PROBLEM AREA
Wait 25 ms
Pulses(i)=pulseAdd
Voltage(i)=ReadAD(AN1)
pulseAdd=PulseAdd+14
Next
wait=1
Loop
For cntTime=1 To 2
Wait 60 s
Next
wait=0
sub ServoPos(channel, pulsewidth)
For PulseIndex=1 To 60
PULSEOUT channel, pulsewidth 10us
Wait 15 ms
Return
Next
end sub
goto Main
I am certain this is an easy fix, but I couldn't find any thing in my code that went against what was displayed in the documentation. Sorry for the noobish question.
-Michael
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You'll need to use the ch1 constant directly there, instead of the channel variable. It isn't possible to pass a reference to a pin to a subroutine in GCBASIC. To be able to do this, GCBASIC would need to generate some complex assembly code which would be inefficient, and which would use a lot of clock cycles and RAM.
If you need to set several different pins, you could also try doing what I've done in several of the subroutines that are included with GCBASIC - pass a number to the subroutine, and have the subroutine use an IF to set a particular pin. Have a look at the 7segment.h file, or the PWMOut sub in the stdbasic.h file to see an example of this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I am fairly new to the GCBASIC compiler, and am having some trouble calling a sub procedure with parameters. I keep getting a missing bit in SET command error, and I am certain it is coming form my sub procedure call.
'Hardware settings
#chip 16F688, 4
#define ch1 PORTC.2
dir PORTC.2 OUT
Dim pulseAdd As Byte
Dim sethome As Byte
Dim Pulses(10)
Dim Voltage(10)
Dim Index As Byte
Dim inSort As Byte
Dim wait As Byte
pulseAdd = 50
wait=0
Main:
pulseAdd = 50
wait=0
While wait=0
For count=1 To 200 'Set Servo to -45 degree position
PULSEOUT PORTC.2, pulseAdd 10us
Wait 15 ms
Next
Wait 50 10ms
For i=1 To 10 'Set Servo in ten evenly spaced positions From 500us-1900us
ServoPos(ch1, pulseAdd) 'PROBLEM AREA
Wait 25 ms
Pulses(i)=pulseAdd
Voltage(i)=ReadAD(AN1)
pulseAdd=PulseAdd+14
Next
wait=1
Loop
For cntTime=1 To 2
Wait 60 s
Next
wait=0
sub ServoPos(channel, pulsewidth)
For PulseIndex=1 To 60
PULSEOUT channel, pulsewidth 10us
Wait 15 ms
Return
Next
end sub
goto Main
I am certain this is an easy fix, but I couldn't find any thing in my code that went against what was displayed in the documentation. Sorry for the noobish question.
-Michael
The trouble is with this line:
PULSEOUT channel, pulsewidth 10us
You'll need to use the ch1 constant directly there, instead of the channel variable. It isn't possible to pass a reference to a pin to a subroutine in GCBASIC. To be able to do this, GCBASIC would need to generate some complex assembly code which would be inefficient, and which would use a lot of clock cycles and RAM.
If you need to set several different pins, you could also try doing what I've done in several of the subroutines that are included with GCBASIC - pass a number to the subroutine, and have the subroutine use an IF to set a particular pin. Have a look at the 7segment.h file, or the PWMOut sub in the stdbasic.h file to see an example of this.