Friday, September 26, 2014

PIC Microcontroller Data Acquisition System

















 Final Project











Abstract
            A data acquisition system was developed as a final project for the microcontroller design course at UW-Platteville. This system was developed to monitor power supplies and aid as a development tool for the design of a 200 W switch-mode power supply. A PIC microcontroller from Microchip was used as the heart of the data collection system. Internal analog to digital converters acquired data from an analog interface. The analog subsystem gathered data from temperature, voltage, and current sensors. Data was recorded through HyperTerminal in Windows. Once the data was gathered MS Excel was used to convert, scale, and plot the data.

Introduction

            Measurement of the three basic quantities: voltage, temperature, and current can provide enough information to allow for debugging of almost any electrical circuit. During the development of a switch-mode power supply it was determined that some sort of data logging was necessary to protect the supply and determine if the supply was operating properly. Out of this need a data acquisition system was developed. The data acquisition system measures one channel of voltage from 0 to 20 volts, one channel of current from –50 to +50 amps, and two channels of temperature (one ambient and one load). This amount of data is enough to determine supply efficiency and temperature rise. With additional channels or faster sampling rates it would be possible to measure and calculate inrush current, supply stability, and transient response.

Implementation options



            Two options were initially considered to implement the data logger. First, adding an outboard analog to digital converter (ADC) to the 8052 board used for development in class was considered. This approach had the advantage of allowing me to use a known good development system, software toolset, and the ability to get support from teachers and other students. Unfortunately, I had a difficult time finding multi-channel ADC converters featuring parallel interfaces to 8-bit busses that could resolve more than 8 bits. Most modern ADCs found used a serial interface. This was a problem on the 8052 board as the serial port was tied up for communication to the PC. Also fully developing a software-based serial protocol on a relatively slow processor like the 8052 could be difficult. Figure 1 shows the proposed block diagram for the 8052 based data acquisition system.

Figure 1, data acquisition system using 8052 board


            The second option considered the use of an altogether different processor, the Microchip PIC controller. PICs are self-contained microcontrollers often including clock, I/O, and a host of peripherals on-chip. The great advantage seen by adopting the PIC was a chip with onboard analog to digital converters was available in a small 14-pin DIP package. In addition a serial port, and multiple timer/counters were available. A low-cost ($35) development kit is available from Microchip to try out any of the 14-pin series of micrcontrollers. Additionally, for the intended application a low-power small form factor device was a plus. Essentially all the PIC needs to create the system is the analog interface and a voltage regulator. Just the 8052 board requires 2 to 3 times the space of the board designed for the PIC controller and analog board. The downside of this approach hinged around learning a new assembly language for the PIC microcontroller and learning a new development environment and device programmer. Figure 2 shows the block diagram for the PIC data acquisition system.


Figure 2, PIC processor based data acquisition system


PIC selection and setup

            There are literally hundreds of PIC microcontrollers to pick from. The programmer I had already purchased narrowed this selection down to 8 or 14 pin devices. At minimum 4 ADC channels, a UART, and one counter timer were needed. The first device found to meet these specifications was the PIC16F688. The ‘688 contains 8 channels of 10-bit AD converters, an enhanced UART, two timer counters, analog input comparison modules, an internal 32kHz to 8MHz clock, and flash program memory.
            In order to use the PIC, settings for all the internal registers needed to be determined or calculated via the datasheet. The internal oscillator was used and set to 4MHz. Next, the serial port was configured. The enhanced UART (EUSART) has an internal baud rate generator (no external timer is needed). The EUSART was setup to communicate at 9600 bps, 1 stop bit, 8 data bits, and no parity. This seemed to be a common serial data rate that was easily achieved with little error in bit-rate on the PIC (about 0.16%). The commonly used baud rates were all available in tables in the ‘688 datasheet. After the serial port was configured the analog to digital converter was set-up. A conversion time of 4.0us as dictated by the datasheet was selected. Then, registers were set up to use the positive supply as the ADC reference voltage along with selecting the location of the most significant bit of the result. Finally, a timer was set up to control the rate of data sampling. The timer values were set to allow for maximum delay that turned out to be around ¾ of a second. The timer overflow bit was checked via polling. This approach was used because exact time intervals were not needed and quick response was not necessary.
            Microchip provides an integrated development environment (IDE) called MPLAB for coding, compiling, setting up, and controlling programmers for the PIC series of microcontrollers. Included in the IDE is a debugger and compiler. The debugger worked well until additional peripherals were initialized and used which then caused the debugger to crash the IDE. Thus, all further testing needed to be conducted on actual hardware. A simple USB powered programmer interfaced to the IDE and reprogrammed the flash program memory in PIC controllers.

