The ATMega32L has 8 channels of 10-bit analog input so you can measure DC voltage inputs from 0 to +5 V with a resolution of about 5 mV. This means you can read any type of sensor with a high level DC output signal. There are hundreds of possibilities: pressure sensors, temperature sensors, light level sensing and many others. In addition, the ATMega32L can be configured to accept four digital inputs and switch four digital outputs. This allows you to control relays and read the state of input switches. The ATMega32L also has a built-in USART that provides serial communication, and does not require a clock oscillator or even a crystal.
Using the ATMega32L and just a few external parts you can quickly build up an interface to the real world that can communicate via serial port to Channel 8.
Note that the capacitors are tantalum, electrolytic types. These are polarized and will have the + lead marked in some way. The acutal uF values are not critical but be sure the input filter capacitor (0.33 uF) is rated to 35 V. Double-check the regulator terminal pin designations from a catalog sheet; it is very easy to get the LM7805 turned around and wired wrong.
Test the power supply section with a good voltmeter before you try to power any other part of the SI430. The LED should light up, but check to see that you are getting +5.00, +/-.010 Vdc, between Gnd and terminal 3 of the regulator. A further precaution is to measure the current draw of the circuit. It should draw less than 40 mA under normal conditions, with just the power-on LED connected. Carefully touch the regulator mounting tab to see if it is overheating; it should be only moderately warm. If the current is too high, check for shorts before you burn up the regulator or the LED!
The MAX232 uses four 10 uF capacitors as part of its level-shifting and these must be carefully connected. They are all tantalum electrolytic types and the polarity is very important. Note that the capacitor polarity between pins 6 and 15, and between pins 2 aqnd 16 of the MAX232 appear to be reversed. This is not a mistake! It is part of the MAX232 scheme for generating a +12 V signal from the SI430 +5 Vdc supply.
Communication to the PC is by a serial cable. A 9-pin cable is most convenient. Select a 9-pin connector that mates with your cable, and wire the pins as shown on the schematic.
The reset pin of the ATMega32L has been pulled high (pin 9) with a 470K resistor. So you have to power the SI430 down to reset it. Another short-cut, but it saves a few more parts. The ATMega32L has an internal 1 MHz oscillator so you don't have to provide an external clock signal or even a crystal. This limits serial port speeds to 2400 baud, but this is a small price to pay for the inherent simplicity.
In order to make a real-world interface that responds to a set of Linux serial port commands, the program inside the ATMega32L has to be listening for incoming requests for data. So a command string structure has to be developed, and then coded into the ATMega32L. For this project, a command set was defined as shown here.
If you want to develop your own command structure and program the ATMega32L to respond, there are a number of tools and development kits available. The Bascom compiler is a good choice because it allows you to write code in BASIC, then compile and upload it to the ATMega32L. And Bascom offers a free, downloadable version of the compiler.
To start, type in the Ping command P; you should receive SI430 65535 in reply. Try sending 0 to get the readings on analog input Ch 0. You can wire up a signal to pin 40 of the ATMega32L and check it with a voltmeter. The returned value in counts should reflect the actual applied voltage, within a few millivolts.
Digital output ports can be checked with LEDs. Digital inputs with switches wired with pull-up resistors to +5 V.
Here is a listing of a C program that communicates with the SI430 and formats the analog readings for Channel 8:
/* Serial Interface Program */
#include stdlib.h
#include stdio.h
#include time.h
#include string.h
main()
{
FILE *fptr;
char IP[5];
char *Vlu;
char Val[50];
double v[7];
double volts;
int ctr = 0;
while (ctr <8)
{
fptr = fopen ("/dev/ttyS0", "r+");
fprintf(fptr, "%d", ctr);
usleep(150000);
fgets(IP, 5, fptr);
volts = atof(IP);
v[ctr] = 5*volts/1024;
fclose(fptr);
usleep(150000);
ctr++;
}
ctr = 0;
while (ctr < 8)
{
asprintf(&Vlu, "%5.3f ", v[ctr]);
strcat(Val, Vlu);
ctr++;
}
printf("%s ", Val);
}
Now that the A/D interface code has been verified, it is simply a matter of inserting it into the Ch8RndServer.c file, compiling and testing it with the rest of the Channel 8 system. The section of Ch8RndServer.c that is appropriate is identified by the comments:
"// ------ Put A/D Code Here ---------"
and
" // ------------ End A/D Code ----------------".
Be sure to remove the code for generating random numbers.
Note that if the floating-point A/D values in volts are kept in an array named v[], the correct string will be automatically generated by the existing code for random values. This code is duplicated in the above example.
Before you run the program, you must set the serial port to 2400 baud. Do this using the following command: stty /dev/ttyS0 2400 You can verify as follows: stty /dev/ttyS0 . Run the example program
For further info e-mail: documatrix@linuxmail.org