Author Topic: Problem with AVR : URGENT  (Read 5125 times)

0 Members and 1 Guest are viewing this topic.

Offline rahulTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Problem with AVR : URGENT
« 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 !
« Last Edit: April 20, 2008, 07:38:12 AM by rahul »

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #1 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
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #2 on: April 20, 2008, 08:59:51 AM »
install giveio.bat found in winavr/bin
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline rahulTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Re: Problem with AVR : URGENT
« Reply #3 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 ?

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #4 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..
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline rahulTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Re: Problem with AVR : URGENT
« Reply #5 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 ?

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #6 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..
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline rahulTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Re: Problem with AVR : URGENT
« Reply #7 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 !


Offline rahulTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Re: Problem with AVR : URGENT
« Reply #8 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 ??

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #9 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
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline rahulTopic starter

  • Jr. Member
  • **
  • Posts: 15
  • Helpful? 0
Re: Problem with AVR : URGENT
« Reply #10 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.
« Last Edit: April 22, 2008, 05:34:49 AM by rahul »

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #11 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..
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Problem with AVR : URGENT
« Reply #12 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();



Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Problem with AVR : URGENT
« Reply #13 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.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #14 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
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Problem with AVR : URGENT
« Reply #15 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);
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #16 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?
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Problem with AVR : URGENT
« Reply #17 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!
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Problem with AVR : URGENT
« Reply #18 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
« Last Edit: May 02, 2008, 12:26:50 PM by superchiku »
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

 


Get Your Ad Here