go away spammer

Author Topic: Issues with $50 robot and Atmega168 !!  (Read 8037 times)

0 Members and 1 Guest are viewing this topic.

Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Issues with $50 robot and Atmega168 !!
« on: April 03, 2009, 01:36:37 PM »
I am having a few issues with my $50 robot. I have spent a lot of time (and money!) on this project, and I am starting to get discouraged.

Here is my status: I have built the circuit, tested and made sure that the servo outputs are getting the full battery voltage (approx 7 volts) and the sensor inputs are getting 5v regulated (also connected to the microcontroller as in the schematic). One question I have is regarding the servos. I opened it up and I know I need to either: 1) cut the pot head off and remove the plastic stopper on the big gear or 2) drill out a hole in the counterpart to the pot head so it can rotate freely, and remove the plastic stopper. My question is regarding writing the software to center out the servo before turning the pot by hand.

In this post (http://www.societyofrobots.com/robotforum/index.php?topic=4487.msg57787) the admin says to use the following code:

Code: [Select]
while(1)
{
wheel_left(30);
delay_ms(20);
}
and modify the 30 until the servo "centers". How do I know when the servo has centered? Also, does he mean to say servo_left instead of wheel_left? The servo only moves continuously when it is opened, and doesn't move at all when closed except when I first plug it in or wiggle the connector on the board (although sometimes I feel a very very slight nudge of the horn) is this normal?

My most irritating problem is trying to get the LED to turn on. I have tried LED_on() and LED_off(), as well as just trying the actual code from that function directly. I have also tried cbi(PORTD, PD4) because I saw it on someone else's code, and nothing works! I rechecked my circuit many times, and after hearing that the LED might be dead I replaced it with another one (my last one) and still same problem. I am able to write successfully to the circuit with no errors. What drives me nuts is that this is a relatively simple circuit. Most of the wires are power/ground wires, and the only other ones come from the programmer header and that seems to be working. So I figure either I will get a short and nothing will work, or the programmer will fail, or it should work! I followed the instructions carefully, and put the longer lead of the LED towards the atmega168, and it connects to the power. The shorter lead connects to the resistor and then that goes to PD4 on the chip.

PLEASE HELP!
Thanks


EDIT:
Ok, this is VERY STRANGE. Moments after I posted this, I decided to do a little test. I took the original LED that I swapped out because I thought it was dead. I put a resistor in the negative lead directly into the battery. I then touched the original LED's leads to the power lead on the battery, and the other end to the resistor. IT LIT UP! Why is this strange? Because I was using the LED in reverse! The long lead, and supposedly the + lead, was touched to the grounded resistor and the - lead was touched to the power on the battery. I can't understand this, maybe it was manufactured wrong? To be more specific, when you look at an LED it has one lead that looks like an upside down "L" which is supposed to be the cathode and the - lead. However this is the lead I touched to the Power of the battery! Can anybody explain this as it is very confusing... Should I just reverse the LED on my board or am I doing something else wrong?
« Last Edit: April 03, 2009, 03:49:35 PM by datt »

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Issues with $50 robot and Atmega168 !!
« Reply #1 on: April 03, 2009, 05:57:03 PM »
well you could try reversing the led on your board, but this is very strange. are you sure your battery is not backwards? but damn is this werid!
Howdy

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: Issues with $50 robot and Atmega168 !!
« Reply #2 on: April 03, 2009, 06:16:27 PM »
This is not the first time the strange LEDs have confused people. I bought the same LEDs mentioned in the $50 tutorial and they are reversed. Admin I would reccomend adding a note to the $50 robot tutorial about the reversed LEDs.

Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #3 on: April 03, 2009, 06:58:23 PM »
Haha wow... I'm glad the LED solution was as simple as that. But for my other issue...

EDIT: LED was not completely solved. I reversed the LED, and now every time I program the device the LED quickly blinks once regardless of whether or not I call LED_on(), and calling that function does not turn on the LED..... WHY!?!

Ok I feel if I pass this one problem, I will be completely set. Servos! Please bear with me as I am having trouble simply deciding where to begin explaining as I have spent so much time on this.

I am trying to modify my servos for continuous rotation. I have opened the servo, and I know the mechanical changes that need to be made. As for software, I tried running the code I posted above, and it seems like the code has no effect. The programmer reports success in uploading the hex file, but it seems to me that nothing is happening.

Case 1: Servo is sealed up, like it came in the mail
Upon plugging it in (PD0), there is a short counterclockwise movement in the servo and it seems like it has reached its "end point". If I jiggle the connector, sometimes I get other small jolts of motion. If I plug it into PD1, the same exact things happen except now it is in the clockwise direction.

Case 2: Servo is opened, so it is no longer bound by the stopper/pot
Upon plugging it in, same behavior as above except now the servos never stop spinning.

I am ready to start modding the servo, but I am not sure that I am sending it the "zero" command properly. As a test, I thought that if I move the pot until the servo stops, it thinks that it has reached the "requested angle". So to test if my code has any effect, I then tried to do a servo_left() with some other number, and I thought that the servo should start spinning again, but it does not move. I also tried to do a PORTD = 0xFF and then check the voltage on PD0, PD1 etc and it should be 5v, but all i get is approx .2 volts... I feel like I am rambling, I hope someone can read this (such as Razor, thanks for your previous answer!) and ask more questions if necessary. I feel like I have read the entire archive of these forums looking for a solution, and I hope someone out there can help.

Thanks in advance
« Last Edit: April 03, 2009, 07:33:40 PM by datt »

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: Issues with $50 robot and Atmega168 !!
« Reply #4 on: April 03, 2009, 07:52:28 PM »
What MCU are you using (mega168 or mega8)
Did you modify the code to run at 8mhz or did you just leave it alone?

Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #5 on: April 03, 2009, 08:07:05 PM »
I am using ATmega168, and the only modifications I made were the ones given by the tutorial which are:

(in makefile)
change
MCU = atmega8
to
MCU = atmega168

and also in the SoR_Utils.h file,
change
#include "timer.h"
to
#include "timerx8.h"

Looking at the fuses, CKDIV8 is enabled (this was enabled by default)

I really feel like no matter what I put into my code, it is not even seen by the MCU...

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Issues with $50 robot and Atmega168 !!
« Reply #6 on: April 03, 2009, 08:23:40 PM »
how about show us all your code

Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #7 on: April 03, 2009, 08:31:26 PM »
All my code is basically the same as it was provided from this site. Here is my test.c file:
Code: [Select]
#include "SoR_Utils.h"

int main(void)
{


initialize();

//printf("TEST!\n");
//cbi(PORTD,PD4);
//LED_on();
//delay_cycles(500);

while(1)
{

LED_on();
//PORTD = 0xFF;
//servo_left(35);
//delay_cycles(20);

// robot_turn_left();
// delay_cycles(500);
// robot_turn_right();
// delay_cycles(500);
// robot_go_straight();
// delay_cycles(500);
// servo_right(32);
// delay_cycles(500);
// servo_scan(33);

}
return 0;
}

You can see I went through a lot of attempted debugging. Is there any more advanced method of debugging? I tried setting break points to make sure that my code is actually being looked at, but every time I try to debug it says it cannot bind the breakpoint would I like to continue anyway without breakpoints...

Here is the SoR_Utils.h:
Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2007 www.societyofrobots.com[url=http://][/url]
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
* SoR Utilities v1, March 10th, 2007
*
****************************************************************************/

//AVR includes
#include <avr/io.h>     // include I/O definitions (port names, pin names, etc)
#include <avr/interrupt.h> // include interrupt support

//AVRlib includes
#include "global.h" // include global settings
#include "buffer.h" // include buffer function library
#include "uart.h" // include uart function library
#include "rprintf.h" // include printf function library
#include "timerx8.h" // include timer function library (timing, PWM, etc)
#include "a2d.h" // include A/D converter function library

//define port functions; example: PORT_ON( PORTD, 6);
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)
#define PORT_ALL_ON( port_letter, number ) port_letter |= (number)
#define PORT_ALL_OFF( port_letter, number ) port_letter &= ~(number)
#define FLIP_PORT( port_letter, number ) port_letter ^= (1<<number)
#define PORT_IS_ON( port_letter, number ) ( port_letter & (1<<number) )
#define PORT_IS_OFF( port_letter, number ) !( port_letter & (1<<number) )


//************CONFIGURE PORTS************
//configure ports for input or output - specific to ATmega8
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
}
//***************************************

