PIC12F629 Lead-Acid Battery Desulfator

PIC12F629 Lead-Acid Battery Desulfator

Hi everyone,
After reading so many articles on Battery desulfator i’ve decided to come out with my version of Battery desulfator using
Microchip base micro-controller using PIC12F629 or PIC 12F675.

“Please pardon my english” .I don’t really have time to check for minor grammatical errors.

Before we begin this circuit although simple in design requires DIY builders to have at least basic PIC programming knowledge with electronics.

Honestly i had no programming knowledge initially.I started on my own on how to blink led using Pic micro-controller.

PIC12F629 Lead-Acid Battery Desulfator
PIC12F629 Lead-Acid Battery Desulfator

I have used this circuit i design to recover 5 Maintenance –free battery ranging from 12volts 2AH (UPS battery) to 7.2AH (Previously used in electric bicycle).I have not attempted to recover a CAR battery since i don’t have any old battery in my home.

I have recovered battery eg:2AH which had voltage as low as 0.9v which i have not charged  for around 8 years after removing battery from a defective home UPS.
I  have managed to recover 4 12v 7.2AH battery which i have not charged since 2004.These batteries were in my self assembled electric bicycle years ago.

These batteries were all recovered in within 48hours.For a car battery it would take weeks maybe.

Battery desulfator circuit i used while with charging battery with 12volt 500ma transformer.
I’d believe using slow and steady approach do produce better result most of the time.

The frequency output from Pin 7 is 56us on with 1ms off in a infinite loop.
During programming i have set it to use internal 4MHZ PIC oscillator which have 1% tolerance and i have disabled reset /mclr.
There is only 3 connection to pic.

I noted the current consumption of the desulfator circuit is around 13 to 15mA with a well desulfated battery if connected to the charger with voltage around 13.8volts.

I noted if a old battery needs to be desulfated the voltage would increase up to 17.xx volts on battery with desulfator  circuit consuming about 40 to 50mA.

The D1  diode i used is the fastest recovery diode i could find with 25ns response time.
The purpose of D2 is to prevent accidental polarity reverse at the input to protect the circuit.D2 could be replace with higher amp rating like IN5820 if needed.
It’s better to obtain C1&C2 capacitor which have a low ESR rating with at least 50V.
For L2 toroid if you could get anything from 170uh to 220uh would be sufficient.Please do not wind higher than 30 turns as the resistance would increase and hence lower the circuit efficiency as well.To be honest i don’t know the uH rating for my self made toroid but i got results which what matters in the end.

For the mosfet if you could find a lower turn on resistance with low turn on/off delayswhich will definitely improve the efficiency of the circuit.

I have connected a piezo speaker temporarily to old battery which needs to be charged since it would have higher internal-resistance.i noticed the piezo speaker would emit a loud 1KHZ sound.But if the battery is already well desulfated i noticed the piezo speaker connected temporarily to battery would hardly emit any sound at all.
We could use piezo speaker as a quick way to test to know if battery to be charged is well desulfated or internal resistance of the batery is already being lowered.

Digital Ammeter Circuit using PIC Microcontroller and ACS712

Digital Ammeter Circuit using PIC Microcontroller and ACS712

Measuring the voltage and current will always be helpful while making or debugging any electrical system. In this project we are going to make our own Digital Ammeter using PIC16F877A Microcontroller and current sensor ACS712-5A. This project can measure both AC and DC current with a range of 0-30A with an accuracy of 0.3A. With few modifications on the code you can also use this circuit to measure up to 30A. So let us get started!!!

Materials Required:

  1. PIC16F877A
  2. 7805 Voltage Regulator
  3. ACS712 current Sensor
  4. 16*2 LCD display
  5. A junction box and load (Just for testing)
  6. Connecting wires
  7. Capacitors
  8. Breadboard.
  9. Power supply – 12V

Working of ACS712 Current Sensor:

Before we start building the project it is very important for us to understand the working of the ACS712 Current sensor as it is the key component of the project. Measuring current especially AC current is always a tough task due to the noise coupled with it improper isolation problem etc. But, with the help of this ACS712 module which was engineered by Allegro thing have become a lot easier.

This module works on the principle of Hall-effect, which was discovered by Dr. Edwin Hall. According his principle, when a current carrying conductor is placed into a magnetic field, a voltage is generated across its edges perpendicular to the directions of both the current and the magnetic field. Let us not get too deep into the concept but, simply put we use a hall sensor to measure the magnetic field around a current carrying conductor. This measurement will be in terms of millivolts which we called as the hall-voltage. This measured hall-voltage is proportional to the current that was flowing through the conductor.

The major advantage of using ACS712 Current Sensor is that is can measure both AC and DC current and it also provides isolation between the Load (AC/DC load) and Measuring Unit (Microcontroller part). As shown in the picture we have three pins on the module which are Vcc, Vout and Ground respectively.

Digital Ammeter Circuit using PIC Microcontroller and ACS712

Current Sensor Module ACS712-5A

The 2-pin terminal block is where the current carrying wire should be passed through. The module work on +5V so the Vcc should be powered by 5V and the ground should be connected to Ground of the system. The Vout pin has an offset voltage of 2500mV, meaning when there is no current flowing through the wire then the output voltage will be 2500mV and when current flowing is positive, the voltage will be greater than 2500mV and when the current flowing is negative, the voltage will be less than 2500mV.

We will be using the ADC module of the PIC microcontroller to read the output voltage (Vout) of the module, which will be 512(2500mV) when there is no current flowing through the wire. This value will reduce as the current flows in negative direction and will increase as the current flows in positive direction. The below table will help you understand how the output voltage and ADC value varies based on the current flowing through the wire.

Digital Ammeter Circuit using PIC Microcontroller and ACS712

These values were calculated based on the information given in the Datasheet of ACS712. You can also calculate them using the below formulae:

Vout Voltage(mV) = (ADC Value/  1023)*5000
Current Through the Wire (A) = (Vout(mv)-2500)/185

Now, that we know how the ACS712 Sensor works and what we could expect from it. Let us proceed to the circuit diagram.

Circuit Diagram:

The complete circuit diagram of this Digital Ammeter Project is shown in the image below.

Digital Ammeter Circuit using PIC Microcontroller and ACS712

The complete digital current meter circuit works on +5V which is regulated by a 7805 Voltage regulator. We have used a 16X2 LCD to display the value of the current. The output pin of the current Sensor (Vout) is connected to the 7th pin of the PIC which is the AN4 to read the Analog voltage.

Further the pin connection for the PIC is shown in the table below


Pin Number

Pin Name

Connected to








E of LCD




D4 of LCD




D5 of LCD




D6 of LCD




D7 of LCD




Vout of Current Sesnor

You can build this digital ammeter circuit on a breadboard or use a perf board.  If you have been following the PIC tutorials then you can also reuse the hardware that we used for learning PIC microcontrollers.  Here we have used the same perf Board which we have built for LED Blinking with PIC Microcontroller, as shown below:

Digital Ammeter Circuit using PIC Microcontroller and ACS712

Note: It is not mandatory for you to build this board you can simply follow the circuit diagram and build you circuit on a bread board and use any dumper kit to dump your program into the PIC Microcontroller.


This current meter circuit can also be simulated using Proteus before you actually proceed with your Hardware. Assign the hex file of the code given at the end of this tutorial and click on play button. You should be able to notice the current on the LCD display. I have used a Lamp as an AC load, you can vary the internal resistance of the Lamp by clicking on it to vary the current flowing through it.

Digital Ammeter Circuit using PIC Microcontroller and ACS712

As you can see in the above picture, the Ammeter shows the actual current flowing through the Lamp which is around 3.52 A and the LCD shows the current to be around 3.6A. However in practical case we might get Error up to 0.2A. The ADC value and voltage in (mV) is also shown on the LCD for your understanding.

Programming the PIC Microcontroller:

As told earlier, the complete code can be found at the end of this article. The code is self explained with comment lines and just involves the concept of interfacing a LCD with PIC Microcontroller and Using ADC module in PIC Microcontroller which we have already covered in our previous tutorials of learning PIC Microcontrollers.

The value read from the sensor will not be accurate since the current is alternating and is also subjected to noise. Hence we read the ADC value for 20 Times and average it to get the appropriate current Value as shown in the code below.

We have used the same formulae which was explained above to calculate the voltage and Current value.

        for (int i=0; i<20;i++) //Read value for 20 Times
        adc=ADC_Read(4); //Read ADC
        Voltage = adc*4.8828; //Calculate the Voltage
        if (Voltage>=2500) //If the current is positive
              Amps += ((Voltage-2500)/18.5);
        else if (Voltage<=2500) //If the current is negative
              Amps += ((2500-Voltage)/18.5);

        Amps/=20;  //Average the value that was read for 20 times

Since this project can also read AC current the current flow will be negative and positive as well. That is the value of the output voltage will be above and below 2500mV. Hence as shown below we change the formulae for negative and positive current so that we do not get negative value.

        if (Voltage>=2500) //If the current is positive
              Amps += ((Voltage-2500)/18.5);
        else if (Voltage<=2500) //If the current is negative
              Amps += ((2500-Voltage)/18.5);

Using a 30A current sensor:

If you need to measure current more than 5A you can simply buy a ACS712-30A module and interface it the same way and change the below line of code by replacing 18.5 with 0.66 as shown below:

        if (Voltage>=2500) //If the current is positive
              Amps += ((Voltage-2500)/0.66);

        else if (Voltage<=2500) //If the current is negative
              Amps += ((2500-Voltage)/0.66);


Once you have programmed the PIC Microcontroller and made your hardware ready. Simply power on the load and your PIC microcontroller you should be able to see the current passing through the wire displayed in your LCD screen.

NOTE: IF you are using a ASC7125A module make sure your load does not consume more than 5A also use higher gauge wires for current carrying conductors.

Digital Ammeter Circuit using PIC Microcontroller and ACS712

The complete working of the PIC microcontroller based ammeter project is shown in the Videobelow. Hope you got the project working and enjoyed doing it. If you have any doubts you can write them on the comment section below or post them on our forums.

Digital Ammeter for PIC16F877A
 * Code by: B.Aswinth Raj
 * Dated: 27-07-2017
 * More details at: //picmicrocontroller.tk
#define _XTAL_FREQ 20000000
#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
#include <xc.h>
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
//LCD Functions Developed by Circuit Digest.
void Lcd_SetBit(char data_bit) //Based on the Hex value Set the Bits of the Data Lines
if(data_bit& 1)
D4 = 1;
D4 = 0;
if(data_bit& 2)
D5 = 1;
D5 = 0;
if(data_bit& 4)
D6 = 1;
D6 = 0;
if(data_bit& 8)
D7 = 1;
D7 = 0;
void Lcd_Cmd(char a)
RS = 0;
Lcd_SetBit(a); //Incoming Hex value
EN  = 1;
        EN  = 0;
void Lcd_Clear()
Lcd_Cmd(0); //Clear the LCD
Lcd_Cmd(1); //Move the curser to first position
void Lcd_Set_Cursor(char a, char b)
char temp,z,y;
if(a== 1)
 temp = 0x80 + b – 1; //80H is used to move the curser
z = temp>>4; //Lower 8-bits
y = temp & 0x0F; //Upper 8-bits
Lcd_Cmd(z); //Set Row
Lcd_Cmd(y); //Set Column
else if(a== 2)
temp = 0xC0 + b – 1;
z = temp>>4; //Lower 8-bits
y = temp & 0x0F; //Upper 8-bits
Lcd_Cmd(z); //Set Row
Lcd_Cmd(y); //Set Column
void Lcd_Start()
  for(int i=1065244; i<=0; i–)  NOP();
  Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
  Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD
  Lcd_Cmd(0x08); //Select Row 1
  Lcd_Cmd(0x00); //Clear Row 1 Display
  Lcd_Cmd(0x0C); //Select Row 2
  Lcd_Cmd(0x00); //Clear Row 2 Display
void Lcd_Print_Char(char data)  //Send 8-bits through 4-bit mode
   char Lower_Nibble,Upper_Nibble;
   Lower_Nibble = data&0x0F;
   Upper_Nibble = data&0xF0;
   RS = 1;             // => RS = 1
   Lcd_SetBit(Upper_Nibble>>4);             //Send upper half by shifting by 4
   EN = 1;
   for(int i=2130483; i<=0; i–)  NOP();
   EN = 0;
   Lcd_SetBit(Lower_Nibble); //Send Lower half
   EN = 1;
   for(int i=2130483; i<=0; i–)  NOP();
   EN = 0;
void Lcd_Print_String(char *a)
int i;
  Lcd_Print_Char(a[i]);  //Split the string using pointers and call the Char function
/*****End of LCD Functions*****/
//**ADC FUnctions***//
void ADC_Initialize()
  ADCON0 = 0b01000001; //ADC ON and Fosc/16 is selected
  ADCON1 = 0b11000000; // Internal reference voltage is selected
unsigned int ADC_Read(unsigned char channel)
  ADCON0 &= 0x11000101; //Clearing the Channel Selection Bits
  ADCON0 |= channel<<3; //Setting the required Bits
  __delay_ms(2); //Acquisition time to charge hold capacitor
  GO_nDONE = 1; //Initializes A/D Conversion
  while(GO_nDONE); //Wait for A/D Conversion to complete
  return ((ADRESH<<8)+ADRESL); //Returns Result
//***End of ADC Functions***//
int main()
    int adc=0; //Variable to read ADC value
    int a1,a2,a3,a4; //Variable to split ADC value into char
    int Voltage; //Variable to store voltage
    int vl1,vl2,vl3,vl4; //Variable to split Voltage value into char
    int Amps; //Variable to store Amps value
    int Am1,Am2,Am3,Am4; //Variable to split Amps value into char
    TRISD = 0x00; //PORTD declared as output for interfacing LCD
    TRISA4 =1; //AN4 declared as input
        /***Current Calculation*****/
        for (int i=0; i<20;i++) //Read value for 20 Times
        adc=ADC_Read(4); //Read ADC
        Voltage = adc*4.8828; //Calculate the Voltage
        if (Voltage>=2500) //If the current is positive
              Amps += ((Voltage-2500)/18.5);
        else if (Voltage<=2500) //If the current is negative
              Amps += ((2500-Voltage)/18.5);
        Amps/=20;  //Average the value that was read for 20 times
        /******Current Calculation******/
        //**Display current**//
        Am1 = (Amps/100)%10;
        Am2 = (Amps/10)%10;
        Am3 = (Amps/1)%10;
        Lcd_Print_String(“Current: “);
         //**Display ADC**//
        a1 = (adc/1000)%10;
        a2 = (adc/100)%10;
        a3 = (adc/10)%10;
        a4 = (adc/1)%10;
      //**Display Voltage**//
        vl1 = (Voltage/1000)%10;
        vl2 = (Voltage/100)%10;
        vl3 = (Voltage/10)%10;
        vl4 = (Voltage/1)%10;
        Lcd_Print_String(” V:”);
    return 0;

X10 Speech Recognition Interface

X-10 is an international technology that provides an easy method of creating home automation. Marry this technology with a speech recognition circuit and the user can use verbal commands to activated electrical appliances and lights around the home or apartment. If this is of interest to you then read on.

The X-10 Interface circuit will allow you to control up to 16 appliance control modules on any of the sixteen available X-10 house codes using the SR-07 speech recognition circuit. The SR-07 speech recognition circuit has its own construction article here and that information will not be repeated here. You may purchase the speech recognition circuit in a kit form (SR-06), or a fully assembled and tested circuit (SR-07) from Images SI Inc., see parts list. The X-10 speech interface requires the speech recognition circuit to function. The speech recognition circuit is the front end of the system.

The speech recognition circuit and components are NOT rated for medical use, critical care or when the possibility of a non-functioning or non-recognized command may cause damage, personal injury or put anyone or thing in jeopardy.

X-10 Technology

X-10 technology has been in the United States since 1978, introduced into our country by Sears and Radio-Shack. It uses the home’s household wiring (power grid) that powers electrical appliances to transmit and receive control commands to the appliances. There are a variety of X-10 commands at our disposal that include; on, off, dim/bright, all on, all off, etc., see table below. Our X-10 speech interface will issue only the basic on and off commands.

It appears that Radio-Shack no longer is carrying X-10 hardware. No matter, X-10 has many distributors including Amazon.com and Images SI Inc. You can also purchase X10 hardware from the official X10 site at //www.x10.com/automation/index.html. There is a dizzying array of X10 components available. You require two X-10 components, the PL-513 Power Line interface, see figure 1 and at least one appliance controller AMC486 see figure 2. If you wish to run more than one appliance, you would need an equal number of appliances.

X-10 Command Codes

Code              Function Description
0 0 0 0 1        All Units Off Switch off all devices
0 0 0 1 1        All Lights On Switches on all lighting devices
0 0 1 0 1        On Switches on a device
0 0 1 1 1        Off Switches off a device
0 1 0 0 1        Dim Reduces the light intensity
0 1 0 1 1        Bright Increases the light intensity
0 1 1 1 1        Extended Code Extension code
1 0 0 0 1        Hail Request Requests a response from the device(s)
1 0 0 1 1        Hail Acknowledge Response to the previous command
1 0 1 x 1        Pre-Set Dim Selection of two predefined levels of light intensity
1 1 0 1 1        Status is On Response indicating that the device is on
1 1 1 0 1        Status is Off Response indicating that the device is off

Aside from the commands, listed above, the X-10 signal protocol also consists of an address.

Hardcore Micros – Microchips PIC10F32x

As an embedded engineer I’m always looking for more and more functions from a smaller and smaller package. Over the last six months, Microchip has been releasing information about the smallest of its chips – PIC10F32x – and in this post I want to look at the new and interesting features coming to PICs.

Up till now when I have looked at the very small end of the micro range, the PIC10s have never offered anything that would get me excited or convince me that they are very usable. At ebmpapst, when I’m designing bottom-end tiny products, I need at least one PWM, so I have been using what I would have called a slightly overspec PIC12F615 for my products.

In the last few weeks however, Microchip has released the Data Sheet for the PIC10F320 and PIC10F322. These I have been looking at using for some time; however, it was the added features of these two new chips that stand out to me, and I’m not just talking about the added Flash and RAM or PWMs they now have.

The first new shiny feature is Configurable Logic Cells (CLC). The PIC10 is not the first to have these, as there is a new breed of PIC12s and 16s that have these too. However, having this and the other features on such a small chip is to me surprising and also powerful.

CLCs are chunks of combinational logic that can be configured to perform high-speed functions without needing core processing time. Each block has 8 inputs that can come from I/O pins, internal clocks, Peripherals, or even from register bits. These inputs can then be passed through one of a number of pre-configured logic blocks that perform functions like AND-OR, S-R, J-K and D type flip-flops. What’s then quite nice is that an external pin can be driven directly from this output, read internally, or it can even generate an interrupt. It may not have the flexibility and programmability of, say, a FPGA LAB, but I can see these becoming very useful glue logic tools for embedded engineers.

Another nice feature to find in such a small chip is the Complementary Waveform Generator (CWG). This allows you generate controllable waveforms for use in a half bridge or switching power supply for example. The module allows for selectable input sources and have some nice and simple auto-shutdown controls. Dead time is also programmable for both the rise and fall side. I’ve seen similar modules on the larger chips but found this much easier to understand and more independent of the code that may be running on the core.

Both the CLC and CWG could be really nice units if only you have a clock source that is easy to control and whose frequency is easy to set. Well the chips now also come with a Numerically Controlled Oscillator (NCO) that can be used to feed the above CLC and CWG modules. This is no Phase Lock Loop (PLL) but will allow for simple clock division. The module works by having a configured value added to an accumulator on each clock cycle. The overflow is then used as a raw output that can be used to drive the module in a number of modes. For example, simple toggling of the output allows for a fixed 50 percent duty, or you can use the module for pulsed frequencies with output pulse width control.

The new features could very well be a clue to where Microchip is going with new designs, maybe trying out these features on the smaller silicon before it makes its way up to the 32bit cores. However, these new features are a welcome sight to me as an embedded engineer. I like the idea of getting more and more features inside small chips – my designs do not need a lot of I/O pins but they need to be clever. I really don’t want to be using a whopping big QFP just to get the features, but suffer with the high pin count.

Climate Controller Designed with PIC

The Sensirion SHT11 sensor is utilized by this climate controller in order to read the temperature and humidity measurements simultaneously.

The measurement and display scale of the climate controller can be selected between Centigrade and Fahrenheit as the temperature measurement ranges from -40° to 123°C and humidity is 0-100% temperature compensated. Some of the uses of this device include food dehydrating, hatchling warmer, small room temp/humidity control, and Greenhouse temperature/humidity control.

The three distinct CD outputs with 10A load or 2DC outputs with one AC up to 4A are managed by the controller board. It also reads the sensor, switches the outputs, reads the rotary encoder, and updates the LCD display. The controller board can be used as a standalone device if temperature and humidity readings only are required.

The sensor uses the combined humidity and temperature sensor SHT11 from Sensirion which comes in a SMDpackage. It is designed from a double sided PCB so that the more obtainable and handy 8-pin DIP carrier version is allowed to be used. A 14-bit analog to digital converter is contained in the sensor for temperature conversion which results in a maximum resolution of 0.1°C.

Data Encryption Routines for PIC24 and dsPIC Devices

Currently, there are three data encryption standards approved for use in the Federal Information Processing Standards (FIPS). This application note discusses the implementation of two of these for PIC24 and dsPIC30/33 devices: Triple Data Encryption Standard (TDES) and Advanced Encryption Standard (AES).

TDES Encryption
The original Data Encryption Standard (DES), a 64-bit block cipher, was invented in the early 1970s by IBM®. DES uses a 64-bit encryption key: 56 bits for encoding and decoding, the remainder for parity. It was adopted by the United States government in 1977 as standard for encrypting sensitive data. By the mid 1990s, several public organizations had demonstrated that they were able to crack a DES code within days.

Triple DES (TDES) is a variant of DES, and is described in FIPS 46-2 and 46-3. TDES uses three cycles of DES to extend the key from 56 bits to 112 or 168 bits, depending on the mode of operation. Because of known weaknesses in the DES algorithm, the actual security is believed to be on the order of 80 and 112 bits, respectively, for the two different methods. The use of TDESwas suggested by the American government in 1999 for use in all systems, except in legacy systems, where only DES was available.

There are several different modes of TDES. The most common involves using two different keys. The data is encrypted with the first key. That result is then decrypted with the second key. The data is then finally encrypted once again with the first key. Other modes of operation include using three different keys, one for each of the stages, and encrypting in all rounds instead of decrypting during the second round. For most new applications, TDES has been replaced with Advanced Encryption Standard (AES). AES provides a slightly higher security level than TDES and is much faster and smaller in implementation than TDES.

The original DES algorithm is outlined in Figure 1. The cycle is run 32 times before the ciphertext is valid.

PIC Controlled Relay Driver

This circuit is a relay driver that is based on a PIC16F84A microcontroller. The board includes four relays so this lets us to control four distinct electrical devices. The controlled device may be a heater, a lamp, a computer or a motor. To use this board in the industrial area, the supply part is designed more attentively. To minimize the effects of the ac line noises, a 1:1 line filter transformer is used.

1 x PIC16F84A Microcontroller
1 × 220V/12V 3.6VA (or 3.2VA) PCB Type Transformer (EI 38/13.6)
1 x Line Filter (2×10mH 1:1 Transformer)
4 × 12V Relay (SPDT Type)
4 x BC141 NPN Transistor
5 × 2 Terminal PCB Terminal Block
4 × 1N4007 Diode
1 × 250V Varistor (20mm Diameter)
1 x PCB Fuse Holder
1 × 400mA Fuse
2 × 100nF/630V Unpolarized Capacitor
1 × 220uF/25V Electrolytic Capacitor
1 × 47uF/16V Electrolytic Capacitor
1 × 10uF/16V Electrolytic Capacitor
2 × 330nF/63V Unpolarized Capacitor
1 × 100nF/63V Unpolarized Capacitor
1 × 4MHz Crystal Oscillator
2 × 22pF Capacitor
1 × 18 Pin 2 Way IC Socket
4 × 820 Ohm 1/4W Resistor
1 × 1K 1/4W Resistor
1 × 4.7K 1/4W Resistor
1 × 7805 Voltage Regulator (TO220)
1 × 7812 Voltage Regulator (TO220)
1 × 1A Bridge Diode

The transformer is a 220V to 12V, 50Hz and 3.6VA PCB type transformer. The model seen in the photo is HRDiemen E3814056. Since it is encapsulated, the transformer is isolated from the external effects. A 250V 400mA glass fuse is used to protect the circuit from damage due to excessive current. A high power device which is connected to the same line may form unwanted high amplitude signals while turning on and off. To bypass this signal effects, a variable resistor (varistor) which has a 20mm diameter is paralelly connected to the input.

Controller schematic

Another protective component on the AC line is the line filter. It minimizes the noise of the line too. The connection type determines the common or differential mode filtering. The last components in the filtering part are the unpolarized 100nF 630V capacitors. When the frequency increases, the capacitive reactance (Xc) of the capacitor decreases so it has a important role in reducing the high frequency noise effects. To increase the performance, one is connected to the input and the other one is connected to the output of the filtering part.

Supply schematic

After the filtering part, a 1A bridge diode is connected to make a full wave rectification. A 2200 uF capacitor then stabilizes the rectified signal. The PIC controller schematic is given in the project file. It contains PIC16F84A microcontroller, NPN transistors, and SPDT type relays. When a relay is energised, it draws about 40mA. As it is seen on the schematic, the relays are connected to the RB0-RB3 pins of the PIC via BC141 transistors. When the transistor gets cut off, a reverse EMF may occur and the transistor may be defected.

To overcome this unwanted situation, 1N4007 diodes are connected between the supply and the transistor collectors. There are a few number of resistors in the circuit. They are all radially mounted. Example C and HEXcode files are included in the project file. It energizes the next relay after every five seconds.

Sinusoidal Control of PMSM Motors with dsPIC30F / dsPIC33F DSC

Motor Control Pulse Width Modulation (MCPWM) and high-speed A/D Converter. The DSP engine of the dsPIC30F2010 supports the necessary fast mathematical operations. The dsPIC30F2010 family member is a 28-pin 16-bit DSC specifically designed for low-cost/high efficiency motor control applications. The dsPIC30F2010 provides these key features: · 30 MIPS processing performance · Six independent or three complementary pairs of dedicated Motor Control PWM outputs · Six-input, 1 Msps ADC with simultaneous sampling capability from up to four inputs · Multiple serial communications: UART, I2CTM and SPI · Small package (6 mm x 6 mm QFN) for embedded control applications · DSP engine for fast response in control loops
This application note describes a method of driving a sensored Permanent Magnet Synchronous Motor (PMSM) with sinusoidal currents controlled by a dsPIC30F Digital Signal Controller (DSC). The motor control firmware uses the dsPIC30F peripherals while the mathematical computations are performed by the DSP engine. The firmware is written in `C’ language, with some subroutines in assembly to take advantage of the special DSP operations of the dsPIC30F.
· Sinusoidal current generation for controlling PMSM motor phases using Space Vector Modulation (SVM) · Synchronization of sinusoidal voltages to PMSM motor position · Four-quadrant operation allowing forward, reverse and braking operation · Closed-loop speed regulation using digital Proportional Integral Derivative (PID) control · Phase advance operation for increased speed range · Fractional math operations performed by the DSP engine of the dsPIC® DSC
You will need the following hardware to implement the described motor control application: · PICDEMTM MCLV Development Board (Figure 1) · Hurst DMB0224C10002 BLDC Motor · 24 VDC Power Supply You can purchase these items from Microchip as a complete kit or as individual components. Check the Development Tools section of the Microchip web site for ordering information.
The dsPIC30F Motor Control family is specifically designed to control the most popular types of motors, including AC Induction Motors (ACIM), Brushed DC Motors (BDC), Brushless DC Motors (BLDC) and Permanent Magnet Synchronous Motors (PMSM), to list a few. Several application notes have been published for ACIM operation (AN984, AN908 and GS004) and Brushless DC Motor Control operation (AN901, AN957 and AN992) based on the dsPIC30F motor control family. These application notes are available on the the Microchip web site (www.microchip.com). This application note demonstrates how the dsPIC30F2010 is used to control a sensored PMSM motor with sinusoidal voltages. The design takes advantage of dsPIC30F peripherals specifically suited
© 2005 Microchip Technology Inc.
It is strongly recommended that you read the “PICDEMTM MCLV Development Board User’s Guide” (DS51554) to fully understand the hardware topology being used in this application note. This User’s Guide can be downloaded from the Microchip web site. Figure 2 is a simplified system block diagram for a Sinusoidal PMSM motor control application. This diagram will help you develop your own hardware. On the low side, the voltage limit is 10V. On the high side, the voltage limit is 48V. It is important to note that the heat sink on the IGBTs have very limited heat dissipation, so high power requirements may not be easily met with the PICDEMTM MCLV development board. To use the PICDEMTM MCLV development board for this application, use the jumper settings shown in Table 1 and the motor connections shown in Table 2 and Table 3.
Position for Sinusoidal Control (dsPIC® DSC Sensored) Open Open Open Short
Phase A 3-Phase Phase B Inverter Phase C 3-Phase PMSM Motor
Jumpers J7, J8, J11 J12, J13, J14
J15, J16, J17, J10 J19
AN2 Reference Speed S2 Start/Stop RB3/CN5 RB4/IC7 RB5/IC8 Hall A R21 Hall B R22 Hall C R25
Position for Sinusoidal Control (dsPIC® DSC Sensored) Phase A (White) Phase B (Black) Phase C (Red) Ground (Green) if available
Connector J9 M3 M2 M1 G
Salient aspects of this topology are: · Potentiometer R14 selects the desired speed (Reference Speed) · Rotor position is detected using Hall effect sensors connected to pins RB3, RB4 and RB5 · Current feedback is provided through a simple operational amplifier circuit · Fault input is received through a comparator circuit connected with the current feedback circuit. The current is sensed using a 0.1 ohm resistor (R26) You can easily adjust the values of the resistors to accommodate the current capabilities of the motor being used for your application. The motor drive circuit, on the other hand, is designed to drive a 24V PMSM motor. You can change the hardware to meet the drive requirement of a specific motor. Note: Refer to the “PICDEMTM MCLV Development Board User’s Guide” (DS51554) for details on how to change the hardware for use with motors greater or less than 24V.
Position for Sinusoidal Control (dsPIC® DSC Sensored) Red Black White Brown Green
Connector J9 +5V GND HA HB HC *
The colors referenced in Tables 2 and 3 for the motor windings and hall sensors, respectively, pertain to the Hurst 24V motor available from Microchip. The ground wire is sometimes not available on some motors.
After your code is developed and you have downloaded it to the dsPIC30F, you will need to press switch S2 to start and stop the motor. The potentiomer marked REF (R14) sets the required speed and direction of rotation of the motor. The motor does not need to stop to change direction of rotation.
© 2005 Microchip Technology Inc.

Introducing Microchip’s GC Family – An Intelligent Analog MCU

An increasing market demand for sophisticated products that interface the digital world of 1s and 0s with the “real-world” has catapulted the need for analog solutions. Consumer devices, from cells phones and music players to blood pressure and glucose meters, are all part analog, and companies like Microchip Technology are more than suited for ensuring their agile development and deployment.

The announcement of Microchip’s latest family of analog microcontrollers—the GC family—expands upon their portfolio of analog intensive applications. It joins the sophisticated PIC line, tailored for advanced applications like motor control, digital power, and automotive lighting, and the PIC24F line, suited for cost-sensitive applications such as low-cost motor control and LED lighting. By embedding Intelligent Analog, Microchip’s GC family of microcontrollers offers designers reduced development costs, consistent analog performances from one design to the next, and faster market delivery. As Jason Tollefson, Senior Marketing Manager at Microchip, told EEWeb, “The GC [family] is the latest and most sophisticated that we’ve done.”

What sets the GC family apart?
The PIC24F “GC” family integrates several new design enhancements, including a 16-bit Delta Sigma microcontroller and a 10 megasample-per-second (MSPS) analog-to-digital (A/D). “It’s the first time we’ve done both of these microcontrollers on one product,” Jason told us. And, for Microchip’s advanced analog integration, these enhancements on one product, “Is a really high watermark.”

In addition to dual microcontrollers, the GC family also incorporates an “analog signal chain” that encompasses dual mega-sample digital-to-analog converters, dual op-amps, and three comparators, all of which interact with high precision analog-to-digital converters. “All of that is interconnectable within the chip, so that you can create analog circuits within the chip and then present only the pieces to the outside world that are required. that helps us with the noise__ we’re not bringing signals out to the board level, and bringing them back in with the possibility of coupling noise from some external component,” explained Jason.

With the GC family, Microchip has done the work ahead of time. As Jason told EEWeb, “By bringing those components on board, the Microchip design team has now contended with noise and interference with digital blocks and we’ve also contended with communication paths and taking out roadblocks. By bringing those components on, the designer has a chip that has those components embedded and they get consistent analog performances from one design to the next. As they design new applications, they don’t have to worry about if they’re designing this analog on this particular board correctly—that’s all embedded in the microcontroller—they just have to worry about interfacing with their sensors.” The integration of multiple blocks inside one chip allows them to be controlled by software that the designer develops, thereby reducing design costs and ensuring faster time-to-market.

Flexible Features for Designers
The GC family offers several features to ensure designers needed flexibility and end-product quality. These include a programmable block referred to as the Programmable Gain Amplifier (PGA), an interconnected switch, and a Peripheral Pin Select.

The PGA which serves as the input to the 16-bit Sigma Delta, provides developers four levels of programmable gain, up to 16x the original size. This, in turn can be combined with the op-amps to create differential input and gain stage. The interconnected switch enables developers to tie into multiple components and programmatically configure signal paths to different devices. Because each component is under software control, developers can make refinements “on the fly.” This enhancement is achieved by the inclusion of muxes into each of the different blocks. “The idea,” explained Jason, “Is that outputs at certain blocks feed into the inputs of other blocks and vice versa. So, it’s quite flexible in that the muxes have a huge amount of inputs.”

The Peripheral Pin Select serves as a re-mapping feature, allowing developers, using software control, to remap peripherals away from pins to other pins. As Jason articulated, “There’s a certain combination of analog and digital peripherals that a customer needs and [the developer] can manipulate where these digital peripherals come out to make use of them to sort of preserve the analog and also allow them to make the most use of their design.”

Features for Rich Applications
The GC Family is the second device in the PIC24 family to include a Direct Memory Access controller (DMA). The DMA serves to facilitate the transfer of data between the CPU and the peripherals without CPU assistance and in doing so, saves power. It also allows the device, “To do two things as once,” said Jason, “We can have our core doing a function and updating the LCD with new information, while in the background, our DMA can be streaming information from [the] 50 channels of A to D into a RAM space.”

Another noteworthy attribute of the GC Family is the ability tailor the presentation of rich information to the end user. If the designer chooses to implement a screen for example, they can show icons that can be animated, they can also show information in text form, or even simple graphic form. With the rich information display, explained Jason, “You can present specific procedures to a user rather than a blinking icon and a number. You can tell them how to apply the sample, when to apply the sample, and if they want to upload the data or results of the information to a smart phone or to a PC, it can walk them through that process as well. With an aging community of diabetic folks, that might be more important to be able to walk them through the process so that there’s not as much jeopardy of them doing the process incorrectly and the data not being valid.”

These features, coupled with USB and LCD touch sensing interfacing, along with Microchip’s XLPtechnology to ensure extended battery life, make the GC family an ideal choice for medical and industrial applications. As Jason indicated, “[Microchip] looked a lot at the medical space—that’s one of our key targets with the family—so things like blood pressure meters, glucose meters, and so on. We also looked at industrial applications, so things like lab instrumentation, environmental quality testers, data loggers, production tracks where they need high-speed sensors, and even things like mining where the miners wear portable gas sensors to make sure they’re not being exposed to dangerous chemicals.”

In order to service the spectrum of designers that will be developing these applications, Microchip included high-speed 12-bit and 16-bit A/D converters. Whereas, in the past developers were limited to using only one A/D converter, providing both expands the capabilities of the end application. The high-speed 12-bit A/D converter, for example could be used to quickly analyze an area of interest, after which time, the 16-bit A/D convertor could be used to collect very fine detail on a subset of data.

Development Kit
To help designers get started, Microchip has developed the PIC24F Starter Kit for Intelligent Analog. The analog header that accompanies the kit can plug directly into the board; Sensors can also be connected to the board itself, which can in turn interface with the analog header. As Jason explained, “We designed the board to be very clean; [the] analog signals are routed away from digital so you’ll get the best representation of the analog you need to conceive of coming out of the header.”

To make things interesting for designers who get the developer kit and showcase the capabilities of the LCD display, Microchip has included onboard sensors with associated demos and menus. These include a microphone demo, a headphone demo, and a light sensor demo. There is also a demo revolving around the A/D convertors themselves. To assist with the programming, Microchip has even thrown in a built-in programmable debugger.

PC for lab software, the board itself, and a USB cable is everything a designer needs to get started on developing a prototype for an end application. With the release of the GC Family, concluded Jason, “We are trying to anticipate all the things that our designers [of] portable applications would want to do and put that on our board in terms of hardware and software so that they can leverage that to the maximum extent.”

MLX90614 SMBus Implementation in PIC MCU

This document presents the MLX90614 infrared thermometers SMBus communication in PIC microcontrollers. This document also describes the applications of the infrared thermometers, as well as typical circuit examples and an assembler and C example of the development tool used.


This application note describes how to implement SMBus communication with MLX90614 Infrared thermometers. Code is for Microchip’s PIC18. The example is MLX90614’s RAM reading. Software implementation of SMBus communication is used so the source code can be migrated for other families 8 bits PIC MCU with small changes. The development tools used are MPLAB IDE and MPSAM (Microchip Assembler) which are free to use and MCC18 (MPLAB C18 Compiler) for which an evaluation version is available from Microchip official website.


  • High precision non-contact temperature measurements;
  • Thermal Comfort sensor for Mobile Air Conditioning control system;
  • Temperature sensing element for residential, commercial and industrial building airconditioning;
  • Windshield defogging;
  • Automotive blind angle detection;
  • Industrial temperature control of moving parts;
  • Temperature control in printers and copiers;
  • Home appliances with temperature control;
  • Healthcare;
  • Livestock monitoring;
  • Movement detection;
  • Multiple zone temperature control – up to 100 sensors can be read via common 2 wires
  • Thermal relay/alert
  • Body temperature measurement


The connection of MLX90614 to MCU is very simple. Two general-purpose pins RC3 and RC4 of the PIC18 are used. Two pull-up resistors R1 and R2 are connected to Vdd and to SCL and SDA lines respectively. C1 is the local power supply bypass decoupling capacitor. The MLX90614 needs that for bypassing of the on-chip digital circuitry switching noise.

C2 has the same function for the microcontroller. The well-known value 100 nF (SMD ceramic type) is typically adequate for these components. Note that the power supply typically needs more capacitors (like 100 µF on voltage regulator input and output), not shown in the schematic.

The components R1, C3, C4 and Y1 are used for the MCU oscillator. On-chip RC oscillators can also be used. For example, with a PIC18F4320 internal RC oscillator set to 8 MHz can be used without problem. SMBus is synchronous communication and therefore is not critical to timings. Refer to MLX90614 datasheets, AppNote, “SMBus communication with MLX90614” and SMBus standard for details. MLX90614 comes in 5V and 3V versions. PIC18LF4320 could be used with the 3V version (MLX90614Bxx) and both PIC18F4320 and PIC18LF4320 – with the 5V version (MLX90614Axx).