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

ExperimenterUK
Sun Oct 13 2019, 12:23 AM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 12:18 PM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 09:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 10:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 09:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 06:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 02:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 08:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 09:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html
ExperimenterUK
Thu Jul 11 2019, 09:44 PM
@praveen123. Can you give a link to the project ?

Downloads

Comments

DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM
baoyen123
Fri Nov 08 2019, 10:06 AM
xiwang
Fri Nov 08 2019, 07:28 AM
ilylily07
Tue Oct 15 2019, 04:32 PM
hientran123
Tue Oct 15 2019, 02:27 AM
Sat Oct 05 2019, 02:38 PM

Online

Guests: 37, Members: 0 ...

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

Members: 38102
Newest member: DeepakBGattani
Forum Activity
Jeanbusatta Avatar
Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM
wimac Avatar
Posted By wimac
Mon Oct 21 2019, 09:18 AM
I’ve been following this thread and looking at the...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:05 PM
sir, 3rd and 4th dot matrix display flickering, ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Oct 18 2019, 09:18 PM
Hopefully you understand some of the program.Which...