Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
bobgardner
PostPosted: Jan 30, 2012 - 01:15 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

I thought you had an ATmega8515? Looks like that makefile is for a mega324?

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 01:45 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


i want to start with 2 photo resistors . when one of them receives more light than the other then an exact output will be true or else the other output pin will be true.
when the 2 photo resistors receive the same amount of light no out put pin will become true.
its so simple.

here is a sample of code for that:

Code:
while(photo_in_1 != photo_in_2){
 if(photo_in_1 > photo_in_2){
  motor_1 = 'true';
  else
  motor_2 = 'true';}
}


can i define any port as input for the analog photo resistors to digital inputs? or there is only a specific port that "accepts" analog to digital?
and if yes which one is it?

i am asking that again because someone referred in a previous post that there is only one specific port that receives analog signal and changes it to digital.

please be direct and specific in your answer.
 
 View user's profile Send private message  
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 02:06 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


i have an atmega8515

maybe,by mistake, i load the code that was written for the project in atmega324p

but i have another project setting to work with atmega8515. there is no difference in the codes ,just the settings that refer to cpu are different.

i also have try those 2 different projects but none of them run the game.
 
 View user's profile Send private message  
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 02:58 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


check out the following code for the solar tracker(for only 2 directions) is it going to be ok? and if yes where should i connect the photo resistors? directly to the input pins(D)?



Code:
#define F_CPU 3686400UL // 3,684 MHz

#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
 




int main(void){
   

   unsigned int east, west;
   
   
   
// Set port D pins 1 and 2 as input (data direction register D, set bit to 0 for INPUT)
    // Note: not really required, this is the default
    DDRD = 0x01;
   DDRD = 0x02;
      
   east = 0x01;
   west = 0x02;

// Set port B pins 3 and 4 as output (data direction register B, set bit to 1 for OUTPUT)
    DDRB = 0x04;
   DDRB = 0x08;

   

while(1){

     PORTB = 0xFF;

   while(east != west){
   if(east > west)
   PORTB = 0x01;
   else
   PORTB = 0x02;
                  
   }

     PORTB = 0xFF;


               }
return 0;}
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jan 30, 2012 - 03:15 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

The light sensor output is an analog voltage. You should read it with an a/d channel. So you need to write a little program that inits the a/d converter, reads it in a loop, and outputs the 8 bits to the serial port or some leds.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 03:49 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


or this code is better than the previous one (above)?
Code:

#define F_CPU 3686400UL // 3,684 MHz

#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
 

   int main(void){
   

   unsigned int east, west;
   unsigned int motor_1, motor_2; 
   
   
// Set port D pins 1 and 2 as input (data direction register D, set bit to 0 for INPUT)
    // Note: not really required, this is the default
    DDRD = 0x00;

      
   east =DDRD = 0x01;
   west =DDRD = 0x02;

// Set port B pins 3 and 4 as output (data direction register B, set bit to 1 for OUTPUT)
    DDRB = 0xFF;
//   motor_1= 0x00;
//   motor_2= 0x00;

  motor_1 = DDRD = 0x04  ;
  motor_2 = DDRD = 0x08  ;
 ;
   

while(1){

     PORTB = 0xFF;

   while(east != west){
   if(east > west)
   motor_1 =1;
   else
   motor_2=1;
                  
   }
     motor_1=0;
     motor_2=0;
     PORTB = 0xFF;


               }
return 0;}



how am i going to create that code for the analog to digital?

this is where i am a beginner .. in avr's programming details ..

any help in the code that you referred mr bobgardner?


Last edited by stavfot on Jan 30, 2012 - 06:46 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
jpmargis
PostPosted: Jan 30, 2012 - 03:53 PM
Rookie


Joined: Oct 07, 2010
Posts: 34
Location: San Dimas, CA

stavfot wrote:
Quote:

but i have another project setting to work with atmega8515. there is no difference in the codes ,just the settings that refer to cpu are different.

Not true! There are differences in the register addresses that will cause your game to be inoperable.

Regarding the photoresistors, the mega8515 analog comparator inputs are AINO (Pin 3) and AIN1 (Pin 4). This model of microcontroller has no A/D converter.

