A DEMODULATOR OF PWM SIGNALS GENERATED FOR A DIGITAL ACCELEROMETER IS DEVELOPED USING A MICROCONTROLLER

This paper presents the use of a microcontroller to demodulate two Pulse Width Modulated (PWM) signals which are being generated by a digital accelerometer, to obtain their pulse widths and transmit them serially to a parallel port of a general purpose computer.


INTRODUCTION
Nowadays, there is a new generation of electronic accelerometers which are more precise, cheaper, smaller and with a wider range than their mechanical counterparts.The scope of its use is very wide, which usually involves force related applications, such as mechanical stress, rotary torque, seismic events, dynamic weight and so on.Thus, the introduction of these tiny digital accelerometers opens the chances of dynamically monitoring acceleration in a real time fashion.In addition, if these devices are integrated with general purpose computers, it is feasible to go beyond just displaying them on an screen, calculating their related energy and forces, etc., saving them up onto disk for further analysis and distributing them through the Internet using the Transmission Control Protocol/Internet Protocol (TCP/IP).These accelerometers, as integrated circuits, generate two PWM squared-waveforms as shown in Figure 1, and the value of the accelerations AX and AY can be calculated through the equations shown in Figure 2 and Figure 3 respectively.To demodulate PWM signals, Karthaus and Fischer [1] used the envelope detection technique and Pascual [2] developed a low pass filter.This proposal deals with developing a PWM demodulator using a microcontroller as a single hardware piece.
Equation that uses the T1X and T2X measured pulse widths to calculate the X-acceleration value Equation that uses the T1Y and T2Y measured pulse widths to calculate the Y-acceleration value

PWM DEMODULATOR REQUIREMENTS
To demodulate a PWM signal it is necessary to know either the width of the high state pulse and the width of the cycle.The present work presents the next strategy 1. Detect when a signal starts or finishes, either if it is in the high or low state.To accomplish this, detection either of the falling or raising edges is needed.
2. Counting slices of time whenever a falling or a raising edge has been detected.
To implement the above strategy, a microcontroller will be used, mostly because it has the following advantages q Flexible detection either of the falling or ra ising edges th rough embedded programming.
q Easiness to count slices of time through the internal programmable timer.
q Fast development of an interface between the computer parallel port and a microcontroller, because electrical compatibility.
q Easy serial communication implementation, which includes protocol developing, handshaking control and data transmission through embedded programming.

PWM DEMODULATOR HARDWARE SETUP
Accelerometer.An ADXL-202 accelerometer was used as an acceleration sensor.It generates two PWM squaredwaveforms signals, 90º shifted, 1mV/g resolution, ± 2 g scope and, with a 5 KHz central operation frequency each, TTL electrically leveled, one designated as the ACCEL_X and the other as the ACCEL_Y.
Microcontroller.The general purpose PIC-16F84 was chosen because its technical features suits with the requested capabilities and its widespread use makes it a simpler task to integrate it with further projects.

SEQUENCE TO DEMODULATE TWO PWM SIGNALS
To measure the width of the low and the high state of the ACCEL_X and ACCEL_Y signals, a time slice counting is carried out, using the internal timer TMR0, which was programmed to count slices of one microsecond, because both ACCEL_X and ACCEL_Y signals have a width time of 200 micro seconds each, so the high and low time are 100 microseconds width.Thus, since TMR0 is an 8-bit register, the maximum count is 255, or, 255 microseconds as maximum width time to record.The sequence to accomplish it is described below and the block diagram to demodulate the PWM signals is shown in Figure 3.
1. To measure the high state of the X-acceleration signal, the software waits until a rising edge of the ACCEL_X signal is detected.Once detected, TMR0 is activated to count until a falling edge of the ACCEL_X signal is detected and then TMR0 is stopped and its content is stored into the T1X register.121 2. To measure the low state of the X-acceleration signal, the software waits until a falling edge of the ACCEL_X signal is detected.Once detected, TMR0 is activated to count until a rising edge of ACCEL_X is detected and then TMR0 is stopped an its content is stored into the TPX register.
3. To calculate the full width of the waveform, the content of the registers T1X and TPX are added and the result is stored in T2X register.
4. The above proceeding is repeated in order to have the pulse widths of the ACCEL_Y signal stored in the T1Y, TPY and T2Y registers.
5. The content of T1X is moved to TTY and thenthe SEND_TTY subroutine is called.
6.The content of T2X is moved to TTY and then the SEND_TTY subroutine is called.
7. The content of T1Y is moved to TTY and then the SEND_TTY subroutine is called.
8. The content of T2Y is moved to TTY and then the SEND_TTY subroutine is called

SEQUENCE TO TRANSMIT 32 BITS TO THE COMPUTER PARALLEL PORT
The SEND_TTY subroutine transmits the 8-bit TTY register to the parallel port of the computer, in a bit to bit fashion, so the next actions are performed and repeated eight times.This subroutine is described below and the block diagram is shown in Figure 4.
q The PIC_READY line is raised to let computer know that the microcontroller is ready to send 32-bits.
q TTY is left-rotated, putting the most significant bit into the Carry bit of the microcontroller STATUS register.
q The Carry bit is outputted to the DATA line.
q A falling edge detection of the IO_CLOCK line is waited.
The PIC_READY line is turned to low let computer know that the microcontroller has already sent the eight-bits.

CONCLUSIONS
Once built, this device was debugged and tested.There are some outcomes which are interesting to comment on.
q Developing, error correcting and modifying source code is by far a real easy task, taking into account it is the embedded hardware that is under a correction process.Analogous process with either active or passive components is clearly a far difficult task to make.
q One chip demodulator means tiny space and light weight, which makes it extremely portable, either to locate it wherever in the lab or install it in remote sites, such as in seismic applications.
q Old mechanical accelerometers, pendulum style, along with their heavy carcasses and gears, are several times more expensive than the digital ones.
q Use of the parallel port instead of the serial port, because a simpler protocol could be devised.

Figure 1 .
Figure 1.X-Y acceleration signals generated by the accelerometer.

Figure 2
Figure 2 depicts the block diagram between the computer parallel port, the microcontroller and the accelerometer, giving details only of the inter-connection lines used and their related pin outs.

Figure 2 .
Figure 2. The general layout shows up the interconnected signal lines among the computer, the microcontroller and the accelerometer.

Figure 3 .
Figure 3.The algorithm shows up the full steps sequence of the PWM demodulator in order to obtain the AX and AY values and send them to the parallel port of the computer.

Figure 4 .
Figure 4. Com mu n icat ion rout i ne bet we en t he microcontroller and the computer, along with the related handshaking.