//************DELAY FUNCTIONS************
//wait for X amount of cycles (23 cycles is about .992 milliseconds)
//to calculate: 23/.992*(time in milliseconds) = number of cycles
//or (number of cycles)*.992/23 = time in milliseconds
void delay_cycles(unsigned long int cycles)
{
while(cycles > 0)
cycles--;
}
//***************************************

//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_OFF(PORTD, 4);//turn LED on
}
void LED_off(void)
{
PORT_ON(PORTD, 4);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);
}
void servo_scan(signed long int speed)
{
PORT_ON(PORTD, 2);
delay_cycles(speed);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);
}
void robot_turn_left(void)
{
servo_left(25);
servo_right(25);
}
void robot_turn_right(void)
{
servo_left(44);
servo_right(44);
}
void robot_go_straight(void)
{
servo_left(25);
servo_right(44);
}
void hold_position(void)//37
{
servo_left(39);//39
servo_right(35);//35
}
//***************************************

//*************INITIALIZATIONS***********
void initialize(void)
{
//other stuff Im experimenting with for SoR
//uartInit();  // initialize the UART (serial port)
//uartSetBaudRate(9600);// set the baud rate of the UART for our debug/reporting output
//rprintfInit(uartSendByte);// initialize rprintf system

//timerInit(); // initialize the timer system

configure_ports(); // configure which ports are analog, digital, etc.
a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

//rprintf("Initialization Complete\r\n");
}
//****************************************


Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Issues with $50 robot and Atmega168 !!
« Reply #8 on: April 03, 2009, 08:47:10 PM »
LED_on should look like this