Microcontroller Firmware

            After configuration of peripherals the microcontroller firmware consisted of a simple loop that acquired samples, converted them to a format acceptable to HyperTerminal, and echoed them to the serial port. Code is attached to the end of this document in listing 1. Peripherals were first initialized as described in the previous section. Following this a timer set to approximately one second would overflow triggering a capture event. The capture event consists of setting ADC registers, then waiting for the conversion to be completed. These events are repeated four times to cover all the input channels. The results are then converted to a three digit octal number via shifts and bit masks. Only 8 bits of the 10-bit result are converted to octal, as it appeared the lower value bits only added noise to the acquired signal. Finally, the converted values were output on the serial port to HyperTerminal in ASCII format delimited with commas. Figure 3 shows the block diagram for the microcontroller firmware.


Figure 3, A block diagram of the PIC’s firmware


Hardware

            The high integration of the PIC controller leads to a very simple hardware solution. On the digital side the PIC controller is connected to a MAX232, RS-232 to logic-level converter. A 5 V power supply and some supply decoupling capacitors round out the digital section of the hardware. Figure 4 shows the implementation of the digital board that was constructed on the PICKit-1 development board.


Figure 4, the digital section of the data acquisition system


Highly integrated sensors reduced the difficulty of implementing an analog interface board. The LM35 temperature sensor features a conditioned output with a 10mV/C output slope. It was decided to use the LM35’s output directly, without amplification, with slightly reduced resolution. A hall-effect current sensor the ASC750SCA-050 made by Allegro was chosen as an easy integrated solution for current sensing. The current sensor is capable of resolving –50 to +50 A and outputs a 0 to 5 V signal corresponding to the current through the device. In the original application it was expected to see load currents up to 30 A. However, when demonstrating the device it was not possible to find power supplies capable of supplying more than 2.5A, thus the captured waveforms appear very noisy due to the small currents measured. Figure 5 shows the schematic of the analog board.


Figure 5, analog interface section of the data acquisition system


            The physical hardware is shown in photo 1. Two LM35 temperature sensors are attached via twisted cable, enabling them to be clamped onto heatsinks to measure power supply temperatures. A set of binding posts is provided for voltage measurement and current measurement input. The 9 pin serial port hangs off the left side of the development board (black PCB on top). Unregulated (9 to 37 VDC) DC input is supplied via two wires exiting the back of the board.


Photo 1, physical realization of the data acquisition system

Results

            To test the data acquisition system an unregulated power supply was used. Real power supplies have internal resistance that can be demonstrated if the load of the supply is varied. The circuit in figure 6 was built to show the effect of loading the supply under various conditions.


Figure 6, an unregulated power supply loaded with various power resistors


The output voltage, current, ambient temperature, and temperature of the load resistor were all monitored via the data acquisition system. After logging the octal numbers to a text file via HyperTerminal, the data was scaled and plotted in MS Excel.


Share:

Monday, September 1, 2014

15 step power supply ( variable DC voltage from 1.25V to 15.19V)

Here is a simple circuit to obtain variable DC voltage from 1.25V to 15.19V in reasonably small steps as shown in the table. The input voltage may lie anywhere between 20V and 35V. The first section of the circuit comprises a digital up-down counter built around IC1— a quad 2-input NAND schmitt trigger (4093), followed by IC2— a binary up-down counter (4029).
Two gates of IC 4093 are used to generate up-down logic using push buttons S1 and S2, respectively, while the other two gates form an oscillator to provide clock pulses to IC2 (4029). The frequency of oscillations can be varied by changing the value of capacitor C1 or preset VR1. IC2 receives clock pulses from the oscillator  and produces a sequential binary output. As long as its pin 5 is low, the counter continues to count at the rising edge of each clock pulse, but stops counting as soon as its pin 5 is brought to logic 1. Logic 1 at pin 10 makes the counter to count upwards, while logic 0 makes it count downwards. Therefore the counter counts up by closing switch S1 and counts down by closing switch S2.
The output of counter IC2 is used to realize a digitally variable resistor. This section consists of four N/O reed relays that need just about 5mA current for their operation. (note. The original circuit containing quad bilateral switch IC 4066 has been replaced by reed relays operated by transistorized switches because of unreliable operation of the former.) The switching action is performed using BC548 transistors. External resistors are connected in parallel with the reed relay contacts. If particular relay contacts are opened by the control input at the base of a transistor, the correspond-ing resistor across the relay contacts gets
connected to the circuit. The table shows the theoretical output for various digital input combinations. The measured output is nearly equal to the theoretically calculated output across regulator IC3 (LM317). The output voltage is governed by the following relationship as long as the input-to-output differential
is greater than or equal to 2.5V: Vout = 1.25(1+R2'/R1') Where, R1' = R15 = 270 ohms (fixed) and R2' = R11 + R12 + R13 + R14 = 220 + 470 + 820 +1500 ohms = 3,010 ohms (with all relays energised) One can use either the binary weighted LED display as indicated by LED1 through LED4 in the circuit or a
74LS154 IC in conjunction with LED5 through LED20 to indicate one of the 16 selected voltage steps of Table I. The input for IC4 is to be tapped from points marked ‘A’ through ‘D’ in the figure.
This arrangement can be used to replace the LED arrangement at points A, B, C, and D.
 This 74LS154 IC is a decoder/ demultiplexer that senses the output of IC2 and accordingly activates only one of its 16 outputs in accordance with the count value. LEDs at the output of this IC can be arranged in a circular way along side the corresponding voltages.

When the power is switched on, IC2 re sets itself, and hence the output at pins 6, 11, 14, and 12 is equivalent to binary zero, i.e. ‘0000’. The corresponding DC output of the circuit is minimum (1.25V).
As count-up switch S1 is pressed, the binary count of IC2 increases and the output starts increasing too. At the highest count output of 1111, the output voltage is 15.19V (assuming the in-circuit resistance of preset VR2 as zero). Preset VR2 can be used for trimming the output voltage as desired. To decrease the output
voltage within the range of 1.25V to 15.2V, count-down switch S2 is to be depressed.
Notes.
 1. When relay contacts across a particular resistor are opened, the corresponding
LED glows.
2. The output voltages are shown assuming the in-circuit resistance of preset VR2 as zero. Thus when the in-circuit resistance of preset VR2 is not zero, the

output voltage will be higher than that indicated here.

Share:

Nine independent telephones (using a single telephone line pair)

