I am currently working on my final year project and I have chosen to compare a 3D solar panel with a flat solar panel. One of the parameters I am trying to calculate is the temperature of the both solar panels. I have advanced quite a lot in the programming area and also have constructed a hardware diagram using Proteus.
To all of those programming students out there... PLEASE NOTE that the 8051 has an internal ADC in port 1 as I have seen many forums stating that the 8051 does not have an internal ADC and this is not correct.
Going back to my problem, the only values that I am getting from my "temperature sensor" are 00.0 and 11.1. Since I am running this on a simulation, the temperature sensor was made up of a simple potentiometer. Vary the resistance, and the temperature should change accordingly. I am strongly confident that the problem is coming for my conversion.
PLEASE CHECK MY CONVERSION!! I am attaching a text file containing the program and the hardware picture.
//Using LM35 Tempreture Sensor interface with 8051 including expansion port for data logger
//Pre-processor commands
#include <reg51.h>
#include <absacc.h>
//Additional Pre-processor commands
#define PPIA 0x4000 //Port A
#define PPIB 0x4001 //Port B
#define PPIC 0x4002 //Port C
#define PPICNTRL 0x4003 //8255 Control Register
#define VOLT1ADC P2 //ADC Port (output)
//Single Bit Definitions
sbit SENS1=P1^0;
sbit SENS2=P1^1;
//sbit VOLTM1=P1^2;
//sbit VOLTM2=P1^3;
sbit readAD=P3^7;
sbit write=P3^6;
sbit chipsel=P3^4;
sbit intr=P3^3;
//Prototype Functions in use
void disp_mess(unsigned char mymess[],length); //no return parameters
void PPI_data(unsigned char value1);
void PPI_cmd(unsigned char value1);
void PPI_data2(unsigned char value2);
void PPI_cmd2(unsigned char value2);
void PPI_data3(unsigned char voltage);
void PPI_cmd3(unsigned char voltage);
void LCDDelay(unsigned char ustime); //Enable Pulse
void CHARDelay(unsigned int mstime);
void disp(unsigned char value1,length); //in between Characters
void TEMPDelay(unsigned int time); //in between Tempreture readings
void INITSER();
void conv();//A to D Conversion
void read();// Read from A/D port
unsigned char tempconv1(void);
unsigned char tempconv2(void);
void volt1conv(unsigned char voltage,length); //Voltage Conversion to ASCII
unsigned int A2DM;
unsigned int ADC;
//Main Function Block
void main(void)
{
unsigned char temp1;
unsigned char temp2;
unsigned char volt1;
unsigned char i;
while(1) //infinite loop
{
XBYTE[PPICNTRL]=0x80; //Control word ALL Ports o/p
//LCD commands
PPI_cmd(0x38); //init. LCD 2 lines, 5x7 matrix, 8-bits
PPI_cmd(0x0E); //LCD on, cursor on
PPI_cmd(0x01); //Clear LCD screen
PPI_cmd(0x80); //change cursor pos
//LCD messages for TEMPERATURE
disp_mess("Sens 1: ",0x0C); //display message on line 1
{
temp1=tempconv1();
disp(temp1,1); // Command To Display 0x2A (*)
disp(0xDF,1);
disp_mess("C",1);
}
PPI_cmd2(0xC0); //change cursor pos
disp_mess("Sens 2: ", 0x0C); //display message on line 2
{
temp2=tempconv2();
disp(temp2,1); // Command To Display 0x2A (*)
disp(0xDF,1);
disp_mess("C",1);
}
PPI_cmd(0x01);
{
A2DM = 0;
for(i=0;i<10;i++) //10 loops to achieve correct value
{
conv(); //Start conversion
read(); //Read ADC
A2DM += ADC; //insert value into array adc_avg and increament
}
A2DM = A2DM/10;
//PPI_cmd3(0x80);
disp_mess("Volt 1: ", 0x0C);
ADC = A2DM * 19; //Value is Units
volt1conv((unsigned char)(ADC/1000));
PPI_data3('.'); //decimal point
ADC = ADC%1000; //Remainder is 2 dp
volt1conv((unsigned char)(ADC/10));
PPI_data3('V');
}
TEMPDelay(50);
// exit: goto exit; //micro stay here
}
}
//Tempreture Convertion Value for SENSOR 1
unsigned char tempconv1()
{
unsigned char input1,val1,val1A,val1B,val1C;
input1=SENS1; //read input from Port 1.0
val1=input1/1000;
val1A=input1%10;
val1B=val1A%10; //remainder is Units digit
val1C=val1B%10; //remainder of second division is Tens digit
val1A=val1A|0x30;
val1B=val1B|0x30; //ASCII Convertions
val1C=val1C|0x30;
PPI_cmd(0x87); //LCD Position
PPI_data(val1C);
PPI_cmd(0x88);
PPI_data(val1B);
PPI_cmd(0x89);
PPI_data('.');
PPI_data(val1A);
}
//Tempreture Convertion Value for SENSOR 2
unsigned char tempconv2()
{
unsigned char input2,val2,val2A,val2B,val2C;
input2=SENS2; //read input from Port 1.1
val2=input2/100; //divide by 10
val2A=input2%10;
val2B=val2A%10; //remainder is Units digit
val2C=val2B%10; //remainder of second division is Tens digit
val2A=val2A|0x30;
val2B=val2B|0x30; //ASCII Convertions
val2C=val2C|0x30;
PPI_cmd2(0xC7); //LCD Position
PPI_data2(val2C);
PPI_cmd2(0xC8);
PPI_data2(val2B);
PPI_cmd2(0xC9);
PPI_data2('.');
PPI_data2(val2A);
}
//Voltage Conversion Value for VOLTMETER 1
void volt1conv(unsigned char voltage,length)
{
char temp1,temp2;
temp1 = voltage; // insert value of voltage (hex) into temp1 array
temp2=0; // clear temp2 array
do
{
temp1 = temp1-100; //decrease value of temp1 by 100
if(temp1>=0)
temp2++; // increament temp2 by 1
}
while(temp1>=0); //as long as temp1 is greater or equal to 0
if(temp2>0)
PPI_data3(temp2+0x30); //Convert temp2 to ASCII
temp2=0;
temp1 = temp1+100;
do
{
temp1 = temp1-10;
if(temp1>=0)
temp2++;
}
while(temp1>=0); //as long as temp1 is greater or equal to 0
PPI_data3(temp2+0x30);
temp2 = temp1+10;
PPI_data3(temp2+0x30);
}
// Prototype Function Decleration To Display SENSOR 1 On LCD
void disp(unsigned char value1,length)
{
unsigned char y,val1; // Variable y For Loop
for(y=0;y<length;y++) // Loop
{
val1 =value1;
PPI_data(val1);
CHARDelay(200); // LCD Is Defned To Port 0
}
}
// Prototype Function Decleration To Display SENSOR 2 On LCD
void disp2(unsigned char value2,length)
{
unsigned char y,val2; // Variable y For Loop
for(y=0;y<length;y++) // Loop
{
val2 =value2;
PPI_data2(val2);
CHARDelay(200); // LCD Is Defned To Port 0
}
}
//LCD Messages for SENSOR 1
void disp_mess(unsigned char mymess[],length)
{
unsigned char val1;
unsigned char i;
for(i=0;i<length;i++)
{
val1=mymess[i];
PPI_data(val1);
CHARDelay(200); //delay for characters
}
}
//LCD Command for SENSOR 1
void PPI_cmd(unsigned char value1)
{
//RS=0 for command
XBYTE[PPIA]=value1; //RW=0 for write
//strobe the Enable Pin
XBYTE[PPIB]=0x04; //E=1 for H-to-L pulse
LCDDelay(18); //~100us
XBYTE[PPIB]=0x00; //E=0
CHARDelay(200); //delay for commands
}
//LCD Data for SENSOR 1
void PPI_data(unsigned char value1)
{
//RS=1 for data
XBYTE[PPIA]=value1; //RW=0 for write
//strobe the Enable pin
XBYTE[PPIB]=0x05; //E=1 for H-to-L pulse
LCDDelay(18); //~100us
XBYTE[PPIB]=0x01; //E=0
}
//LCD Command for SENSOR 2
void PPI_cmd2(unsigned char value2)
{
//RS=0 for command
XBYTE[PPIA]=value2; //RW=0 for write
//strobe the Enable Pin
XBYTE[PPIB]=0x04; //E=1 for H-to-L pulse
LCDDelay(18); //~100us
XBYTE[PPIB]=0x00; //E=0
CHARDelay(200); //delay for commands
}
//LCD Data for SENSOR 2
void PPI_data2(unsigned char value2)
{
//RS=1 for data
XBYTE[PPIA]=value2; //RW=0 for write
//strobe the Enable pin
XBYTE[PPIB]=0x05; //E=1 for H-to-L pulse
LCDDelay(18); //~100us
XBYTE[PPIB]=0x01; //E=0
}
//ADC Routine for Conversion
void conv()
{
chipsel = 0; //Make CS low
write = 0; //Make WR low
write = 1; //Make WR high
chipsel = 1; //Make CS high
while(intr); //Wait for INTR to go low
}
void read()
{
chipsel = 0; //Make CS low
readAD = 0; //Make RD low
ADC = VOLT1ADC; //Read ADC port
readAD = 1; //Make RD high
chipsel = 1; //Make CS high
}
//LCD Command for Voltage 1
void PPI_cmd3(unsigned char voltage)
{
//RS=0 for command
XBYTE[PPIA]=voltage; //RW=0 for write
//strobe the Enable Pin
XBYTE[PPIB]=0x04; //E=1 for H-to-L pulse
LCDDelay(18); //~100us
XBYTE[PPIB]=0x00; //E=0
CHARDelay(200); //delay for commands
}
//LCD Data for Voltage 1
void PPI_data3(unsigned char voltage)
{
//RS=1 for data
XBYTE[PPIA]=voltage; //RW=0 for write
//strobe the Enable pin
XBYTE[PPIB]=0x05; //E=1 for H-to-L pulse
LCDDelay(18); //~100us
XBYTE[PPIB]=0x01; //E=0
}
//Serial Communication Settings
void INITSER()
{
TMOD=0x20;
SCON=0x50;
TH1=0xFD;
TL1=0xFD;
TR1=1;
}
//LCD Enable Pulse
void LCDDelay(unsigned char ustime)
{
unsigned char i;
//single loop
for(i=0;i<ustime;i++);
}
//Delay used for Message Characters
void CHARDelay(unsigned int mstime)
{
unsigned int i,j;
//nested loops
for(i=0;i<mstime;i++) //outer loop
for(j=0;j<190;j++); //inner loop
}
//Delay between Tempreture readings
void TEMPDelay(unsigned int time)
{
unsigned int x,z,y;
//nested loops
for(x=0;x<time;x++)
for(z=0;z<255;z++)
for(y=0;y<255;y++);
}
Attached image(s)
Attached File(s)
-
Temp.txt (8.26K)
Number of downloads: 779
This post has been edited by JackOfAllTrades: 29 August 2010 - 04:51 AM
Reason for edit:: Added code to post.

New Topic/Question
Reply




MultiQuote







|