Discussion in "8051 Discussion Forum" started by    shaik    Aug 3, 2010.
Wed Aug 11 2010, 08:44 AM
#11
hello ajay,
Ya u r right.
My first project was on AVR microcontroller so i think that this same libraries and functions worked for delay in this also.
But i forgot that now my project is on 8051 and AVR and 8051 both are different.

Thank u very much for nice information.
You are Master in Embedded system.
Your each and every reply are point to point and also in very simple language.
Thanks for ur support.
I think that without u i will not go further in my project.

I tried to make for loop for delay in 8051.
I had not able to find the solution of one previous problem
I had write one program for generating PWM using PCA. The code is as follows.

#include <stdio.h>

#include "reg_c51.h"

void main()
{
	CMOD = 0x02; // Setup PCA timer

	CL = 0x00;
	CH = 0x00;

	CCAP1L = 0x40; // Set the initial value same as CCAP0H
	CCAP1H = 0x40; // 75% Duty Cycle

	CCAPM1 = 0x42; // Setup PCA module 0 in PWM mode.

	CR = 1; // Start PCA Timer.

	while (1)
	{}
}


I run this program last week it´s working perfectly, but when i check this program again say today then it´s not giving PWM o/p.

Is there any problem of PCA ? Because PCA is one type of array and when i run 1st program then 2nd program after 2nd program again 1st program, may array or flash memory was not perfectly empty.

I don´t understand wht is the problem.
there is no error in code but when i check again then not working.
I had change nothing.

Please give ur suggetion for this problem.
Thank u in advance.

Wed Aug 11 2010, 07:35 PM
#12

Thank u very much for nice information.
You are Master in Embedded system.
Your each and every reply are point to point and also in very simple language.
Thanks for ur support.
I think that without u i will not go further in my project.

shaik



Thank you it feels nice when everyone achieve what they want.

Is there any problem of PCA ? Because PCA is one type of array and when i run 1st program then 2nd program after 2nd program again 1st program, may array or flash memory was not perfectly empty.

shaik


what? i did not understand.. just make sure you did not damage your output pin

code is all fine, no doubt in that.
 shaik like this.
Thu Aug 12 2010, 06:53 AM
#13
hello ajay,
One thing i am sure that u r master of Embedded system.

I had not damage the o/p pin.
when i toggle the pin then all pins r working, but only pins not display PWM o/p.


[ Edited Thu Aug 12 2010, 06:56 AM ]
Fri Aug 13 2010, 03:51 PM
#14
I see that pin has alternate function as Analog input, Datasheet says by default pin is in Digital IO mode but just to make it confirmed, set that pin as Digital IO by configuring the analog registers. Lets hope it starts working afterward.
Sat Aug 14 2010, 05:01 AM
#15
You may also want to check whether the reset ckt is ok.
what values are used for the reset cap-resistor?
Mon Aug 16 2010, 08:41 AM
#16
hello,
Thanks for ur reply.

I want to give Analog i/p through Pot [R12 connected with P1_7 pin] and take digital o/p.
how can i do this?
In AT89C51CC01 datasheet on Page no: 132 gives sample program for ADC.
I had check this program but problem is how can i know from what i/o what o/p i got?
I know the theory of ADC, but i had never done practical.

Another problem is Pot is connected to one single bit pin (P1_7) and analog signal needs Byte of 8 bits, and i want to give i/p of analog signals only by Pot.

For this i have one program as follows.
* @file $RCSfile: Adc_8bits.c,v $ */

#include "reg_c51.h"

unsigned char value_converted=0x00; /* converted value */
unsigned char value_AN6=0x00;       /* converted AN6 value */
unsigned char value_AN7=0x00;       /* converted AN7 value */
bit end_of_convertion=0;            /* software flag */

