Electronics Temperature Sensor (LM35 + PIC16F877A)

Circuit Temperature sensor (LM35 + PIC16F877A) schematics Circuit Electronics,
Here's one temperature sensor (thermometer) circuit that you can easily build. It uses the popular PIC 16F877A microcontroller. The temperature sensor is LM35. The LM35 outputs an analog voltage proportional to the temperature. The output from the LM35 is 0.1V/'C. So, when temperature sensed is 61'C, the output voltage is 0.61V. This analog voltage is read by the PIC and processed to display the corresponding temperature value on the LCD.

The temperature range for this circuit is 0'C to 150'C.

The analog to digital conversion is done by the PIC ADC module. In the code, I've used the mikroC library function for ADC. You can view the library file here: http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/adc_library.htm

However, you should have a knowledge of how the ADC module works and how to use it. I had written a tutorial on modalities of operation of the PIC 16F877A ADC.

For LCD interfacing, I used the mikroC LCD library. You can view the library file here: http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/lcd_library.htm

Here is the code for PIC16F877A:
(You can download the source file from: https://rapidshare.com/files/3044512089/LM35PIC16F877A.c)
--------------------------------------------------------------------------------------------------------------
//Programmer: Syed Tahmid Mahbub
//Compiler: mikroC PRO for PIC v4.60
//Target PIC: PIC16F877A
--------------------------------------------------------------------------------------------------------------
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

unsigned long ADRead;
unsigned int vDisp[3];
unsigned char Display[7];

void main() {

PORTA = 0;
TRISA = 0X01;
PORTB = 0;
TRISB = 0;
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1, 1, "Temp:");
//Display = "+125 'C";
Display[4] = 39; //'
Display[5]= 'C';
ADCON1 = 0x0E;
ADC_Init();
while (1){
ADRead = (ADC_Get_Sample(0) * 500) >> 10;
vDisp[0] = ADRead / 100;
vDisp[1] = (ADRead / 10) % 10;
vDisp[2] = ADRead % 10;
Display[1] = vDisp[0] + 48;
Display[2] = vDisp[1] + 48;
Display[3] = vDisp[2] + 48;
LCD_Chr(1, 8, Display[0]);
LCD_Chr(1, 9, Display[1]);
LCD_Chr(1, 10, Display[2]);
LCD_Chr(1, 11, Display[3]);
LCD_Chr(1, 12, Display[4]);
LCD_Chr(1, 13, Display[5]);
//LCD_Out(1, 8, ); // 'Show temperature
delay_ms(200); //200ms delay for waiting
}
}
--------------------------------------------------------------------------------------------------------------

Reference documents:
LM35 datasheet: www.ti.com/lit/ds/symlink/lm35.pdf
PIC16F877A datasheet: ww1.microchip.com/downloads/en/devicedoc/39582b.pdf

mikroC LCD library: http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/lcd_library.htm
mikroC ADC library: http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/adc_library.htm

Schematics for Temperature sensor (LM35 + PIC16F877A) Circuit Electronics
read more "Electronics Temperature Sensor (LM35 + PIC16F877A)"

Electronics MAGIC of knowledge

Circuit MAGIC of knowledge schematics Circuit Electronics,
I turned the switch on and BOOM! That noise, the tiny puff of smoke and the accompanying smell had become far too familiar.

I looked on in confusion at all the failed electronics components in front of me. I needed answers. Why did the H-bridge circuit not work as “claimed”? Books showed numerous such circuits. The Internet was not short of designs either. They were all similar though. I had done my research. I thought I understood the principles and modalities of operation. Then, where did the fault lie? Frustration was creeping in. But I just had to find the fault and fix it.

I wanted to make the SMPS based inverter because I could learn so much in a field completely new to me and then use the inverter at home during power cuts. In that one night of experimentation, I had failed repeatedly, damaging 24 IR2110’s and a lot more components. I had applied all I had learned thus far. Success, however, eluded me.


