Discussion in "8051 Discussion Forum" started by    shaik    Aug 3, 2010.
Wed Aug 11 2010, 02:14 pm
#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.

Thu Aug 12 2010, 01:05 am
#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, 12:23 pm
#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, 12:26 pm ]
Fri Aug 13 2010, 09:21 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, 10:31 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, 02:11 pm
#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, 03:29 pm ]
Mon Aug 16 2010, 11:37 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, 02:13 pm
#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, 05:05 pm ]
Wed Aug 18 2010, 12:43 am
#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, 03:12 pm
#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

Downloads

Comments

best_yyPa
Tue Apr 16 2024, 09:42 am
ErnestoExpop
Tue Apr 16 2024, 02:57 am
Jamesclepe
Mon Apr 15 2024, 11:10 am
Aliciaelora
Mon Apr 15 2024, 07:59 am
btaletvpcu
Mon Apr 15 2024, 04:36 am
UbvpwcTib
Mon Apr 15 2024, 03:13 am
AmyJow
Sun Apr 14 2024, 11:54 pm
Jamesraw
Sat Apr 13 2024, 08:18 pm