Society of Robots - Robot Forum

Software => Software => Topic started by: rahul on April 20, 2008, 07:37:28 AM

Title: Problem with AVR : URGENT
Post by: rahul on April 20, 2008, 07:37:28 AM
Hi,

I was starting out with Robotics and thus tried to do my project with microcontrollers.
I am using Atmega 8 and following this tutorial.
http://www.opend.co.za/tutorials/avrtut3.htm

and using the ICP programmer as in :
http://www.opend.co.za/tutorials/avrtut2.htm

when I ran my code in Programmers Notepad (i.e. tools-> make all );
I ended with

errors:none
----end----


Then I connected my Programmer to printerport .. and the other end to respective pins of atmega8 and when I hit

tools->make program

I got the following error:

http://imageupload.com/out.php/i104535_error1.jpg


can anyone tell me where am I going wrong ?










thanks !!

I need help .. gotta finish it today !
Title: Re: Problem with AVR : URGENT
Post by: superchiku on April 20, 2008, 08:56:18 AM
giveio is not installed in ur computer so the parallel port is not recognised , do that 1st
Title: Re: Problem with AVR : URGENT
Post by: superchiku on April 20, 2008, 08:59:51 AM
install giveio.bat found in winavr/bin
Title: Re: Problem with AVR : URGENT
Post by: rahul on April 20, 2008, 09:38:38 AM
install giveio.bat found in winavr/bin

I guess I installed that ..

after tools->make program
winavr said
Errors:none
----end----

I wonder why it isnt working further .. ?
I applied 5v (4.5v actually) .. and poof .. nothing works !

Thanks anyways ... atleast I know my programmer works ! (Atleast I hope so .. )


any ideas .. what now ?
Title: Re: Problem with AVR : URGENT
Post by: superchiku on April 20, 2008, 09:40:22 AM
what do u mean by not working any further...

the make program button makes all the required hex and other files for the microcontroller...

u cant expect anything else from the make program button..
Title: Re: Problem with AVR : URGENT
Post by: rahul on April 20, 2008, 10:52:37 AM
The tutorial says that this is the last step.
take a look at the tutorial

http://www.opend.co.za/tutorials/avrtut3.htm

it says that after the 'make program' .. if no errors show up, your microcontroller is programmed. insert the AVR into the test circuit and apply 5v.

I did.
Was the led not supposed to blink ?
Title: Re: Problem with AVR : URGENT
Post by: superchiku on April 20, 2008, 01:06:28 PM
yes it is but thats not the programmers fault , some fault must be there in your algorithm show me your code ill explain..
Title: Re: Problem with AVR : URGENT
Post by: rahul on April 20, 2008, 02:30:26 PM
Its right there on the tutorial page .. I downloaded the code right from there .. here it is :

#include <avr/io.h>

// Last modified: 26 October 2006
// Changed to work with WinAVR 20060421
// modified: 21 April 2005


// Compiled on WinAVR 20060421

//---------------------
// function prototypes
void delay(void);
int main(void);
//---------------------



void delay(void)
{
uint32_t waitcounter;
   waitcounter = 100000;   
   while(0 != waitcounter) {
      waitcounter--;
   }   
}

int main(void)
{
uint8_t countval;

//---------
// initialise the hardware
   DDRC = 0xff;

//---------
// initialise the count value
   countval = 0;

//---------
// the main loop
   while(1) {
// the delay
      delay();
// the port counting
      PORTC = countval++;
   }
//---------

}




I made the ICP programmer RIGHT  as on that tutorial
http://imageupload.com/out.php/i104844_upload.png

since it said it an In Circuit Programmer, I made the ckt for led blinking as on the tutorial ..
connected to the programmer pins
applied 5v ..
used Winavr as said over there ..
first tools-->make all
then tools-->make program

closed winavr, disconnected the programmer .. and re-applied 5 v ...
I thought it would blink !

do sort out !

Title: Re: Problem with AVR : URGENT
Post by: rahul on April 20, 2008, 02:58:06 PM
I did tried again .. but this time I got :

http://img153.imagevenue.com/img.php?image=24820_reprogramming_no_5v_122_916lo.jpg

another attempt :

http://img189.imagevenue.com/img.php?image=24842_reprogramming_with_5v_WTF_122_32lo.jpg


I guess the AVR got the code .. maybe that's why it isn't accepting the code again .. or it died?

apologies, if I sound irritated and desperate ..
but that is how I feel ...

somebody .. please .. tell me where am I ??
Title: Re: Problem with AVR : URGENT
Post by: superchiku on April 21, 2008, 11:43:49 AM
first of all your code is quite wrong while(0 != waitcounter)...

no no no

this is not the format , its not plain english your talking , its a programming language write like this

while(waitcounter != 0)

then if your using atmega16 or 32 ,.... portc needs to be jtag disabled first before using it as normal i/o..

in place of that use port d instead

another thing portc=countval++ ??????????

what do u mean by that, its not a normal variable you are accessing , its a register write it in binary or hex form

like this PORTC=0x01;
it will switch on the 0th pin of port c

try to use this program instead....

Code: [Select]
#include <avr/io.h>

// Last modified: 26 October 2006
// Changed to work with WinAVR 20060421
// modified: 21 April 2005


// Compiled on WinAVR 20060421

//---------------------
// function prototypes
void delay(void);
int main(void);
//---------------------



void delay(void)
{
unsigned long int waitcounter;
   waitcounter = 100000;   
   while(waitcounter != 0) {
      waitcounter--;
   }   
}

int main(void)
{

//---------
// initialise the hardware
 DDRD=0x01;

//---------
// initialise the count value
 

//---------
// the main loop
   while(1) {
// the delay
      delay();
// the port counting
      PORTD ^=(1<<0)l;

   }
//---------

}



this is a much simpler code this will work on pin 0 of port d , switching it on and off at regular intervals
Title: Re: Problem with AVR : URGENT
Post by: rahul on April 21, 2008, 05:07:43 PM


// the port counting
      PORTD ^=(1<<0)l;




this is a much simpler code this will work on pin 0 of port d , switching it on and off at regular intervals



----edited----

I got it ! lemme test this thing again !!

I will look a little more idiot here, but I understood the whole code .. except this  ''   PORTD ^=(1<<0)l;    ''

can you explain this part please?


thanx !

Rahul.
Title: Re: Problem with AVR : URGENT
Post by: superchiku on April 22, 2008, 08:10:19 AM
oh.. there's a printing mistake..

its PORTD^=(1<<0);

not

PORTD^=(1<<0)|;

remember these are bit wise operators so if you dont know abt them then please try learning abt bitwise operators before you start mcu programming..
Title: Re: Problem with AVR : URGENT
Post by: Admin on April 26, 2008, 05:49:45 PM
What are you using to measure the PORTC pin voltages? I mean, how do you know it isn't working?

Also, your delay is really really short. Set waitcounter to 65500 and call delay multiple times in your while loop:
delay();
delay();
delay();
delay();


Title: Re: Problem with AVR : URGENT
Post by: Webbot on May 01, 2008, 04:37:09 AM
Quote
first of all your code is quite wrong while(0 != waitcounter)...

no no no

this is not the format , its not plain english your talking , its a programming language write like this

while(waitcounter != 0)
Either way will work - and its not uncommom for people to write conditions in this 'reverse' format. It's just a matter of taste - but its best to stick with one format or the other.


Quote
another thing portc=countval++
what do u mean by that, its not a normal variable you are accessing , its a register write it in binary or hex form
This code should still work though. If you had LEDs on each output pin then pin 1 will flash at half the speed, pin 2 at a quarter, pin 3 at an eight etc relative to pin 0. But superchiku is right in that you need to be aware that you are changing all 8 pins. If its just some test code then fine - but if you start to hook up other devices on the other 7 pins then you will start to get into trouble.

Also have you checked that the LED isn't broken? Try just setting the pin to 0 in your loop and see if the LED comes on. If not: try setting it to 1. If neither works then the LED is probably broken or connected the wrong way around.

Title: Re: Problem with AVR : URGENT
Post by: superchiku on May 01, 2008, 10:31:50 PM
Quote
another thing portc=countval++
what do u mean by that, its not a normal variable you are accessing , its a register write it in binary or hex form

This code should still work though


this wont work webbot the countval is kepe on increasing there is no limit after 7 it should be reset to 0 but it isnt, while 0!=waitcounter) is a very adhoc way of writing so its better not to do that
Title: Re: Problem with AVR : URGENT
Post by: Webbot on May 02, 2008, 09:08:33 AM
It does work !

Its no different from Admins code in $50 Robot
Code: [Select]
void configure_ports(void){
DDRC = 0x00;  //configure all C ports for input
PORTC = 0x00; //make sure pull-up resistors are turned off
DDRD = 0xFF;  //configure all D ports for output
DDRB = 0xC7;  //configure B ports 0, 1, 2, 6, 7 for output, 11000111
}

See that 'DDRD=0xFF' well if you added a line after saying 'PORTD=0xFF' then it would set all 8 pins on port D to high. Or 'PORTD=0xAA' which is '10101010' in binary would set 4 pins high and 4 pins low.

In the code above they are setting PORTC to a number that increases from 0 to 0xFF so it will turn all 8 pins on/off in a single instruction. So if you want pins 7,6 and 5 to be high and the rest low you could write 'PORTC=0xE0' which is much quicker, and takes less space, than:
PORTC |= (1<<7);
PORTC |= (1<<6);
PORTC |= (1<<5);
PORTC &= ~(1<<4);
PORTC &= ~(1<<3);
PORTC &= ~(1<<2);
PORTC &= ~(1<<1);
PORTC &= ~(1<<0);
Title: Re: Problem with AVR : URGENT
Post by: superchiku on May 02, 2008, 10:48:35 AM
i know abt that he has written portc=countval

countval++

it would go on without stopping like start count val from 0 then1 then 2 then so on... dont u realise that?
Title: Re: Problem with AVR : URGENT
Post by: Webbot on May 02, 2008, 11:06:49 AM
ok - this is my last response - I think we're going in circles.

Quote
it would go on without stopping like start count val from 0 then1 then 2 then so on... dont u realise that?
of course I do ! All I can suggest is that you build it with an LED on each pin of PORTC and then write this code:

Code: [Select]
uint_8 countval =0;
DDRC = 0xff; // set portc to output
while(1){
  PORTC =  countval++;
  wait for 1 second
}

Then you will see what I can see. Pin 0 flashing every 1 second, Pin 2 every 2 seconds, Pin 3 every 4 seconds, Pin 4 every 8 seconds etc etc.

Please don't reply - just build it!
Title: Re: Problem with AVR : URGENT
Post by: superchiku on May 02, 2008, 12:19:18 PM
my bad i didnt see it was uint_8 declaration i thought it was normal int , yes then it will work