C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 25th, 2012, 02:10 PM
RoN#32 RoN#32 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 RoN#32 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 38 sec
Reputation Power: 0
Need tons of help asap!!s.o.s

Hello guys,
im an Industrial Informatics student and im working on a project concerning an automatic moving photovoltaic. I use light sensors for motion. Automatically it has to find the less sensor value and moves to that position .. Im using 20 sensors.. I have difficulty in reading the sensors as they use Adc...
Using ATmega 16A
Atmel Studio 6.0

I really need ur help guys if its possible!!Thanks

Reply With Quote
  #2  
Old October 25th, 2012, 04:19 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,354 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 8 h 21 m 53 sec
Reputation Power: 383
Do you have a cute little robot with wheels and motors and cpu and beeping and blinking lights (I hope not) and stuff? Would an ATmega forum be more useful to you?
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old October 25th, 2012, 05:27 PM
RoN#32 RoN#32 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 RoN#32 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 38 sec
Reputation Power: 0
nop , just a piece of wood/steel..no wheels & stuff. Just a photovoltaic with sensors / stepper motors etc. AVR Forum didnt help cuz they dont say anything about programming!

Reply With Quote
  #4  
Old October 25th, 2012, 11:51 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,836 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 16 h 15 m 5 sec
Reputation Power: 1774
The first thing I would suggest is you look through the atmel application notes and review any of them which mention ADC, especially any which focus on basic operation.

> Im using 20 sensors.. I have difficulty in reading the sensors as they use Adc...
Start small and simple.
Using just one sensor, write a program that turns on a LED when the sensor is exposed to light, and turns off the LED when there is no (or less) light on the sensor.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #5  
Old October 26th, 2012, 12:02 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,125 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 16 h 57 m 4 sec
Reputation Power: 1949
Is your problem with the ADCs? Just what is the problem? Do you not know how to interface with them? The data sheets should tell you that. Do you not know what to do with the digital value you receive from them? Well, what's the conversion function? Just exactly what is the problem that you're having?

In one product I worked on (computerized greenhouse controls), we had sensors that were hooked up to ADCs which were read by microprocessors (more primitive than 8051s, so that was purely in assembly) and then those values were transmitted back to a PC which converted the readings into temperature, humidity, light level, whatever. In most cases, it was a simple linear formula of 0 to 5 volts corresponding to digital values from 0 to 255 which in turn corresponded to readings from some minimum to some maximum. In the case of one humidity sensor, the curve was not linear so we had to use a look-up table. What is the conversion formula for your sensors? What is keeping you from simply applying that formula?

Reply With Quote
  #6  
Old October 26th, 2012, 03:15 AM
RoN#32 RoN#32 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 RoN#32 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 38 sec
Reputation Power: 0
@salem
Im gonna post the program in a while
@dwise1_aol
Its my first time "playing" with ADCs , reading sensors and etc, so yea basically i dont know how to interface with them. Is it possible to add u on skype?

Reply With Quote
  #7  
Old October 26th, 2012, 06:41 AM
RoN#32 RoN#32 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 RoN#32 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 38 sec
Reputation Power: 0
#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <util/delay.h>



void adc_init(void);
uint16_t adc_read(uint8_t ADC_channel);

int main(void){

adc_init();

while(1){
int i;
uint16_t min;
int imin;
uint16_t pinakas[8];
DDRC = 0xFF;
PORTC = 0X00;

for (i=0; i<8; i++)
{
pinakas[i]=adc_read(i);
}

min=pinakas[0];
imin=0;

for(i=0;i<8;i++)
{
if(min>pinakas[i])
{
min=pinakas[i];
imin=i;
}
}


switch (imin)
{
case 1:
if (imin=1)
{
PORTC =0b00000001;
}
break;
case 2:
if (imin=2)
{
PORTC =0b00000010;
}
break;
case 3:
if (imin=3)
{
PORTC =0b00000011;
}
break;
case 4:
if (imin=4)
{
PORTC =0b00000100;
}
break;
case 5:
if (imin=5)
{
PORTC =0b00000101;
}
break;
case 6:
if (imin=6)
{
PORTC =0b00000110;
}
break;
case 7:
if (imin=7)
{
PORTC =0b00000111;
}
break;
case 8:
if (imin=8)
{
PORTC =0b00001000;
}
break;
default:
{
PORTC =0b11111111;
}
}
}
return 0;
}