After repeated failures, I posted my problem on online electronics forums. Numerous members from around the world, engineers and non-engineers alike, joined in to contribute. I learnt and questioned. Heated discussions, arguments and counter-arguments took place. And I absorbed all I could. I did not get a direct solution to my problem but I felt I had become richer and perhaps, through discussion, helped make others richer.

 I spent hours reading documents and application notes, analyzing existing designs and testing the different concepts experimentally. However, the result was the same.

One day I stumbled upon a circuit on the internet, which had a different type of MOSFET gate protection, which employed a resistor between “gate” and “source”. Theoretically this resistor was not required. I redesigned the entire circuit with these resistors connected.

MAGIC! I got the required AC output. No BOOM, no smoke, no smell! 4 resistors (one between gate and source of each MOSFET) that, in total, cost less than $0.25, had been the difference! This was the magic of knowledge – the power of knowledge people refer to.

I then resorted to books and the Internet and learnt why the gate-to-source resistor stopped the MOSFET, and in turn the driver IR2110, from “blowing”.

After completing my inverter, I regularly posted on online electronics forums, especially www.edaboard.com – in the time I found between school, sports, electronics endeavors and other activities – to help others and to learn.

Many people later posted on www.edaboard.com regarding problems where the MOSFET and driver “blew”. I had been the one to suggest the use of the “gate-to-source” resistor and this had been the solution to most such problems.

My repeated failures had frustrated me, but also pushed me beyond the boundary of books to learn, acquire and share knowledge, to believe in the power of knowledge but most importantly to believe in myself and my capabilities. This belief and these teachings helped me in later endeavors to overcome obstacles in my way and achieve success.

---------------------------------------------------------------------------------------------------------------------
Importance of the gate-to-source resistor:

It prevents accidental turn on of the MOSFET by external noise usually at startup when the gate is floating. The MOSFET may sometimes turn on with a floating gate because of the internal drain to gate "Miller" capacitance. A gate to source resistor acts as a pull-down to ensure a low level for the MOSFET. I have had MOSFETs blowing up in high voltage circuits, without the resistor in place. In most of the commercial power supplies / inverters I have seen, there is a 1k resistor used.

A similar experience is narrated in Sanajaya Maniktala's "Switching Power Supplies A to Z". This is also talked of in Raymond Mack's "Switching Power Supplies Demystified".

Schematics for MAGIC of knowledge Circuit Electronics
read more "Electronics MAGIC of knowledge"

Electronics Smart Sine - Software to generate sine table

Circuit Smart Sine - Software to generate sine table schematics Circuit Electronics,
Here is the software Smart Sine, that I created and now use to generate sine tables.

It is the improved and more developed version of the software I had previously created with a few more useful features. It is relatively simple to use and gives results quickly as opposed to manually calculating the table.

Here are a few screenshots:






Schematics for Smart Sine - Software to generate sine table Circuit Electronics
read more "Electronics Smart Sine - Software to generate sine table"

Electronics Generation of sine wave using SPWM in PIC16F684

Circuit Generation of sine wave using SPWM in PIC16F684 schematics Circuit Electronics,

I have previously shown how to calculate the values for the sine table. Now I will show you how to use that sine table for generating a sine wave using a PIC16F684. Why PIC16F684? It is a nice little 14-pin PIC that contains all that is needed for SPWM (sinusoidal pulse width modulation) – the ECCP module. Since the ADC or comparator or other peripherals are not used and there are enough pins, I selected the PIC16F684.




Let’s run the 16F684 from a 16MHz crystal oscillator and use a 16kHz switching frequency.

So, the required value of PR2 is 249.


The sine table (for half a cycle) is:

0, 25, 49, 73, 96, 118, 139, 159, 177, 193, 208, 220, 231, 239, 245, 249, 250, 249, 245, 239, 231, 220, 208, 193, 177, 159, 139, 118, 96, 73, 49, 25

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


Here is the code:


unsigned char sin_table[32]={0,25,49,73,96,118,137,

159,177,193,208,220,231,239,245,249,250,249,245,

239,231,220,208,193,177,159,137,118,96,73,49,25};



unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;

unsigned int TBL_temp;

unsigned char DUTY_CYCLE;


void interrupt(){

     if (TMR2IF_bit == 1){

        TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;

        if (TBL_POINTER_NEW < TBL_POINTER_OLD){

           CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge

        }

        TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 11;

        DUTY_CYCLE = TBL_POINTER_SHIFT;

        CCPR1L = sin_table[DUTY_CYCLE];

        TBL_POINTER_OLD = TBL_POINTER_NEW;

        TMR2IF_bit = 0;

     }

}


void main() {

     SET_FREQ = 410;

     TBL_POINTER_SHIFT = 0;

     TBL_POINTER_NEW = 0;

     TBL_POINTER_OLD = 0;

     DUTY_CYCLE = 0;

     ANSEL = 0; //Disable ADC

     CMCON0 = 7; //Disable Comparator

     TRISC = 0x3F;

     CCP1CON = 0x4C;

     TMR2IF_bit = 0;

     T2CON = 4; //TMR2 on, prescaler and postscaler 1:1

     while (TMR2IF_bit == 0);

     TMR2IF_bit = 0;

     TRISC = 0;

     TMR2IE_bit = 1;

     GIE_bit = 1;

     PEIE_bit = 1;

    

     while(1);

}

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


Download the hex file from:

To make the process of updating sine table value simple, table pointer was used. The frequency here is set to 50Hz and the switching frequency is 16kHz. The 16F684 generates SPWM signals on P1A, P1B, P1C and P1D pins which should then be connected to a full-bridge stage for feeding into transformer.

16kHz frequency is used since it is toward the end of the audible spectrum and so the noise emitted will not be intolerable. Frequency above 20kHz is not used as 20kHz is the maximum frequency for the ECCP module of 16F684.


Since the ECCP module and interrupt take care of the SPWM, it is being executed by the hardware modules. So, while these are running, you can do other stuff as well by coding them in the while(1) loop, which, as you can see, is blank now, since no other task is being carried out besides SPWM.


Generating the sine table:



The SPWM signals:



 


The generated sine wave:



Schematics for Generation of sine wave using SPWM in PIC16F684 Circuit Electronics
read more "Electronics Generation of sine wave using SPWM in PIC16F684"

Electronics 600W 50Hz sine wave inverter test circuit

Circuit 600W 50Hz sine wave inverter test circuit schematics Circuit Electronics,



Here I tested a 600W 50Hz sine wave inverter circuit using push-pull topology instead of full-bridge topology. 2 PIC16F684's were used - one for SPWM and one for charging. 2 microcontrollers were used intentionally as the purpose was to test if I could use the microcontrollers together and use each of them for multitasking. 2 auxiliary transformers are used - one for powering the circuitry when running off mains and one for current sensing. Charging is done with 4 relays that are turned on/off according to input voltage and accordingly connect the input voltage to an appropriate transformer winding/tapping to keep output voltage relatively constant. Switching frequency is 16kHz. The sine table has 32 values.

Here is the complete sine table:

0, 16, 32, 47, 62, 77, 91, 103, 115, 126, 136, 144, 151, 156, 160, 162, 163, 162, 160, 156, 151, 144, 136, 126, 115, 103, 91, 77, 62, 47, 32, 16, //65%

0, 17, 33, 49, 65, 80, 94, 107, 120, 131, 141, 149, 156, 162, 166, 168, 169, 168, 166, 162, 156, 149, 141, 131, 120, 107, 94, 80, 65, 49, 33, 17, //67.5%

0, 17, 34, 51, 67, 82, 97, 111, 124, 135, 146, 154, 162, 167, 172, 174, 175, 174, 172, 167, 162, 154, 146, 135, 124, 111, 97, 82, 67, 51, 34, 17, //70%

0, 18, 35, 53, 69, 85, 101, 115, 128, 140, 150, 160, 167, 173, 178, 180, 181, 180, 178, 173, 167, 160, 150, 140, 128, 115, 101, 85, 69, 53, 35, 18, //72.5%

0, 18, 37, 55, 72, 89, 104, 119, 133, 145, 156, 166, 174, 180, 184, 187, 188, 187, 184, 180, 174, 166, 156, 145, 133, 119, 104, 89, 72, 55, 37, 18, //75%

0, 19, 38, 56, 74, 91, 108, 123, 137, 150, 161, 171, 179, 186, 190, 193, 194, 193, 190, 186, 179, 171, 161, 150, 137, 123, 108, 91, 74, 56, 38, 19, //77.5%

0, 20, 39, 58, 77, 94, 111, 127, 141, 155, 166, 176, 185, 191, 196, 199, 200, 199, 196, 191, 185, 176, 166, 155, 141, 127, 111, 94, 77, 58, 39, 20, //80%

0, 20, 40, 60, 79, 97, 114, 131, 146, 159, 171, 182, 190, 197, 202, 205, 206, 205, 202, 197, 190, 182, 171, 159, 146, 131, 114, 97, 79, 60, 40, 20, //82.5%

0, 21, 42, 62, 82, 100, 118, 135, 151, 165, 177, 188, 197, 204, 209, 212, 213, 212, 209, 204, 197, 188, 177, 165, 151, 135, 118, 100, 82, 62, 42, 21, //85

0, 21, 43, 64, 84, 103, 122, 139, 155, 169, 182, 193, 202, 210, 215, 218, 219, 218, 215, 210, 202, 193, 182, 169, 155, 139, 122, 103, 84, 64, 43, 21, //87.5%

0, 22, 44, 65, 86, 106, 125, 143, 159, 174, 187, 198, 208, 215, 221, 224, 225, 224, 221, 215, 208, 198, 187, 174, 159, 143, 125, 106, 86, 65, 44, 22, //90%

0, 23, 45, 67, 88, 109, 128, 147, 163, 179, 192, 204, 213, 221, 227, 230, 231, 230, 227, 221, 213, 204, 192, 179, 163, 147, 128, 109, 88, 67, 45, 23, //92.5%

0, 23, 46, 69, 91, 112, 132, 151, 168, 184, 198, 210, 220, 228, 233, 237, 238, 237, 233, 228, 220, 210, 198, 184, 168, 151, 132, 112, 91, 69, 46, 23 //95%

//0, 25, 49, 73, 96, 118, 139, 159, 177, 193, 208, 220, 231, 239, 245, 249, 250, 249, 245, 239, 231, 220, 208, 193, 177, 159, 139, 118, 96, 73, 49, 25, //100%

Each 32 values corresponds to one half-cycle of a 50Hz sine wave, each set corresponding to a different duty cycle. The duty cycle varies as the amplitude of the sine wave is varied by adjusting the value of the CCPR1L register. The maximum value of each set of 32 values is set to correspond to a different duty cycle and the other 31 values are in the same ratio to the maximum value for all sets of values. A pointer is used in the main code to retrieve the required set of 32 values for a required duty cycle. The lowest duty cycle is 65% because, for feedback, lower duty cycles are not required. The maximum duty cycle is set at 95% to provide some dead-time and avoid cross-conduction. At the beginning of each half-cycle, one MOSFET is driven according to the duty cycle values retrieved from the table. At the end of the half-cycle and beginning of the next half-cycle, the other MOSFET is driven according to those same duty cycle values. Upon a fault condition (such as low-battery), both MOSFETs are turned off and kept off.

It works as intended and testing was successful. However, it requires adjustments to be made for the final one.

Schematics for 600W 50Hz sine wave inverter test circuit Circuit Electronics
read more "Electronics 600W 50Hz sine wave inverter test circuit"