// FUNCTION_PURPOSE:this function setup Adc with channel 6 and 7 and start 8bits convertion.
void main(void)
{
/* configure channel P1.6(AN6) and P1.7(AN7) for ADC */
ADCF = 0xC0;                        

/* init prescaler for adc clock */
/* Fadc = Fperiph/(2*(32-PRS)), PRS ->
 ADCLK[4:0] */
ADCLK = 0x06;                       /* Fosc = 16 MHz, Fadsc = 153.8khz */

ADCON = 0x20;                       /* Enable the ADC */

EA = 1;                             /* enable interrupts */
EADC = 1;                           /* enable ADC interrupt */

	while(1)
	{
	   ADCON &= ~0x07;                  /* Clear the channel field ADCON[2:0] */
	   ADCON |= 0x06;                   /* Select channel 6 */
	   ADCON &= ~0x40;                  /* standard mode */
	   ADCON |= 0x08;                   /* Start conversion */
	
	   while(!end_of_convertion);       /* wait end of convertion */
	   end_of_convertion=0;             /* clear software flag */
	   value_AN6=value_converted;       /* save converted value */
	
	
	   ADCON &= ~0x07;                  /* Clear the channel field ADCON[2:0] */
	   ADCON |= 0x07;                   /* Select channel 7 */
	   ADCON &= ~0x40;                  /* standard mode */
	   ADCON |= 0x08;                   /* Start conversion */
	
	   while(!end_of_convertion);       /* wait end of convertion */
	   end_of_convertion=0;             /* clear software flag */
	   value_AN7=value_converted;       /* save converted value */
	}
}


// FUNCTION_PURPOSE:Adc interrupt, save ADDH into an unsigned char 
void it_Adc(void) interrupt 8
{
	ADCON &= ~0x10;                     /* Clear the End of conversion flag */
	value_converted = ADDH;             /* save value */
	end_of_convertion=1;                /* set flag */
}




But in this code i/o and o/p channels r same. and i want to give i/p from Pot and take o/p from other pin.
My task is take analog i/o then check the volts for that inputed signal and save like following table.

Volts Duty cycle Range Stored value
0v – 1v :: 0 – 50 :: V1
1v – 2v :: 50 – 100 :: V2
2v – 3v :: 101 – 150 :: V3
3v – 4v :: 151 – 200 :: V4
4v – 5v :: 201 - 255 :: V5

please give me ur suggetion for this problem.
Thanks in advance.


[ Edited Mon Aug 16 2010, 09:59 AM ]
Mon Aug 16 2010, 06:07 PM
#17
you first have to know how ADC works..

you can get some basic information about ADC here:
http://www.8051projects.net/adc-interfacing/introduction.php

Now ADC converts analog to an equivalent digital value. This digital value is measure of steps taken by ADC to reach that analog level. each step of adc provides the resolution of that ADC. if ADC is an 8-bit resolution so it has 255 steps, 10bit ADC has 1023 steps and so on..

Now to calculate voltage from digital value, you first need to know what is the equivalent value of step size in volts. reference voltage comes in picture here, reference voltage is that voltage which is used by ADC to define a maximum input range to an ADC. so if my ref voltage is 5V, so ADC will give maximum digital value at 5V and miniumum value at 0V. Say for example if my ADC is an 8-bit, so maximum steps it can have is 255. if i set my reference voltage at 5V, so ADC will give 255 when input voltage is 5v or more and 0 incase input voltage is 0V.

so each step will have a voltage equivalent = 5V/255 = 0.0196V = 19.6mV
so if my ADC shows a digital value of 45 my input voltage is = 45 * 19.6 = 88.2mV

I hope you got the idea how to use ADC values now and understand the concept of ADC I am sure you can implement that voltage table now.
 shaik like this.
Tags adcanalog to digital converteradc output to voltagehow to use adcinterfacing adc
Tue Aug 17 2010, 08:43 AM
#18
hello ajay,
Thanks for ur informative reply. ile
I get little idea of ADC from ur reply.
I try to implement the voltage table. please check this table.

Analog i/o [Volts] :: i/o Volt/255[v] :: mV(millvolt) :: Digital value o/p :: Formula :: i/p voltage
1 :: 0.0039 :: 3.9 ::45 :: 45*19.6 :: 88.2mV
2 :: 0.0078 :: 7.8 :: 10 :: 10*19.6 :: 19.6mv
3 :: 0.0117 :: 11.7 ::20 :: 20*19.6 :: 39.2mV
4 :: 0.0156 :: 15.6 ::30 :: 30*19.6 :: 58.8mV
5 :: 0.0196 :: 19.6 ::40 :: 40*19.6 ::78.4mV

In which unit i get Digital o/p ? e.g for analog i have volts.
if i want to calculate digital o/p from analog i/o e.g if analog i/p is 1v then which formula can i use [19.6/1] ?

I am bit confuse that what i need for analog i/p, Pin(Bit) or Port(Byte)?
what i need for Digital o/p, Pin(Bit) or Port(Byte)?

I want to use P1_7 pin(Bit) [Pot-R12 in AT89STK-06 board] for analog i/o, can this possible?
I want to take one pin(Bit) for digital o/p, can this possible?

please give ur suggestion for this confusion.
Thanks in advance.


[ Edited Tue Aug 17 2010, 11:35 AM ]
Tue Aug 17 2010, 07:13 PM
#19
I have no idea how you wrote that table

if i want to calculate digital o/p from analog i/o e.g if analog i/p is 1v then which formula can i use [19.6/1] ?



its simple mathematics.
19.6mV give you 1 step or 1 on ADC digital output
1V or 1000mV will give you (1/19.6) * 1000 = 51.02 = 51 as ADC Digital value

**Make sure that above calculations are assuming that reference voltage is 5V.

I am bit confuse that what i need for analog i/p, Pin(Bit) or Port(Byte)?


Analog input is always on pin but you cant read it as a bit coz its analog value not digital. you have to user ADC to get the value.

what i need for Digital o/p, Pin(Bit) or Port(Byte)?


digital output is always in bytes can be 1 byte if 8-bit ADC or 2 bytes if 10, 12 or 16 bit ADC.

I want to use P1_7 pin(Bit) [Pot-R12 in AT89STK-06 board] for analog i/o, can this possible?


Yes its possible. but do not consider analog input as a bit, coz its not a digital value. so when you say Analog input its always Analog input on a Port pin. never considered as a single bit value.

I want to take one pin(Bit) for digital o/p, can this possible?


yes its possible but it will not give you deterministic answer, i mean you cannot represent an 8bit or more value by a single bit. so you need a complete port. If you have a display on board, its better or use serial port to display ADC value.
 shaik like this.
Wed Aug 18 2010, 09:42 AM
#20
hello ajay,
Thanks for ur valuable and informative reply.
Now i had clear all my dauts related to ADC.

Just see the table i make it correct.

Analog i/o [Volts] Formula Digital o/p
1 :: (1/19.6)*1000 :: 51.02
2 :: (2/19.6)*1000 :: 102.04
3 :: (3/19.6)*1000 :: 153.06
4 :: (4/19.6)*1000 :: 204.08
5 :: (5/19.6)*1000 :: 255.10

Now i try to make program for ADC.

Thank u very much for ur reply.

Get Social

Information

Powered by e107 Forum System

Conversation

Thu Jun 11 2020, 06:27 AM
anudee
sir could please send the code for I2C and wifi interfacing with 8051
scena
Tue May 19 2020, 10:29 PM
Does anyone have microcontroller programming software for STC15F104W (core 8051, 4 k, 128 byte, 6 I/O pin, UART ... DIL8), that works?
Sat May 02 2020, 07:38 PM
Tamu Gurung
Hi I am looking for a assembly language program for a digital decimal counter. Time counts max limit of 2 mins starting from 2.00 mins and ending at 0.00. time is to be displayed on 4 7-segment LED displays. Edsim51 simulator to be used. Thanks
Wed Mar 25 2020, 01:39 PM
Tajammul
Sir kindly send the code file i2c for 8051
ExperimenterUK
Fri Mar 13 2020, 10:36 PM
@ Rohitnani,ABEBE..which project ?
Fri Mar 13 2020, 12:55 PM
ABEBE
how can get hadwere of this project
Rohitnani
Sat Mar 07 2020, 05:11 PM
Sir, Could you please send me the zip file input password....
Wed Feb 26 2020, 04:58 PM
Peter Parker
Is it possible to send multiple messages using only 1 GSM module?
Sat Feb 01 2020, 10:12 AM
Pearl Olin
Hello,
Wed Jan 22 2020, 06:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 124, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123