PHOTO 3. This temperature probe can be subjected to
harsh environments. The ENV-TMP's watertight construction
allows it to swim. Thus, it’s perfect for monitoring the
temperature of just about any liquid.
character and stuff every incoming byte into the selected
sentence buffer until we encounter 0x0A.
If everything goes right, a single sentence will be
placed in the targeted buffer. Once the sentence is
captured, it can be identified by the three characters that
follow the talker ID (GP). The fields are set for each
sentence type, and we can simply parse the sentence to
obtain the information we want to work with. I assembled
the sentence buffer code using the C switch directive:
bufcntr = 0;
while(1){
switch(bufcntr)
{
case 0:
i = 1;
while(!(CharInQueue()));
data_in = recvchar();
if(data_in == ‘$’)
{
gpsbuf0[0] = data_in;
do{
data_in = recvchar();
gpsbuf0[i++] = data_in;
}while(data_in != 0x0A);
}
if(data_in == 0x0A)
{
bufcntr = 1;
}
break;
Initially, the bufcntr variable is set to zero, which
points to the 128-character array gpsbuf0. It is not
necessary, but we will do it here. We’ll preserve the initial
dollar sign character in the first element of each sentence
array. That’s why you see the i index pointer initialized to 1
instead of 0.
The CharInQueue function blocks the execution of the
program thread. However, the code that makes up the ISRs
(interrupt service routines) is able to execute. Since we’re
prototyping the GPS data acquisition function, at this time
we’ll not write timer/iteration code around the
CharInQueue call to force it to release and allow other code
to execute. Plus, the PmodGPS is streaming in serial data to
the PIC18F46J13’s USART every second.
Once the USART interrupt handler detects and buffers
an incoming character, we use the recvchar function to pull
a character from the tail of the USART_RxBuf array. If the
character we pulled from the receive buffer array happens
to be a dollar sign, we continually pull characters from the
receive buffer until we encounter a linefeed character
(0x0A).
Upon the arrival of the linefeed character, we set the
bufcntr to point at the next gpsbufx array. We continually
perform this process for each of the five gpsbufx arrays.
Here’s the code for populating the second sentence buffer:
case 1:
i = 1;
while(!(CharInQueue()));
data_in = recvchar();
if(data_in == ‘$’)
{
gpsbuf1[0] = data_in;
do{
data_in = recvchar();
gpsbuf1[i++] = data_in;
}while(data_in != 0x0A);
}
if(data_in == 0x0A)
{
bufcntr = 2;
}
break;
A Rugged Robotic
Temp Sensor
I normally employ the services of a Senserion
temperature/humidity sensor for embedded applications.
However, this is a robotic application. So, the temperature
sensor I’ve selected is fit attire for a roving mechanical
meteorologist. The business end of the Atlas Scientific
ENV-TMP is posing for us in Photo 3.
The ENV-TMP is a breeze to use. All we have to do is
supply power to the probe and pick up the temperature
data with the microcontroller’s analog-to-digital converter
(ADC). The red and black wires are the power connections.
The ENV-TMP draws a mere 6 µA.
With current consumption that low, we could use one
of the PIC’s I/O pins to power the temperature probe. The
ENV-TMP’s white wire will feed our microcontroller’s 12-bit
ADC. The temperature is gleaned from the ENV-TMP by
converting the raw ADC count to millivolts.
Once we have a millivolt value, we can call upon the
PIC18F46J13 to substitute it into the ENV-TMP’s
temperature formula as ADC_VAL:
SERVO 01.2013 41