This circuit is able to handle nine independent telephones (using a single telephone line pair) located at nine different locations, say, up to a distance of 100m from each other, for receiving and making outgoing calls, while maintaining conversation secrecy. This circuit is useful when a single telephone line is to be shared by more members residing in different rooms/apartments. Normally, if one connects nine phones in parallel, ring signals are heard in all the nine telephones (it is also possible that the phones will not work due to higher load), and out of nine persons eight will find that the call is not for them. Further, one can overhear others’ conversation, which is not desirable. To overcome these problems, the circuit given here proves beneficial,
as the ring is heard only in the desired extension, say, extension number ‘1’.
For making use of this facility, the calling subscriber is required to initially dial the normal phone number of the called subscriber. When the call is established, no ring-back tone is heard by the calling party. The calling subscriber has then to press the asterik (*) button on the telephone to activate the tone mode (if the phone normally works in dial mode) and dial extension number, say, ‘1’, within 10 seconds. (In case the calling subscriber fails to dial the required extension number within 10 seconds, the line will be disconnected automatically.) Also, if the dialed extension phone is not lifted within 10 seconds, the ring-back tone will cease.
The ring signal on the main phone line is detected by opto-coupler MCT- 2E (IC1), which in turn activates the 10-second ‘on timer’, formed by IC2 (555), and energises relay RL10 (6V, 100- ohm, 2 C/O). One of the ‘N/O’ contacts of the relay has been used to connect +6V rail to the processing circuitry and the other has been used to provide 220-ohm loop resistance to deenergise the ringer relay in telephone exchange, to cut off the ring.
When the caller dials the extension number (say, ‘1’) in tone mode, tone receiver CM8870 (IC3) outputs code ‘0001’, which is fed to the 4 bit BCD-to-10 line decimal decoder IC4 (CD4028). The output of IC4 at its output pin 14 (Q1) goes high and switches on the SCR (TH-1) and associated relay RL1. Relay RL1, in turn, connects, via its N/O contacts, the 50Hz extension ring signal, derived from the 230V AC mains, to the line of telephone ‘1’. This ring signal is available to telephone ‘1’ only, because half of the signal is blocked by diode D1 and DIAC1 (which do not conduct below 35 volts). As soon as phone ‘1’ is lifted, the ring current increases and voltage drop across R28 (220-ohm, 1/2W resistor) increases and operates opto-coupler IC5 (MCT-2E).
This in turn resets timer IC2 causing:
(a) interruption of the power supply for processing circuitry as well as the ring


Share:

Gas Leakage Alarm ( LPG gas leakage detector with audio visual indicator)

LPG gas is supplied in pressurized steel cylinders. As this gas is heavier than air, when it leaks from a cylinder it flows along floor and tends to settle in low spots such as a basement. This can cause fire or suffocation if not dealt with.

Here is a circuit that detects the leakage of LPG gas and alerts the user through audio-visual indications. Fig. 1 shows the circuit of the gas leakage alarm. The circuit operates off a 9V PP3 battery. Zener diode ZD1 is used to convert 9V into 5V DC to drive the gas sensor module. The SEN-1327 gas sensor module from RhydoLABZ is used in this circuit. Its output goes high when the gas level reaches or exceeds certain point. A preset in the module is used to set the threshold. Interfacing with the sensor module is done through a 4-pin SIP header. Pin details of the gas sensor module are shown in Fig. 2.


LPG Gas Leakage Alarm Schematic

An MQ-6 gas sensor is used in the gas sensor module. As per its datasheet, it has high sensitivity to propane, butane, isobutene, LPG and natural gas. The sensor can also be used to detect combustible gases, especially methane. This circuit has been tested with LPG gas and was found to work satisfactorily. Whenever there is LPG concentration of 1000ppm (parts per million) in the area, the OUT pin of the sensor module goes high. This signal drives timer IC 555, which is wired as an astable multivibrator. The multivibrator basically works as a tone generator. Output pin 3 of IC 555 is connected to LED1 and speaker-driver transistor SL100 through current-limiting resistors R5 and R4, respectively. LED1 glows and the alarmsounds to alert the user of gas leakage. The pitch of the tone can be changed by varying preset VR1. Use a suitable heat-sink for transistor SL100.
Share:

Infrared Remote for Toy Car Motor Controller

This add-on circuit enables remote switching on/off of battery-operated toy cars with the help of aTV/video remote control handset operating at 30–40 kHz. When the circuit is energised from a 6V battery, the decade counter CD4017 (IC2), which is configured as a toggle flip-flop, is immediately reset by the power-on-reset combination of capacitor C3 and resistor R6. LED1 connected to pin 3 (Q0) of IC2 via resistor R5 glows to indicate the standby condition. In standby condition, data output pin of the integrated infrared receiver/demodulator (SFH505A or TSOP1738) is at a high level (about 5 volts) and transistor T1 is ‘off’ (reverse biased).

INFRARED TOY CAR MOTOR CONTROLLER

The monostable wired around IC1 is inactive in this condition. When any key on the remote control handset is depressed, the output of the IR receiver momentarily transits through low state and transistor T1 conducts. As a result, the monostable is triggered and a short pulse is applied to the clock input (pin 14) of IC2, which takes Q1 output (pin 2) of IC2 high to switch on motor driver transistor T2 via base bias resistor R7 and the motor starts rotating continuously (car starts running). Resistor R8 limits the starting current. When any key on the handset is depressed again, the monostable is retriggered to reset decade counter IC2 and the motor is switched off.

Standby LED1 glows again. This circuit can be easily fabricated on a general-purpose printed board. After construction, enclose it inside the toy car and connect the supply wires to the battery of the toy car with right polarity. Rewire the DC motor connections and fix the IR receiver module in a suitable location, for example, behind the front glass, and connect its wires to the circuit board using a short 3-core ribbon cable/shielded wire. Note. Since the circuit uses modulated infrared beam for control function, ambient light reflections will not affect the circuit operation. However, fluorescent tubelights with electronic ballasts and CFL lamps may cause malfunctioning of the circuit.
Share:

IR Remote Switch

Imagine the convenience of selecting TV channels using your remote and then pointing the same remote to your switchboard to switch on/off the fan or the tubelight. Here is a simple circuit to remotely switch on/off any electrical device through a relay using the normal TV/VCR/VCP/VCD remote controlunit. It works up to a distance of about 10 metres. The circuit is built around a 3-pin IR IC receiver (Siemens SFH-506-38 or equivalent) that can detect 38kHz burst frequency generated by a TV remote. (This IR receiver module has been covered earlier in many projects published in this blog.) The output pin of IR sensor goes low when it detects IR light, triggering the monostable (1-second) built around timer NE555. The output of the mono toggles the J-K flip flop, whose Q output drives the relay through SL100 npn transistor (T1).



LED2, LED3, and LED4 are used to display the status of each output stage during circuit operation. Back-EMF diode D5 is used for protection. Transistor T1 is configured as an open-collector output device to drive the relay rated at 12V DC. The circuit draws the power from voltage regulator 7805. Capacitor C5 is soldered close to the IR sensor’s pins to avoid noise and false triggering. Capacitor C3 and resistor R3 also avoid false triggering of monostable NE555. The monostable acts as a 1-second hysterisis unit to restrict the flip-flop from getting retriggered within one second. To activate any other 12V logic device, use the output across the relay coil terminals.
Share:

Stepper Motor Interface

This simple circuit and program listing allows the Maximite microcomputer (SILICON CHIP, March-May 2011) to control a stepper motor. It could be expanded to allow for the control of multiple motors, with four of the Maximite’s external I/O pins used to control each motor with identical driver circuits. A ULN2003 Darling ton transistor array (IC1) switches current through the stepper motor’s two winding
 in either direction. When one of the four Maximite output pins (8, 12, 16 & 20, corresponding to I/Os 19, 17, 15 & 13) goes high, the corresponding output pin on IC1 goes low, sinking current through a motor winding. Conversely, when these pins are high, the corresponding Darlington transistor is off and so no current flows through that portion of the winding.


Share:

Touch Switch using 555 oscillator IC

This touch switch built based on famous 555 timer IC. When the plate is touched the 555 timer is triggered and the output on pin 3 goes high turning on the LED and the buzzer for a certain period of time. The time that the LED and the buzzer is on is based on the values of the capacitor and resistor connected to pin 6 & 7. The 10M resistor on pin 2 causes the the circuit to be very sensitive to the touch.

Share:

Sunday, August 31, 2014

Three-Phase Appliance Protector

Many of our costly appliances require three-phase AC supply for operation. Failure of any of the phases makes the appliance
Prone to erratic functioning and may even lead to failure. Hence it is of paramount importance to monitor the availability of the three-phase supply and switch off the appliance in the event of failure of one or two phases. The power to the appliance should resume with the availability of all phases of the supply with certain time delay in order to avoid surges and momentary fluctuations.

The complete circuit of a three phase appliance protector is described here. It requires three-phase supply, three 12V relays and a timer IC NE555 along with 230V coil contactor having four poles. Relays RL1 and RL2 act as a sensing devices for phases Y and B, respectively.

These relays are connected such that each acts as an enabling device for the subsequent relay. Therefore the combination of the relays forms a logical AND gate connected serially. The availability of phase R energizes relay RL1 and its normally opened (N/O) contacts close to connect phase Y to the input of transformer X2.

The availability of phase Y energizes relay RL2 and its N/O contacts close to connect phase B to the input of transformer X3, thus applying a triggering input to timer IC NE555 (IC1). Therefore the delay timer built around NE555 triggers only when all the phases (R, Y and B) are available.

It provides a delay of approximately four seconds, which energizes relay RL3 and its N/O contact, closes to connect the line to the energizing coil of four-pole contactor relay RL4. Contactor RL4 closes to ensure the availability of the three-phase supply to the appliance.

The rating of contactor RL4 can be selected according to the full-load current rating of the appliances. Here the contact current rating of the four-pole contactor is up to 32A. The availability of phases R, Y and B is monitored by appropriate LEDs connected across the secondary windings of transformers X1, X2 and X3, respectively. Hence this circuit does not require a separate indicator lamp for monitoring the availability of the three phases. When phase R is available, LED1 glows.
When phase Y is available, LED2 glows. When phase B is available, LED3 glows. The main advantage of this protector circuit is that it protects three-phase appliances from failure of any of the mounted on the backside of cabinet. Connect the appliance through external wires.



Caution. To avoid the risk of electric shock, ensure that AC mains is disconnected during assembly of the circuit and double check everything before connecting your circuit to the mains. phases by disconnecting the power supply through the contactor and automatically restores the three-phase supply to the appliance (with reasonable time delay) when all the phases are available.  Assemble the circuit on a general purpose PCB and enclose in a cabinet with the relays and contactor.



Share:

REMOTE CONTROL FOR HOME APPLIANCES

Connect this circuit to any of your home appliances (lamp, fan, radio, etc) to make the appliance turn on/off from a TV, VCD or DVD remote control. The circuit can be activated from up to 10 meters.
The 38kHz infrared (IR) rays generated by the remote control are received by IR receiver module TSOP1738 of the circuit.
Pin 1 of TSOP1738 is connected to ground, pin 2 is connected to the power supply through resistor R5 and the output is taken from pin 3.
The output signal is amplified by transistor T1 (BC558). The amplified signal is fed to clock pin 14 of decade counter IC CD4017 (IC1). Pin 8 of IC1 is grounded, pin 16 is connected to Vcc and pin 3 is connected to LED1 (red), which glows to indicate that the appliance is ‘off.’
The output of IC1 is taken from its pin 2. LED2 (green) connected to pin 2 is used to indicate the ‘on’ state of the is fed to clock pin 14 of decade counter IC CD4017 (IC1). Pin 8 of IC1 is grounded, pin 16 is connected to Vcc and pin 3 is connected to LED1 (red), which glows to indicate that the appliance is ‘off.’ The output of IC1 is taken from its pin 2. LED2 (green) connected to pin 2 is used to indicate the ‘on’ state of the appliance. Transistor T2 (BC548) connected to pin 2 of IC1 drives relay RL1. Diode 1N4007 (D1) acts as a freewheeling diode. The appliance to be controlled is connected between the pole of the relay and neutral terminal of mains.
It gets connected to live terminal of AC mains via normally opened (N/O) contact
when the relay energises.

Share:

BTemplates.com

Powered by Blogger.