Code: [Select]
void LED_on(void)
{
PORT_ON(PORTD, 4);//turn LED on
}
Your LED will not turn on if you turn the voltage to it off. PORT_OFF turns off the voltage.

LED_off should look like this

Code: [Select]
void LED_off(void)
{
PORT_OFF(PORTD, 4);//turn LED off
}


Also you are including the timerx8.h which is for a processor running at 8MHz, but you said you have CKDIV8 checked which is dividing the default clock speed by 8. So in effect 8/8 = 1MHz. You need to unprogram CKDIV8.

Please set your fuses like this:
http://www.engbedded.com/cgi-bin/fc.cgi?P_PREV=ATmega168&P=ATmega168&V_LOW=62&V_HIGH=DF&V_EXTENDED=F9&M_LOW_0x3F=0x22&M_HIGH_0x07=0x05&M_HIGH_0x20=0x00&M_EXTENDED_0x06=0x00&B_CKDIV8=P&B_SPIEN=P&B_SUT0=P&B_CKSEL3=P&B_CKSEL2=P&B_BOOTSZ1=P&B_BOOTSZ0=P&B_CKSEL0=P

And multiply all your cycles by 8

Please go through this tutorial as the default $50 robot code is written for an ATmega8
http://www.societyofrobots.com/step_by_step_atmega168_swapout.shtml
« Last Edit: April 03, 2009, 08:58:51 PM by pomprocker »

Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #9 on: April 03, 2009, 08:51:46 PM »
The LED_on() and LED_off() functions were written by SoR. The way Admin has it set up is that the current is trying to go through the LED, through the resistor, and sink into the microcontroller. When the port is pulled high, current cant go through, but you "turn the port off" to allow the current to flow and hence the LED turns on. Looking at it now, it seems like the best way would be to have PD4 source the voltage. The way the schematics dictate, the power hits the LED as soon as the battery is attached (or the switch is turned on, if one exists) but current only flows when the PD4 port is set low... At least this is my understanding, does anybody else think different? Anyway, I tried LED_on() and LED_off() and neither work :|

I see what you're saying about the clock divider and it makes sense, but right now I'm just trying to get the LED to light up, and I already tried disabling the CKDIV8 fuse (no effect).
« Last Edit: April 03, 2009, 09:01:18 PM by datt »

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Issues with $50 robot and Atmega168 !!
« Reply #10 on: April 03, 2009, 08:56:31 PM »
PORT_OFF brings the voltage low (0vdc), a red LED needs 2vdc of forward voltage, a blue LED needs 3.3vdc forward voltage.

PORT_ON brings the voltage high (5vdc), the resistor will limit the current and give it the voltage it needs to light your LED.

Please play with the LED wizard if you don't comprehend.
http://led.linear1.org/1led.wiz

source voltage is 5vdc since it gets regulated
LED forward voltage is 2vdc if its red
LED forward current in 20mA
You can always check component datasheets if you're not sure.



Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #11 on: April 03, 2009, 09:04:02 PM »
I know what you're saying, but if you look at the schematic for the robot

http://www.societyofrobots.com/images/sbs_avr_schematic.png

or my attachment, you see that the LED is connected directly to the supply voltage, and the other end is connected to a resistor which then connects to PD4

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Issues with $50 robot and Atmega168 !!
« Reply #12 on: April 03, 2009, 09:09:10 PM »
ok, you are not even using any timer functions in your code so i would comment out your timerx8.h include. as you are just using the delay cycles function for pauses.


also you should comment your closing brackets as to what they are to avoid confusion.

Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2007 www.societyofrobots.com[url=http://][/url][url=http://][/url]
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
* SoR Utilities v1, March 10th, 2007
*
****************************************************************************/

//AVR includes
#include <avr/io.h>    // include I/O definitions (port names, pin names, etc)
#include <avr/interrupt.h> // include interrupt support

//AVRlib includes
#include "global.h" // include global settings
#include "buffer.h" // include buffer function library
//#include "uart.h" // include uart function library
//#include "rprintf.h" // include printf function library
//#include "timerx8.h" // include timer function library (timing, PWM, etc)
#include "a2d.h" // include A/D converter function library

//define port functions; example: PORT_ON( PORTD, 6);
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)
#define PORT_ALL_ON( port_letter, number ) port_letter |= (number)
#define PORT_ALL_OFF( port_letter, number ) port_letter &= ~(number)
#define FLIP_PORT( port_letter, number ) port_letter ^= (1<<number)
#define PORT_IS_ON( port_letter, number ) ( port_letter & (1<<number) )
#define PORT_IS_OFF( port_letter, number ) !( port_letter & (1<<number) )


//************CONFIGURE PORTS************
//configure ports for input or output - specific to ATmega8
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
}
//***************************************

//************DELAY FUNCTIONS************
//wait for X amount of cycles (23 cycles is about .992 milliseconds)
//to calculate: 23/.992*(time in milliseconds) = number of cycles
//or (number of cycles)*.992/23 = time in milliseconds
void delay_cycles(unsigned long int cycles)
{
while(cycles > 0)
cycles--;
}
//***************************************

//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_ON(PORTD, 4);//turn LED on
}
void LED_off(void)
{
PORT_OFF(PORTD, 4);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);
}
void servo_scan(signed long int speed)
{
PORT_ON(PORTD, 2);
delay_cycles(speed);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);
}
void robot_turn_left(void)
{
servo_left(25);
servo_right(25);
}
void robot_turn_right(void)
{
servo_left(44);
servo_right(44);
}
void robot_go_straight(void)
{
servo_left(25);
servo_right(44);
}
void hold_position(void)//37
{
servo_left(39);//39
servo_right(35);//35
}
//***************************************

//*************INITIALIZATIONS***********
void initialize(void)
{
//other stuff Im experimenting with for SoR
//uartInit();  // initialize the UART (serial port)
//uartSetBaudRate(9600);// set the baud rate of the UART for our debug/reporting output
//rprintfInit(uartSendByte);// initialize rprintf system

//timerInit(); // initialize the timer system

configure_ports(); // configure which ports are analog, digital, etc.
a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

//rprintf("Initialization Complete\r\n");
}
//****************************************


Code: [Select]
#include "SoR_Utils.h"

int main(void) {


    initialize();

    while(1) {

LED_on();
        robot_go_straight();

    }  // end while
return 0;
}  // end main


In the above code it is for 1MHz, in this case leave your clock divide by 8 (CKDIV8) fuse programmed. Also make sure your global.h and makefile is set up for an ATmega168 running at 1MHz


Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Issues with $50 robot and Atmega168 !!
« Reply #13 on: April 03, 2009, 09:12:42 PM »
I know what you're saying, but if you look at the schematic for the robot

http://www.societyofrobots.com/images/sbs_avr_schematic.png

or my attachment, you see that the LED is connected directly to the supply voltage, and the other end is connected to a resistor which then connects to PD4


I apologize I see what your saying. That is an odd way to do it. OK well, the VCC is your 5v going directly to the LED, but the current is being limited by the resistor, and the PD4 needs to be 0vdc to act as a ground for it to light.

If it were me I would wire the resistor to PD4, then the anode (long leg) of the LED to the resistor, and the cathode (short leg) to ground. That way all you need to do to turn on the LED is bring the pin high with PORT_ON

Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #14 on: April 03, 2009, 09:22:52 PM »
Yeah I didn't even realize it while I was soldering, I just wanted to get it up and running before I messed with it. But I agree it seems like a better idea to have PD4 source the voltage, go through a resistor, then the LED then ground. It just makes more logical sense to "turn on" a port and have the led turn on as well.

I tried again (using the code you just gave), and still no luck! All that happens is the LED blinks once briefly every time I program the device or when I plug in the battery for the first time. My makefile says

MCU = atmega168
and
F_CPU = 1000000

The global.h file just redefines F_CPU so I just commented that part out (it said #define F_CPU 3686400)
Do I need to include "#define" in the makefile also? It seems "#" means a comment in the makefile. And i'm modifying the global.h file that is in the project directory, is this the one it loads?
« Last Edit: April 03, 2009, 09:24:44 PM by datt »

Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #15 on: April 03, 2009, 09:30:59 PM »
HOLY CRAP!!!!
I do believe I just scared all my neighbors with my yelling.

:) :)
I've always thought that no matter what code I write, the MCU doesn't even see it :)

So in the makefile, I found a line
SRC = $(TARGET).c a2d.c

however since my source filename isn't the same as whatever TARGET is (Photovore_v1 or atmega168 i duno who cares)
it did not load the file!
I changed to
SRC = test.c a2d.c

and the LED WORKS!!! hahaha!

Wow, now I will have some work to do on the servos, but I think i'm gonna let my brain rest a while first, I spent the whole day on this!!

Thank you so much for taking your time to help me out pomprocker (also thanks to Razor Concepts and SmAsH).

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Issues with $50 robot and Atmega168 !!
« Reply #16 on: April 03, 2009, 09:43:48 PM »
i dont really see what i did, but hey thanks ;D and glad to hear your board works!
Howdy

Offline dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #17 on: April 03, 2009, 10:03:24 PM »
Just thanks for your time and input!  ;)

Offline GearMotion

  • Supreme Robot
  • *****
  • Posts: 489
  • Helpful? 24
  • Two decades+ of Embedded Design
    • CircuitGizmos
Re: Issues with $50 robot and Atmega168 !!
« Reply #18 on: April 04, 2009, 09:52:14 AM »
I apologize I see what your saying. That is an odd way to do it. OK well, the VCC is your 5v going directly to the LED, but the current is being limited by the resistor, and the PD4 needs to be 0vdc to act as a ground for it to light.

If it were me I would wire the resistor to PD4, then the anode (long leg) of the LED to the resistor, and the cathode (short leg) to ground. That way all you need to do to turn on the LED is bring the pin high with PORT_ON

It certainly isn't an odd way to do it at all. In fact it is more common to do it that way.

The reason? Historically output pins have had better current _sinking_ ability (pull to ground) than current _sourcing_ ability (provide current). 

You should be able to recognize either way as valid, and the current sinking (low = on) as more common.

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Issues with $50 robot and Atmega168 !!
« Reply #19 on: April 04, 2009, 12:03:25 PM »

You should be able to recognize either way as valid, and the current sinking (low = on) as more common.


Can you reference this? I'd like to read more about it.

Offline Jdog

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: Issues with $50 robot and Atmega168 !!
« Reply #20 on: April 04, 2009, 12:26:46 PM »
That's how the axon's led is set up.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Issues with $50 robot and Atmega168 !!
« Reply #21 on: April 04, 2009, 12:33:22 PM »
Can you reference this? I'd like to read more about it.

Check out the 'Typical Characteristics' section of the datasheets. For an ATMega168 with Vcc=5v then each IO pin can source about 40mA but can sink about 60mA.

Also don't forget that the IO pin which the LED is connected to can also be used to drive other output devices so it may be required to source current for the LED plus the output device if it was cinfigured as 'pin high = on'. So Admins design appears the preferred route.
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 GearMotion

  • Supreme Robot
  • *****
  • Posts: 489
  • Helpful? 24
  • Two decades+ of Embedded Design
    • CircuitGizmos
Re: Issues with $50 robot and Atmega168 !!
« Reply #22 on: April 04, 2009, 01:11:28 PM »

You should be able to recognize either way as valid, and the current sinking (low = on) as more common.


Can you reference this? I'd like to read more about it.

Very roughly speaking the PIC was the first microcontroller I noted that could source enough current on its output to drive an LED. Until then, most microcontrollers I've dealt with were only able to sink that much current. (Even though it isn't a LOT of current, really.) Before that microcontrollers often had outputs that were CMOS/TTL type and couldn't source/sink much at all. Drivers (chip or transistor) were necessary to drive even LEDs.

The silicon technology has moved to a point where newer micros are more capable, but still many will have open collector/drain outputs capable of greater current sinking than sourcing.

Also, in the interest of being pedagogical, if you want to swap out the LED and drive something like a motor using a transistor or FET, then you might want to think in terms of a "low-side switch" - The LED/motor connected to a high voltage and the operation of the circuit switching the driver on buy connecting the LED/motor to ground.


Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Issues with $50 robot and Atmega168 !!
« Reply #23 on: April 04, 2009, 05:23:53 PM »

Also don't forget that the IO pin which the LED is connected to can also be used to drive other output devices so it may be required to source current for the LED plus the output device if it was cinfigured as 'pin high = on'. So Admins design appears the preferred route.


I kinda lost you here....you're saying that if you use the pin to connect a servo, then everytime the pin gets pulsed, the LED will flash?

btw...I was never able to get my LED workin on my $50 robot board.

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Issues with $50 robot and Atmega168 !!
« Reply #24 on: April 04, 2009, 05:30:43 PM »

Also don't forget that the IO pin which the LED is connected to can also be used to drive other output devices so it may be required to source current for the LED plus the output device if it was cinfigured as 'pin high = on'. So Admins design appears the preferred route.


I kinda lost you here....you're saying that if you use the pin to connect a servo, then everytime the pin gets pulsed, the LED will flash?

btw...I was never able to get my LED workin on my $50 robot board.
i guess it would? and if you got your led from the place that admin said it may be connected backwards as there was a polarity problem with them. there is a recent thread on this if you want to look it up.
Howdy

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Issues with $50 robot and Atmega168 !!
« Reply #25 on: April 04, 2009, 08:26:34 PM »

Also don't forget that the IO pin which the LED is connected to can also be used to drive other output devices so it may be required to source current for the LED plus the output device if it was cinfigured as 'pin high = on'. So Admins design appears the preferred route.


I kinda lost you here....you're saying that if you use the pin to connect a servo, then everytime the pin gets pulsed, the LED will flash?


Yep.
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 dattTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Issues with $50 robot and Atmega168 !!
« Reply #26 on: April 04, 2009, 08:35:10 PM »
Quote
i guess it would? and if you got your led from the place that admin said it may be connected backwards as there was a polarity problem with them. there is a recent thread on this if you want to look it up.

That's this thread!  ;D

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Issues with $50 robot and Atmega168 !!
« Reply #27 on: April 04, 2009, 08:42:33 PM »
Quote
i guess it would? and if you got your led from the place that admin said it may be connected backwards as there was a polarity problem with them. there is a recent thread on this if you want to look it up.

That's this thread!  ;D
no way man! what was i on? i have really bad memory right now as its exams and ive got tonnes of homework and assignments, i apologise if i seem dopey at all :)
Howdy

 


Get Your Ad Here