void adc_init(){
ADCSRA |=(1<<ADPS2)| (1<<ADPS1)|(1<<ADPS0); // Prescaler 8 (4 MHz/8=125KHz).
ADMUX |= (1<<REFS0); // AVCC with external capacitor at AREF pin.
ADMUX |= (1 << ADLAR);
ADCSRA |= (1<<ADEN); // Enable ADC.
ADCSRA |= (1<<ADSC); // Start ADC conversion
}

uint16_t adc_read(uint8_t ADC_channel){
int16_t adc_val;
ADMUX = (ADMUX & 0xF0) | (ADC_channel & 0x0F);
ADCSRA |= (1<<ADSC);
while( ADCSRA & (1<<ADSC) );// wait until ADC conversion is complete
adc_val = ADC;
return adc_val;
}

I dont understand whats the prob...the 3rd led lights up only

Reply With Quote
  #8  
Old October 26th, 2012, 09:13 AM
MauroEldritch's Avatar
MauroEldritch MauroEldritch is offline
Contributing User
Click here for more information
 
Join Date: Oct 2012
Location: Buenos Aires, Argentina
Posts: 64 MauroEldritch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 36 m 5 sec
Reputation Power: 1
Quote:
Originally Posted by RoN#32

while(1){
int i;
uint16_t min;
int imin;
uint16_t pinakas[8];
DDRC = 0xFF;
PORTC = 0X00;

for (i=0; i<8; i++)
{
pinakas[i]=adc_read(i);
}

min=pinakas[0];
imin=0;

for(i=0;i<8;i++)
{
if(min>pinakas[i])
{
min=pinakas[i];
imin=i;
}
}


switch (imin)
{
case 1:
if (imin=1)
{
PORTC =0b00000001;
}
break;
case 2:
if (imin=2)
{
PORTC =0b00000010;
}
break;
case 3:
if (imin=3)
{
PORTC =0b00000011;
}
break;
case 4:
if (imin=4)
{
PORTC =0b00000100;
}
break;
case 5:
if (imin=5)
{
PORTC =0b00000101;
}
break;
case 6:
if (imin=6)
{
PORTC =0b00000110;
}
break;
case 7:
if (imin=7)
{
PORTC =0b00000111;
}
break;
case 8:
if (imin=8)
{
PORTC =0b00001000;
}
break;
default:
{
PORTC =0b11111111;
}
}
}
return 0;
}



I just wonder if that infinite loop would have something to do.
Maybe I'm wrong, but doesn't it avoids the program to return 0?

As I said, maybe I'm wrong.

Reply With Quote
  #9  
Old October 26th, 2012, 09:56 AM
EEmaestro EEmaestro is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 58 EEmaestro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 17 h 52 m 2 sec
Reputation Power: 2
DP

Reply With Quote
  #10  
Old October 26th, 2012, 09:56 AM
EEmaestro EEmaestro is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 58 EEmaestro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 17 h 52 m 2 sec
Reputation Power: 2
The infinite loop just causes the CPU to loop through the exact same code indefinitely until the power is shut off. That is a normal technique for embedded code.

Is there a way you can tell if adc_init() has properly initialized the ADC's ?

And what about adc_read(i) ? Is there a way you can either print out a value or illuminate an LED when it returns some value but extinguish the LED when it returns some other value? That would give you an indication of whether or not it is properly reading an analog voltage that you could manually change for testing.
Comments on this post
MauroEldritch agrees: Thanks for explaining it to me. +rep.

Reply With Quote
  #11  
Old October 27th, 2012, 08:34 AM
RoN#32 RoN#32 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 5 RoN#32 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 38 sec
Reputation Power: 0
Its running for 2 sensors , but not for more...Cant understand whats going on...Can someone help me a bit?

Reply With Quote
  #12  
Old October 29th, 2012, 11:16 AM
EEmaestro EEmaestro is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 58 EEmaestro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 17 h 52 m 2 sec
Reputation Power: 2
Google "AVR AT Mega16A enable ADC" for lots of tutorials on using the ADCs in this CPU. You probably forgot something. I don't know what it is. Trying out the tutorials might help you figure out the missing link. If the ADCs are interrupt-driven, it is also possible something in the code masks off all the ADC interrupts except for the two that are working. Investigate that possibility.

P.S. You need to figure out whether the ADC interrupts are hardware interrupts or software interrupts. If they are software interrupts, then it is a distinct possibility that some ADC interrupts are disabled. If they are hardware interrupts, then you will need to investigate further.

Last edited by EEmaestro : October 29th, 2012 at 11:21 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Need tons of help asap!!s.o.s

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap