free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Go to page  [1] 2 3
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
Luqman
Sun Jul 29 2007, 11:42PM
 User Offline
Registered Member #1962
Joined: Wed Jul 04 2007, 03:13AM

Posts: 19
Thanked 0 times in 0 posts
hi, would any one send me an example PIC C code to take averages of many ADC values, to get a stable one so that a comparator with hysteresis effect may be obtain.


Back to top


Ajay
Mon Jul 30 2007, 03:50AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
its fairly easy... create an array and store the value.. like this...
unsigned long int adc_val;

unsigned int adc_avg; // stores adc average value

main() { //this is just to explain
unsigned char i;
adc_val =0;
for(i=0;i<50;i++){
adc_val+ = adc(); // adc() is function that returns
// converted adc value
}
adc_avg = adc_val/50;
}

This will give you average of 50 value, and i am sure its stable you can take average of averages.. that will give you even more stable value.. but that is needed when you have high fluctuations.. etc
If anymore doubt please ask..

[ Edited Mon Jul 30 2007, 03:52AM ]

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top



This post has been thanked 1 time
 Luqman 
Luqman
Fri Aug 03 2007, 03:32AM
 User Offline
Registered Member #1962
Joined: Wed Jul 04 2007, 03:13AM

Posts: 19
Thanked 0 times in 0 posts
/in the following programe
//Vs taking different adc values
//when Vs<=Va and when FG1=1 then LED at pin c4 should be on at Vs=Va+Va_1/2
//and for the same Vs<=Va but FG1=0 LED at pin c4 should be off at Vs=Va-Va_1/2
//i.e. want to get flashing of LED with some delay at a slightly different voltages
//so that trying to achieve a compratr with hystarisis
//how it could be achieve plz suggest a practical logic to cachieve this task

#include "snsr1.h"

#define cutoff 255 //5V
#define Va_1 10 //0.2V
#define Va 51 //1V
#define Vb 102 //2v
#define Vc 179 //3.5v


void main()
{
int Vs;
int1 FG1,FG2,FG3,FG4;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

// TODO: USER CODE!!

while(1)
{
set_adc_channel( 0 );
Vs = read_adc();
if(Vs<=Va)
{
FG1=1;
Vs = Va+Va_1/2;
output_bit(PIN_C4,1);
output_bit(PIN_C5,0);
output_bit(PIN_C6,0);
delay_ms(1000);
FG1=0;
Vs = Va-Va_1/2;
output_bit(PIN_C4,0);
output_bit(PIN_C5,0);
output_bit(PIN_C5,0);
}

else if(Va<Vs<=Vb)
{
FG2=1;
output_bit(PIN_C4,1);
output_bit(PIN_C5,0);
output_bit(PIN_C6,0);
}

else if(Va<Vs<=Vc)
{
FG3=1;
output_bit(PIN_C4,0);
output_bit(PIN_C5,1);
output_bit(PIN_C6,0);
}

else
{
FG4=1;
output_bit(PIN_C4,0);
output_bit(PIN_C5,0);
output_bit(PIN_C6,1);
}
}
}


[ Edited Fri Aug 03 2007, 04:04AM ]
Back to top


Ajay
Fri Aug 03 2007, 04:13AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
As i gave you an example already.. i think you did not read it carefully.. anyways you need to make just a little change in your program.
Please replace
Vs = read_adc();
in your program with the code below
CODE:
adc_val =0;
for(i=0;i<50;i++){
     adc_val+ = read_adc();
}
Vs = adc_val/50;
 


and define adc_val as unsigned long int and define i as unsigned char.. and see what you get..

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top



This post has been thanked 1 time
 Luqman 
Luqman
Fri Aug 03 2007, 06:31AM
 User Offline
Registered Member #1962
Joined: Wed Jul 04 2007, 03:13AM

Posts: 19
Thanked 0 times in 0 posts

i really appreciate ur concern
there is Flow Chart named FC1.doc file and modified code with ur suggestions, i m trying to achieve the following conditions

1) When Vs<=Va Green LED flashes(on and off) with certain delay
and RLY1 should also be on and off with the above
delay. It was achieved in comparator based circuit
with adding a flasher cct. (a comparator with
hysteresis).This hysteresis effect has to implement in
software.
2) WhenVa<Vs<=Vb
Green LED on constantly
and RLY1 should off
3) When Vb<Vs<=Vc
yellow LED on
and RLY2 should on
4) When Vc<Vs
Red LED on
and RLY3 should on

plz suggest me the practical schematic(16F877 cct.) to meet for these conditions and sugget me the corresponding modifications in the code.
Back to top


Ajay
Fri Aug 03 2007, 07:53AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
well whatever you are telling you can do by yourself.. i ain't giving you any code for that..
but for point 1. can you first tell me what is the result you're getting with the software change i told you?

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


Luqman
Fri Aug 03 2007, 09:47PM
 User Offline
Registered Member #1962
Joined: Wed Jul 04 2007, 03:13AM

Posts: 19
Thanked 0 times in 0 posts
actually i have some doubts in my cct. (schematic) as well, that how can i connect an LED and Relay at the same port pin a/c to my desired condition and what voltage should i give at Vref- and Vref+. would u like to suggest me the schematic(cct.) plz.
Back to top


Ajay
Sat Aug 04 2007, 05:01AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
connecting led is simple..

5V |----/\/\/\/\----|>|---Port Pin

and for connecting relays.. i have added a document in the circuit section of the download check it. It has full explanation of the different circuits that can be used for the relays..
In your case i think the Fig D of the document is the best way to connect the relay.

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top



This post has been thanked 1 time
 Luqman 
Luqman
Tue Aug 07 2007, 09:35PM
 User Offline
Registered Member #1962
Joined: Wed Jul 04 2007, 03:13AM

Posts: 19
Thanked 0 times in 0 posts
u say that i just finish things like
while(1) {----}
what does it mean
Back to top


Ajay
Wed Aug 08 2007, 01:42AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
that was a part of my signature.. doesn't matter did u see the circuit? i hope you wont have any problem now

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


Go to page  [1] 2 3  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems