I'm trying to control a servo using Great Cow Basic (GCBasic). I will be using the PIC18F4520 to control the servo.
So far, I have the following code which I have ported from BASIC Stamp code that does work:
Code:
#chip 18f4520, 4
dim Cnt as word
dir PORTB.0 OUT
do
'Counterclockwise:
FOR Cnt = 1 to 20
pulseout PORTB.0, 1000 ms
wait 20 ms
NEXT
'Center:
FOR Cnt = 1 to 20
pulseout PORTB.0, 750 ms
wait 20 ms
NEXT
'Clockwise:
FOR Cnt = 1 to 20
pulseout PORTB.0, 500 ms
wait 20 ms
NEXT
loop
However, the above code only makes the servo turn clockwise in even interval.
Please provide some code that could make a servo work correctly on GCBASIC. Everything compiles correctly, I'm sure the Micro controller and the servo are working. I even tried the code in ISIS simulator and get the same results as in real life.
Thanks for the response, but I tried what you said about changing the loop time and it still works the same way, only a bit slower. I also tried OSCCON = 0x62, still get same results.
The compiler already knows it's running at 4 MHz, hence
The Pulseout command would be a one-shot turn this pin on for xxxx wait/delay cycles, then turn off. So 100 10us is the same as 1000us without the overhead of word sized assembler instructions (presuming that a variable will be used on down the road). Also a fast clock (i.e. 20 Mhz) will be needed if variables will be used in conjunction with us wait/delay variables.
Sorry that I did not explain that well enough, check the GCBasic help file here on PulseOut. To put it another way, there is only one pulse, per PulseOut command. To do Qty (100) 10us PulseOuts then:
Code:
For count = 1 to 100
PulseOut PortB.0, 1 10us
next
These statements are all equivalent in GCBasic:
Code:
PulseOut PortB.0, 1 ms
PulseOut PortB.0, 100 10us
PulseOut PortB.0, 1000 us