Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic Basic Newbie

Status
Not open for further replies.

SwingeyP

Member
I would normally struggle with assembler to do thsi but having found pic basic i though i'd struggle with that instead ;-)

A couple of questions :

First off what's wrong with this please

Symbol outpin = PORTB.0

Const uplimit = 200 'Set upper limit - max. 255, each step is 10uS
Const downlimit = 100 'Set lower limit - min. 0

Dim pulse As Byte

TRISB = 0xff
pulse = 128 'Set initial value to middle

For pulseup = pulse To uplimit 'move from middle to upper limit'
ServoOut outpin, pulseup
delayms 18
Next pulseup


loop:
For pulsedown = uplimit To downlimit
ServoOut outpin, pulsedown
delayms 18
Next pulsedown

For pulseup = downlimit To uplimit 'move from lower to upper limit'
ServoOut outpin, pulseup
delayms 18
Next pulseup


Goto loop

Secondly has anyone written a plugin for the OSHON simulator to show servo control?

Many thanks - Paul
 
I am not familiar with PicBasic, but looks good. Using TRISB = 0xff "normally" means to make PortB all inputs. Use TRISB = 0x00 to make them all outputs, or TRISB = 0xfe to make all inputs, except PortB.0 as an output.
 
oops - yeah its meant to be output.

I get the following error:

Error line 11: The running variable in For statement must be Byte or Word data type.

Any ideas anyone?
 
and the moral of the story is ..... Read the manual!

Different variations of pic basic etc ... and yes the for next variables needed to be dimensioned too. Makes sense really.

Thanks for your help.

Symbol outpin = PORTB.0

Const uplimit = 200 'Set upper limit - max. 255, each step is 10uS
Const downlimit = 100 'Set lower limit - min. 0

Dim pulse As Byte
Dim pulseup As Byte
Dim pulsedown As Byte


TRISB = 0xff
pulse = 128 'Set initial value to middle

For pulseup = pulse To uplimit 'move from middle to upper limit'
ServoOut outpin, pulseup
WaitMs 18
Next pulseup


loop:
For pulsedown = uplimit To downlimit
ServoOut outpin, pulsedown
WaitMs 18
Next pulsedown

For pulseup = downlimit To uplimit 'move from lower to upper limit'
ServoOut outpin, pulseup
WaitMs 18
Next pulseup


Goto loop


I don't suppose anyone out there has a plugin for demoing servos ...?


Regards - Paul
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top