User manual

20
5.3 USART Driver for GPS module:
The PIC microcontroller uses UART2 to read NMEA messages from the GPS module on board.
We have developed a parser for NMEA messages to extract the necessary information from the
message. First the RMC and GGA messages are isolated in a buffer and then parsed separately
using the funtions ParseGGA() and ParseRMC().
The information extracted is stored in the following variables/structs:
UtcTime utcTime;
Latitude latitude;
Longitude longitude;
GPSDate gpsDate;
GPSDate rtcDate;
uint8_t fixQuality;
uint8_t satellitesCount;
GPSSpeed gpsSpeed;
GPSHeading gpsHeading;
GPSAltitude gpsAltitude;
Please refer to the code in app.h for more details about these structs.
The state machine is maintained using the function APP_Tasks_GPS(). Please refer to it for
more details on the implementation.
5.4 SPI Driver for the MCP3910:
The PIC microcontroller uses SPI driver (SPI_ID_4) to read analog inputs from the channels CH0
and CH1 on the MCP3910 which are mapped to pins CI1+ and CI1- for CH0 and CI2+ and CI2-
for CH1.
The channels can be used as current measurement as well.
The reading range of these ports is -0.6 to 0.6
The state machine configures the MCP3910 in the beginning and then reads the analog inputs at a 1
second interval. Before starting any communications with the device, ADC_Select pin must be cleared.
This action is performed by PLIB_PORTS_PinClear(ADC_Select). The pin ADC_CS should be cleared right
before writing to and reading from the SPI buffer and should be set high right after the completion of
the operation. For every successful completion of read/write, an event is thrown by the SPI module
which can be handled in APP_BufferEventHandlerSPI1(DRV_SPI_BUFFER_EVENT buffEvent,
DRV_SPI_BUFFER_HANDLE hBufferEvent, void* context )
The readings have 24bits resolution. The 24 bits resolution measurements are stored inside
the variable appData_MCP3910.adcSamples. Current measurement is done by converting this
measurement to mV reading and then dividing by the resistor value used as shown in the
following formula which was obtained from the MCP3910 datasheet:
appData_MCP3910.adcMeasurement = (((appData_MCP3910.adcSamples * (MCP3910_VREF)) /
(12582912.f))/MCP3910_Resistor)*1000;
The state machine is maintained using the function APP_Tasks_MCP3910(). Please refer to it for
more details on the implementation.