Special Application Processor (SAP) Series of Microcontroller Modules |
SAPIN3 : 3 Input Serial Converter |
|
Introduction |
||
The SAPIN3 is a microcontroller based
module that converts 2 analog inputs to an 8 bit value, reads a single
digital input, and serially transmits the values at 9600 baud. This simple
device requires only 1 integrated circuit and a handful of discrete
components.
The software is written in C using the CCS PCM C Compiler which is a powerful and cost effective compiler. |
||
Hardware |
||
Hardware Description |
The SAPIN3 uses the PIC12C672 8 pin
microcontroller (U1) from MicroChip (www.microchip.com).
The 4 Mhz ceramic oscillator provides accurate timing for generating the
9600 baud rate. The serially transmitted data is connected from pin 7
(GP0) of the micro through a 220 ohm resistor to pin 2 of the DB9 female
connector. This eliminates the need for a MAX232 type of device.
The 2 a/d inputs are applied to GP1 and GP2. The potentiometers shown are external and provide a 0 to 5 volt input. The single digital input is a pushbutton switch connected to pin 4 (GP3) and pulled up to VCC with a 10k resistor. The 5 volts to power the module is provided by the 7805 type regulator. |
|
|
||
Software |
||
Software Description |
The software is written in C and is contained in the file sapin3.c. There are 2 sections to the file. The first section I consider the header section and contains information on the file such as file name, author, last update, and a description. Compiler information is included also as well as how to compile it. | |
The header portion of the file contains a comment section with file information. The #include <12c672.h> statement includes processor specific definitions. The #use delay statement sets the oscillator value and the #use rs232 statement sets the parameters for the serial port. Notice that only the transmit pin is used and the INVERT qualifier is used to get the level correct for the serial port on the PC to recognize. | //------------------------------------------------ |
|
The main() function contains the application specific code
and is executed from reset after the C startup code is executed. The
program executes the infinite loop contained within the while statement;
while( 1 ) The a/d channels are set as inputs in the set_tris_a statement followed by the statement that controls the delay between sends. The REPEAT_TIME is defined in the header portion of the file and is set to 100 milliseconds. |
//----------------------------------------------- set_adc_channel( 1 ); rad1 = read_adc(); rad2 = read_adc(); |
|
The clock used for the a/d conversion is set to the divide by 8 configuration. This allows correct conversion using the 4 Mhz oscillator. Refer to the data sheet for more details. The a/d pin configuration is then set for all analog configuration. A/D channels 1 and 2 on pins 6 (GP1) and 5 (GP2) are converted and storied in variables rad1 and rad2 respectively. These are 8 bit values ranging from 0 to 255 (0 to 0xff hex). The remaining portion of the while loop uses the printf statement to format the output as ascii text. The printf statement sends the text out the serial channel. |
||
Software Compiling |
The software for the PIC is written in C for the CCS PCM C Compiler. The program is compiled from the DOS command prompt as;
|
|
Part Programming |
The compiler produces the hex file, sapin3.hex, that is used
to program the PIC12C672 using the PICSTART Plus programmer. Set the
configuration bits as follows;
|
|
This page has been hit |