_________________
Mr. Informer


Last edited by jpmargis on Jan 30, 2012 - 07:10 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jan 30, 2012 - 04:09 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

If your goal with this project is to learn how to write a nontrivial program for an avr computer, then it seems that about now is the time to search for 'analog to digital converter' in the avr datasheet and in the tutorials and examples here. If you are lucky, a simple cut n paste from the example into your test program will get the a/d reading. You will need an avr with an a/d converter obviously.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 04:19 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


so you mean that the atmega8515 that i have plugged in stk500 has no analog to digital converter?

should i buy another cpu?

could you please post the code that is need for the analog to digital converter?

you must know where exactly that code is posted or you can write it down here ,since you know it. unfortunately i have no time to that by my self for i have many exams these days and i am reading all day.

if you please can help me i would be grateful to you.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jan 30, 2012 - 04:26 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

I can send you a compilable working progam for a mega32 on an ereshop.com board, and it compiles with the imagecraft compiler. Wait till I get home from work.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
snigelen
PostPosted: Jan 30, 2012 - 04:43 PM
Posting Freak


Joined: Jan 08, 2009
Posts: 1152
Location: Lund, Sweden

stavfot wrote:
so you mean that the atmega8515 that i have plugged in stk500 has no analog to digital converter?

If you read at least the first page of the data sheet for the mega8515 it will give a list of features in the 8515.
(and ADC is not one of them).
 
 View user's profile Send private message  
Reply with quote Back to top
jpmargis
PostPosted: Jan 30, 2012 - 04:57 PM
Rookie


Joined: Oct 07, 2010
Posts: 34
Location: San Dimas, CA

stavfot wrote:
Quote:

should i buy another cpu?

Not necessarily. You can get basic functionality using the mega8515. The motor will always be hunting, but the comparator is sufficient to determine east versus west. You will need to have one of your friends in the electrical engineering department design a circuit to bias and match your particular photoresistors.

_________________
Mr. Informer


Last edited by jpmargis on Jan 30, 2012 - 07:11 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 06:32 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


i dont have atmega32 cpu! i only have atmega8515

please any help is gladly acceptable only for atmega8515
 
 View user's profile Send private message  
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 06:38 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


is it possible to connect directly the 2 photo resistors in any input defined port ? for example the (+) of resistor to one of the input defined pin and the (-) to ground of the same input port. for the second photo resistor the (+) to one of the input defined pins of the port(not the same pin with the others photo resistor pin) and the (-) to the ground (same pin as of the other photo resistor).

is it possible that?
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jan 30, 2012 - 06:38 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

Code:

  o5V
  |
 [] photocell
  |
  +-- avr comparator input
  |
 [] trimpot
  |
  V

So make 2 of these and hook em up to the analog comparator. The output of the comparator will go hi when the + input is 1uv above the - input, and will go lo when its 1uv below the other input.

If you had no intention of getting another avr, why did you ask if you had to get another avr?

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 06:40 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


where is that [deleted] sheet? if i 'd found it i would gladly read it...
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jan 30, 2012 - 07:04 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

Come on. Who makes AVRs? Think they have the datasheets for their products on their web site?

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Jan 30, 2012 - 08:17 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England

stavfot,

I warned you about your language here once before - do it again and that will be the end.

Moderator

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
stavfot
PostPosted: Jan 30, 2012 - 09:48 PM
Wannabe


Joined: Dec 15, 2011
Posts: 93


ok i will check there. sorry Mr clawson. it was just a humor (you know there is similarity in between these two words sheet s..t) but i am sorry again.

i have a good knew! the game finally run! but it is too slow after the 1st flashing lights till the first pattern created, and then again it goes slow. i am almost sure that is due to the slow cpu and not for the delays, for i plaid with the values in delays ect but the difference was in certain moments and not in the heave part of the game(when it goes to case menu).

any ideas?
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jan 30, 2012 - 10:03 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21257
Location: Orlando Florida

The fuses must be set for internal oscillator, and its running at 1mhz instead of 3.646mhz.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits