Degrees Celsius = 0.0512 ADC_VAL 20.5128
Naturally, we can easily convert the Celsius temperature
value to Fahrenheit. I wrote a little diddy that reads the
ENV-TMP, performs the Celsius calculation, and spits out
both Celsius and Fahrenheit temperature values:
done = adc_done();
done = adc_done();
tempmv = read_adc();
tempmv *= 0.805664;
tempC = 0.0512 tempmv - 20.5128;
tempF = (1.8 tempC) + 32;
printf(“Temp F = %3.2f \r\n”,tempF);
printf(“Temp C = %3.2f \r\n”,tempC);
The raw temperature count is stored in the tempmv
floating point variable. The PIC’s ADC is referenced to Vcc
and GND, with Vcc coming in at 3. 3 VDC. That puts each
step of the microcontroller’s 12-bit ADC at .0008056664
volts. We must convert the raw temperature count to
millivolts to use the ENV-TMP’s Celsius temperature formula.
So, we multiply the ADC step voltage by 1,000 and multiply
the new step voltage with the raw count value contained
Now, we’re ready to plug our newly calculated tempmv
into the ENV-TMP formula. The calculated Celsius
temperature value is stored in the tempC floating point
variable. Using the standard Celsius to Fahrenheit
conversion formula (Degrees Fahrenheit = ( (1.8 tempC) +
32), we compute a Fahrenheit temperature value and store
it in the tempF floating point variable.
We can use the sprintf instruction to prepare the
floating point temperature readings for insertion into an
array. The printf instruction allows us to display or transmit
the temperature data using the PIC18F46J13’s USART.
Securing the Data
SDO = MISO
SDI = MOSI
SCHEMATIC 1. The tri-state buffer is optional. However, if you
have several devices on the same SPI bus, it becomes essential.
The data that emanates from the PmodGPS
is Excel spreadsheet-ready. The commas that
separate the data fields in the GPS sentences are
used to place each data set in a spreadsheet cell.
If we were to collect the GPS sentences into a file
and name the file gpsdata.csv, Excel would open
the file and automatically import the data into
separate cells of a worksheet.
This type of file is called a Comma Separated
Values file (CSV). We can also CSV-format our
temperature data to match that of the PmodGPS.
I’ve already given you the hardware and
firmware keys to the microSD card interface. I
used the same EDTP microSD hardware interface
that I described in detail in the December 2010
issue of Nuts & Volts.
The microSD hardware is close
up and personal in Photo 4. The
pairs of 10K resistors and 100 nF
bypass capacitors that support the
tri-state buffer IC are graphically
depicted in Schematic 1.
In the December 2010 Design
Cycle, I used the Microchip
Application Libraries to construct
the microSD firmware driver. If
PHOTO 4. This simple little circuit also
seems to fall into a bunch of my
projects. It's a simple design that
pays big benefits. This is a super easy
way to add gigabytes of nonvolatile
storage to your robot's electronic
42 SERVO 01.2013