November 25th, 2013 at 9:23 am
Having worked with any one Microcontroller, moving from one of its family to another is just a matter of matter knowing the right tools and understanding how things have to be done in terms of software (compiler specific addressing like that of the SRFs) and hardware (circuitry, design practices, etc., )
In this post we will have a look at everything you will need while getting started with PIC microcontrollers.
Thing you will need,
Here is a very small list of things that you will need to start working with PIC micros.
- The Microcontroller
- Datasheet for that device
- A suitable programmer tool
- MPLAB IDE and a C compiler.
- A computer with internet connection
- And some basic electronics components and tools
Getting the hardware ready,
This is step zero towards working on any embedded platform. You MUST have the hardware at your disposal. You can either buy an evaluation board for your device or make on a perf board. Fortunately, there is not much work need to have a bare bone version of the evaluation board with just the absolute necessary components.
For any given controller, you will need to build the reset circuit, plug in a crystal oscillator and power it up for it work standalone. You might want to add a little ICSP connector to program the chip without having to pull it off its socket but then its not really needed if you are okay with pulling the controller off the circuit each time you have to reprogram it. Otherwise there is nothing that is really needed for the operation of the controller. Beyond this, its all application specific stuffs and will change from one project to another.
For simplicity sake you can make something like this that conveniently sits on a breadboard allowing you to do all the prototyping on the breadboard.
As you can see the above board has only what is needed (except the power LED) on it and it has a very small footprint. To make such a circuit, all you need is the datasheet to tell you which pin is for what. Most of the time there is an application circuit in the datasheet vary close to the pin description or in the corresponding chapters Eg., the oscillator circuit will probably be there in the section devoted to the external oscillators.
There are a lot lot of programmers for the PIC micros. One of the most commonly used and programmer/debugger is the PICkit 2. It has a lot cool features like acting as a serial monitor and logic analyzer. It was really stable and rugged. Like they say, good things are not meant to last. I some how managed to brick my PICkit 2 a few weeks back.
That’s when I bought this attractive, supposedly upgraded version of the PICkit 2… The all new PICkit 3!!
There are a lot of drawbacks in this product and the cost was a more than the its predecessor. I already knew all its drawbacks, but listening to all of it form David Jones in his video blog (http://www.eevblog.com/) at one stretch, reduced my impression further. If you are planing to buy this product then I suggest you to see the video I have attached below.
Now that we have all the cons some of the pros are, support for more device and future devices from Microchip. Microchip has already stopped support for PICkit2 in some of its newer devices. Presently there are a handful of chips that are not compatible with PICkit 2 in a year or so there will probably be a lot to that list.
Besides, all the problems that are currently there could be fixed with a simple software update. The hardware is what that cannot be changed. Whether Microchip guys give us the update or the user community cracks it open for us is a question that only time can answer.
Setting up the IDE
The next thing that you will have to worry about is the development environment. Download the Mplab X or Mplab 8 IDE form the microchip website. The page is fully populated with details of the new Mplab X IDE. If you happen to be one of those classic Mplab 8 lovers you’ll have to scroll down to the very bottom of the page to find an unobtrusive link to a Mplab v8.X
Download any one of those IDE’s and install them in your computer. The next thing to do would be to download one of the compiler that Microchip offers. Here is a list of all the compiler that they provide.
- C18 Compiler
- Hitech C compiler
- XC 8 Compiler
Here at EmbedJournal we use all the above compilers interchangeably. All of them are almost the same and have minor differences. The C18 compiler has been around for some time and has a lot of sample code and libraries. The XC 8 is an advancement over the c18 compiler and hence offers more features.
While installing the compilers, install it in the default directory and ask it to add the path to Mplab’s environment variables. By doing this you just let your IDE know that there is compiler installed and ready to be used.
New Project! New File!
The next thing to do will be to create a new project workspace and start populating it with your source code. Here is a step by step image gallery that will help you do it.
During the creation of the project you will have to specify the device, programmer and the compiler you are going to be using for the project. Though all the parameters can be changed from the project properties window, it is advisable to have already installed the compiler and decided upon the device you are going to be working on.
August 13th, 2013 at 10:03 am
Asimple low-power inverter circuit is described here, which converts 12V DC into 230V AC. It can be used to power very light loads like night lamps and cordless telephones,but can be modified into a powerful inverter by adding more MOSFETs. This circuit has two stages-battery charger with cut-off, and battery level indicator and inverter circuit.Charging circuit is built around IC1 (LM317) as shown in Fig. 1. When mains 230V AC is available, IC1 provides gate voltage to SCR1 (TYN616) through diode D3 (1N4007). SCR1 starts charging the battery. For output voltage setting preset VR1 may be used.
The battery level indicator and inverter circuit is shown in Fig. 2. The battery level checking system is built around transistors T1 and T2 (both BC547) along with some discrete components. When the battery is charged (say, to more than 10.50V), LED1 glows and piezo-buzzer PZ1 does not sound. On the other hand, when battery voltage goes down (sayk, below 10.50V),LED1 stops glowing and piezo-buzzer sounds, indicating that the battery has been discharged and needs recharging for further use.The inverter is built around IC2 (CD4047), which is wired as an astable multivibrator operating at a frequency of around 50 Hz. The Q and Q outputs of IC2 directly drive power MOSFETs (T3 and T4). The two MOSFETs (IRFZ44) are used in push-pull configuration. The inverter output is filtered by capacitor C1.
Assemble the circuit on a general-purpose PCB and enclose it in a suitable metal box. Refer Fig. 3 for pin configurations before mounting the components on the PCB. Mount the transformer on the chassis and the battery in the box using supporting clamps. Use suitable heat-sinks for MOSFETs. The circuit can be used for other applications as well by delivering higher power with the help of a higher current rating transformer and additional MOSFETs.
August 9th, 2013 at 5:59 am
Two of the problems commonly associated with street lights are false triggering due to slight variation in the intensity of ambient light and no control over switching action. Here is a simple switching circuit for street lights that overcomes these problems.
The circuit is built around popular op-amp IC 741 (IC1), 14-bit ripple counter CD4060 (IC2), SCR BT169, BC557 and other components. IC1 along with LDR1 enables IC2, which drives transistor T1 into conduction. IC2 is also used to trigger SCR1 to switch on the street light. Removal of trigger turns the light ‘off.’
IC CD4060 has an inbuilt oscillator around its pins 9, 10 and 11. Pin 12 is the master reset (MR) control. The oscillator is disabled when pin 12 is high and enabled when pin 12 is low.
In daytime, i.e., when light is falling on LDR1, its resistance decreases and the high output at pin 6 of IC1 cuts off pnp transistor T1 and disables IC2. At this stage, SCR1 remains untriggered to switch off the street light.
At night, i.e., when no light is falling on LDR1, its resistance increases and low output pin 6 of IC1 drives pnp transistor T1 into conduction. This enables IC2 and its internal oscillator starts oscillating.
After a preset time, pin 14 (Q7) of IC2 goes high and SCR BT169 is triggered through resistor R9 and diode D3. This energises RL1 and street light is turned on. This time interval can be varied by connecting the gate of SCR1 to pins 6, 13, etc of IC CD4060 (not shown in Fig. 1). Transistor T2, which is normally conducting, is driven into non-conduction when output pin 3 (Q13) of IC2 goes high, which de-energises relay RL1 to switch off the street light. This time can be adjusted with the varying preset resistor VR2.
Put simply, the street light turns ‘on’ when Q7 of IC2 goes high and ‘off’ when Q13 goes high, provided pin 12 of IC2 remains low.
The circuit works off regulated 12V DC. You can assemble it on any general-purpose PCB and enclose in a suitable cabinet. The mains AC terminal for the street light is connected to the normally-open (N/O) contact of relay RL1, so the street light turns on when the relay energises.
August 6th, 2013 at 5:02 am
There are times when you want to view the video clips taken by your camera on your TV. You can do so by interfacing the video output of the source device (camera) to the video input terminals of the TV. However, at times the video signal level needs to be raised before it is fed to the TV.
A PAL video amplifier is expected to have a 3dB bandwidth of 5.5 MHz. The waveform levels of a 1VPk-Pk PAL video signal between any two line sync pulses (separation 64 Us) are shown in Fig. 1. The waveform shows that each scan line lasts 64 µs, of which only 52 Uscontains active video or picture data. The video level (variable) lies between 0V and 0.7V and the blanking level extends from 0V down to –0.3V (for 12 Us). The black level or blanking level starts at 0V, the white level or peak video level is 0.7V and the sync pulse peak (-ve) level is –0.3V.
Normally, the video amplifier section for TV requires low and high voltage level stages. Fig. 2 shows a typical low-level transistorised video amplifier stage that accepts 1VPk-Pk and outputs 2VPk-Pk signal. (The circuit has been tested at 4.7 MHz.) This low-level stage requires a single 5V DC supply.
The R1-R2 divider network adjusts the DC level of the video, while the R5-R6 divider network adjusts the gain. You may replace both the dividers with two 4.7-kilo-ohm (or 5-kilo-ohm) trimpots for proper adjustment of the DC level and the gain. The 75-ohm resistor (R3) may be discarded if you feed the video from a high-output-impedance stage.
Although the resistive load in the collector of the transistor provides reasonably good bandwidth, a peaking coil of 20 to 30 uH can be added in series with R4 to improve its performance at higher frequencies. With 1VPk-Pk signal as the input, the given circuit outputs 3.5VPk-Pk maximum amplitude at 6.25 MHz without the peaking coil.
August 6th, 2013 at 4:09 am
Here we put all the theory to work and present a simple power amplifier module that can be easily built with readily available components. The block diagram of the amplifier is shown in Fig. 1. It is typical of most audio amplifiers, although the circuit is somewhat different.
A power amplifier contains audio input, amplifier, driver, output and power supply sections. The amplifier section provides most of the voltage gain. The driver stage is a buffer between the amplifier section and the output stage. The output stage usually has to drive a low-impedance load such as a loudspeaker. The power comes from the power supply, and the output signal appearing across the load should ideally be a replica of the input signal. In other words, the output stage takes power from a DC supply to boost the signal so it can drive a load.
The circuit shown in Fig. 1 shows the amplifier, driver and output sections. The amplifier section is built around JFET VHF/UHF amplifier 2N5484 (T1) and npn transistor BC548 (T2). The driver section is built around transistor BC639 (T3) while the output section is built around transistors BD139 and BD140 (T4 and T5).
The input signal is coupled to volume control VR1 via capacitor C1. The value of VR1 is specified as 1-mega-ohm. Since the gate terminal of FET (T1) can be regarded as an open circuit, the input impedance of the circuit is equal to the value of VR1. Like all audio volume controls, VR1 needs to have a logarithmic taper (usually denoted as ‘type C’) to give an apparent linear relationship between rotation of the control and the volume level. This is necessary because human hearing follows a logarithmic response, in which a change in the output power by a factor of 10 is heard as a change by a factor of two.
The FET stage in amplifier section is used to give a high input impedance. The next stage is common-emitter amplifier comprising transistor T2. Preset VR2 is used to adjust amplification and avoid direct coupling between transistor stages T2 through T5. This means that DC voltages for T3, T4 and T5 are all determined by the collector voltage at T2. The most important voltage is at the emitters of T4 and T5. Preset VR2 is used to adjust this to half the supply voltage. To stabilise this and other voltages in the circuit, resistor R13 gives negative feedback from the output to the emitter of transistor T2. If capacitor C8 is not included, the feedback will be for both DC and AC voltages. It will be for DC only if C8 is added.
When voltage at the emitters of transistors T4 and T5 rises, say, due to a temperature change, the voltage at the emitter of transistor T2 will also increase by way of R13. This will cause T2 to conduct less current, making the DC voltage at its collector increase. As a result, transistor T3 will conduct more current and its collector voltage will drop. This then reduces the voltages at the bases of T4 and T5 and hence their emitter voltages.
Driver transistor T3 and its collector load is the base circuitry associated with T4 and T5. In effect, T3 is connected as a common-emitter amplifier. The output signal developed across T3 is applied to the base of T4 via diode D1 and the parallel combination of resistor R9 and preset VR3. The base of pnp transistor T5 connects directly to collector of T3. The driver stage therefore drives a relatively low-resistance load, requiring a transistor capable of handling high power.
The output transistors are npn transistor T4 and pnp transistor T5, connected as a complementary symmetry class-AB output stage. In this configuration, an npn transistor and a pnp transistor (complementary) with equal current gains (symmetrical) are required. Thus, ideally, the DC current gains of T4 and T5 should be matched by measurement.
The DC biasing circuit for T4 and T5 has one diode and two parallel-connected resistors. Preset VR3 is used to adjust the quiescent collector current of T4 and T5 and therefore the class of operation. The output stage also involves capacitor C4, which is known as a bootstrapping capacitor. Bootstrapping is included to allow a higher output voltage swing. If capacitor C4 is not included, biasing resistors R7 and R8 are combined into a single resistor.
Ideally, the output signal should be able to swing from 0V to the value of the supply voltage. However, this cannot happen due to the 0.6V forward bias required across the base-emitter junctions of the output transistors and also the losses. For the positive half cycle, if the output is to reach the supply voltage, the voltage at T4 must be at least 0.6V higher than the supply voltage. Similarly, an output of 0V can be obtained only if the base voltage of T5 falls to –0.6V.
By adding bootstrapping capacitor C4, the output voltage swing is effectively added to the DC bias voltages. Thus, for the positive half-cycle, the positive change adds to the bias voltage at T4, causing it to conduct more current and produce a higher output voltage. Similarly, in the negative half-cycle, the negative-going swing reduces the quiescent bias voltage, helping T5 turn on harder and produce a lower output voltage.
An important aspect of amplifier design is power supply decoupling. When the output stage is producing full output power, the power supply delivers substantial peak currents. Under these conditions, it is possible that some of the audio signal appears on the supply line. To prevent this signal from affecting the operation of the rest of the circuit, it must be eliminated from that part of the supply feeding the voltage amplifier section. So resistor R6 is added together with C2 and ZD1 to maintain the amplifier’s supply voltage to a constant 10V.
Assemble the circuit on a general-purpose PCB and enclose in a suitable cabinet. Mount the diodes, electrolytic capacitors and transistors with the correct polarity. Output transistors T4 and T5 have a metalised surface on one side, which should face the centre of the board. A heat-sink is required for both the transistors. Either a small (20mm2) piece of aluminium or a commercially available heat-sink can be used. The heat-sinks on T4 and T5 should be insulated from the transistors with a piece of Mylar or similar material, as this transistor (and therefore the heat-sink) connects directly to the power supply.
Before applying power to the circuit, connect an 8-ohm load (resistor or loudspeaker) to the output, and capacitor C1 between the input terminal and the volume control. Set the volume control to minimum and then apply power—either from the plug pack or an external 12V DC supply.
Ensure that both the output transistors are cool when touched. If not, try adjusting preset VR3. The correct setting for VR3 should give a quiescent collector current of around 100 mA through T4 and T5.
August 6th, 2013 at 3:49 am
Usually, low-priced home stereo power amplifiers don’t have output level indicators. An output power level indicator can be added to each channel of these stereo power amplifiers. As low levels of the output power are not disturbing and damaging to the people, there is no need to add a preamplifier and low-level detector before IC LM3915. But you should know when the output power becomes considerably high.
Here we present a very simple, low-cost stereo-level indicator circuit for home power amplifiers with power rating of around 0.5W. The circuit is built around two LM3915 dot/bar display driver ICs (IC1 and IC2). LM3915 senses analogue voltage levels to drive ten LEDs, providing a logarithmic 3dB/step analogue display.
The voltage levels below 1V are not important because these correspond to a low level of the audio signal. Similarly, input voltage levels above 30V correspond to too high levels of the output power, which are not applicable for home power amplifiers. So the voltage levels of our interest are 1V to 30V, which can be handled directly with LM3915. LM3915 needs no protection against ±35V inputs, which simplifies the circuit.
Most audio power amplifiers can drive 2-ohm to around 32-ohm loads. A load of several kilo-ohms will not change the conditions for the amplifier. CON1 is the input connector and CON2 output connector for the loudspeaker or headphone. Each channel has its own LM3915 and ten LEDs to indicate the power level. To indicate the different audio levels, select LEDs of three colours as per your liking. For example, you can have five green LEDs, three yellow LEDs and two red LEDs.
If appropriate signal generators and measuring equipment are not available, the level indicator can be calibrated based on personal observations. For example, the audio signal should be in the green LEDs zone when the signal is strong enough but not irritating, in the yellow zone when it is disturbing or starting to get distorted, and in the red zone when it is heavily distorted or too strong to listen to in the room.
Calibration can be done with the help of potentiometers VR1 and VR2, which are optional. Switches S1 and S2 let you select between two modes of LM3915 operation—the bar mode and the dot mode. These too can be removed or replaced with jumpers, if not required. When the switches are removed, leave pins 9 of IC1 and IC2 open.
The circuit works off regulated 12V. You can also power it through a 12V rechargeable battery.
Assemble the circuit on a general-purpose PCB and enclose in a suitable cabinet. Fix all the LEDs in two rows on the front side of the cabinet. Also affix the two terminals for input and output on rear side of the cabinet.
August 6th, 2013 at 3:42 am
n areas like staircase or porch of your home, lighting is required only for a short period of time at night. We often forget to switch off these lights, which results in considerable wastage of electricity. Here is a simple circuit that switches off the lights automatically after a predetermined time. The circuit consumes no power when inactive.
Circuit and working
Fig. 1 shows the circuit of staircase light controller. It consists of opto-isolator MOC3041 (IC1), popular timer NE555 (IC2), triac BT136 (TRIAC1) and a few discrete components. Timer IC2 is configured in monostable mode. Momentarily pushing switch S1 triggers the timer (IC2), which keeps the triac conducting and the light bulb (B1) ‘on’ until the timer times out.
Producing a small DC voltage from AC mains to run an electronic control requires a step-down transformer or a voltage-dropping capacitor circuit. Here a tricky and easy solution is adopted. Bulb B1 gets power via the diode of bridge rectifier BR1 and zener diode ZD1. The voltage drop across zener diode ZD1 is filtered by capacitor C1. This voltage is sufficient to run the rest of the circuitry.
Working of the circuit is simple. Press switch S1 momentarily to turn bulb B1 ‘on.’ The bulb remains ‘on’ for around 20 seconds and then turns off automatically. This duration is long enough for you to find your way up or down the staircase in the dark. It can, however, be varied by changing the values of timing components R2 and C2.
August 6th, 2013 at 2:33 am
Make tube lights automatically switch on at night and switch off in daytime using this automatic control system. Automatic darkness-controlled lighting system means that whenever there is darkness, light source like bulb or tube-light glows automatically.
The circuit works off regulated 5V and uses triac BT136, NOT gate 7404 and light-dependent resistor (LDR).
Operation of the circuit is simple. During daytime, low resistance of LDR1 makes pin 1 of gate N1 low and its output pin 2 goes high. This high output is applied to input pin 3 of gate N2. As a result, the output of gate N2 goes low. Hence no gate signal is applied to triac BT136 (triac 1) and it acts as an open circuit and the bulb does not glow.
At night, the high resistance of LDR1 makes pin 1 of gate N1 high and its output pin 2 goes low. This low output is applied to input pin 3 of gate N2. As a result, the output of gate N2 goes high, which is applied to the gate of triac BT136 (triac 1) and it acts as a short circuit and the bulb start glowing.
Assemble the circuit on a general-purpose PCB and keep at a suitable place. Keep LDR1 at such a place that enough light falls on it in day-time. You can also use this circuit as a street light controller.
June 10th, 2013 at 3:24 pm
Now you need not fear dark nights when power breaks down. Here’s a white LED-based emergency light that automatically turns on when mains power supply fails.
The circuit consists of power supply, battery charger and switching sections. The power supply and charger sections are built around transformer X1, diodes D1 and D2, transistor T1, resistors R1 and R2, and zener diode ZD1. The power supply for the circuit is derived from AC mains by using 9V-0-9V, 250mA step-down transformer X1. Diodes D1 and D2 rectify the AC voltage into DC voltage, which is smoothed by filter capacitor C1. The unregulated DC voltage is regulated by transistor T1 along with resistor R1 and zener diode ZD1. The regulated DC voltage, via resistor R2, charges the lead-acid battery. Diode D3 connects the battery power supply to the switching circuit when mains power is unavailable.
The switching circuit is built around an NE555 timer (IC1), which is wired in monostable mode. When a low voltage is applied at trigger pin 2 of IC1, the timer activates and its output pin 3 goes high. It remains in that state until IC1 is triggered again at its pin 2.
Light-dependant resistor LDR1 is connected between the positive supply of the battery and trigger pin 2 of IC1. Resistor R3 is connected between pin 2 of IC1 and ground. The resistance value of LDR1 remains high in dark (at night) and low in ambient light (in daytime). This phenomenon is utilised to control the switching circuit.
Working of the circuit is simple. In daytime, when ambient light falls on LDR1, its resistance decreases to make trigger pin 2 of IC1 high. As a result, output pin 3 goes low and the LEDs (LED1 through LED7) remain off.
At night (in the dark), the resistance of LDR1 increases and a low voltage is applied to trigger pin 2 of IC1. This activates the monostable and its output goes high to make all the LEDs glow.
When mains power is available, reset pin 4 of IC1 is grounded via transistor T2 and its output pin 3 remains low. As a result, the LEDs don’t glow. When mains power fails, transistor T2 does not conduct and reset pin 4 of IC1 gets positive supply through resistor R5. As a result, the output of IC1 goes high to light up the LEDs. Due to pulsating DC output at pin 3 of IC1, it can drive seven LEDs (LED1 through LED7).
Assemble the circuit on a general-purpose PCB and enclose in a cabinet with enough space for the battery. Mount the seven white LEDs on the front panel of the box. Fix LDR1 away from the white LEDs to prevent their light from falling on LDR1.
May 27th, 2013 at 3:25 am
This circuit could be used to toggle on and off a NE555 output by a single momentary button. Similar circuits are often used instead of mechanical bistable relays, especially when the circuit must back to the start condition by switching off the power supply.
At the start condition pins 2 and 6 are supplied with half voltage, then the output (pin 3) keeps the low level. By pressing the button Q1 turns on with a small delay, while Q2 keeps off due to the collector of Q4. Once the capacitor is charged Q1 leads pin 2 and 6 to low voltage (about 3V) and prevents Q2 from switching on. By releasing the button the capacitor discharges. Since the output of the NE555 is now high Q3 and Q4 are off. So by pressing the button again Q2 switches on and leads pin 4 to low voltage (about 0V), then the circuit backs to the start condition.