NEW
Our∧ resident expert on all things
robotic is merely an email away.
roboto@servomagazine.com
Tap into the sum of all human knowledge and get your questions answered here!
From software algorithms to material selection, Mr. Roboto strives to meet you
where you are — and what more would you expect from a complex service droid?
by
Dennis Clark
Q. I use PICBASIC PRO to write my robot programs.
Until now, I’ve just used the serial I/O commands
that will use any I/O pin. I want to use interrupts in
my programs and this will interfere with the bit-banged
serial I/O commands. I have not managed to make this
work yet. How is it done?
— Ed Rupp, CO
A. No doubt you have found the obvious solution to
use the hardware UART, but when using it you
discovered that it spit garbage out the USART port.
This is because PBP defaults all commands and timing to an
assumed 4 MHz oscillator. We usually want our controllers
to run as fast as possible, so 4 MHz isn’t likely our first
choice for a clock speed. The example program that I’ve
included here shows all the obvious settings that show how
to use the USART (HSERIN, HSEROUT), and it shows a
couple that aren’t so obvious. You will need to read the PIC
datasheet to know that at higher clock speeds, you need to
use a different BRG (Baud Rate Generator) divider setting.
Here is the basic (pardon the pun) source code to use
the hardware USART just like the bit-banged ports in PBP:
‘*******************************************************
‘* Name : PBPUSART.PBP *
‘* Author : Dennis Clark for Mr. Roboto column *
‘* June 2008 *
‘* Notice : Copyright (c) 2008 [Dennis Clark *
‘* TTT Enterprises] *
‘* : Feel free to use this any way you want to*
‘* Notes : Faster clocks require different bits*
‘* set in TXSTA *
‘* : register. 2400 is the max baud rate *
‘* at 4MHz. *
‘*******************************************************
INCLUDE M16F6xx.INC
DEFINE HSER_BAUD 9600
DEFINE HSER_RCSTA
DEFINE HSER_TXSTA
DEFINE OSC
‘DEFINE HSER_BAUD 2400
14 SERVO 06.2008
‘ For > 4MHz use these settings
90H
24H
10
‘ For 4MHz, just use this
‘ setting instead
char var byte
Hserout [“HSEROUT working!”, 13, 10] ‘ cr/lf
While 1 = 1
Hserin 10000, timeout, [char] ‘ Get a character
Hserout [char] ‘ Send it back
if char = 13 then ‘ add LF to the CR
HSEROUT [10]
endif
timeout: ‘ we’ll keep resetting to here
when waiting
wend
End
The important part that you may Figure 1. Choose the correct PIC device!
not have found yet
is the HSER_TXSTA
setting. This DEFINE
points to a Special
Function Register in
the USART block TXSTA. The value given here (in hex) tells
the BRG to use the high speed setting. This is NOT done in
the default PBP USART setup because PBP assumes that the
clock rate is 4 MHz unless told otherwise. Don’t forget to
set the correct PIC device type before you download the
code (see Figure 1)!
Q. I have several QRB-1134 IR reflection sensors that
I want to use but I don’t know what resistor values
to use for the LED side or the sensor side. How can
you tell how to set the current or how to read the value
back from the light sensor side?
— George T., via email
A. If you are using QRB-1134s, then I assume you want
to use them as line sensors since they are kind-of
bulky. I love these sensors because they are easy to
mount and are very forgiving in their use (see Figure 2). To