go_away

Author Topic: [SOLVED] Desperate request for help - fourth time building controller  (Read 1083 times)

0 Members and 1 Guest are viewing this topic.

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
I am now in the fourth iteration of my attempt to build the $50 robot micro-controller. Most of my previous attempts have been foiled by an inability to solder well, though after the fourth time I am finding myself quite adept at it.

Having purchased entirely new components for this most recent attempt, and having tested each connection and validated everything I know how to - and having the system not respond, just as it hasn't the past two attempts - is something I just cannot understand (and of course my wallet is having trouble understanding as well).

I just really can't move on without understanding what issue could be causing this problem - it has to be something fundamental that I am doing wrong, and my problem is I do not understand where to look. Other than checking circuit continuity, resistance, voltages - I do not understand what to check, or how to try to find the error. I am at a total loss and really just looking for help - I would greatly appreciate any thoughts. There is clearly something I simply do not understand and I have nobody to turn to in order to try to assist in figuring out what I am missing.

------------------------------------------------------------

I have the six pin connector setup, but am using a battery pack now so a single source of power from a NiMH 2000mAh, 6v battery pack.


I have used my multimeter and have ensured that everything is connected as should be on the circuit diagram, and that there are no connections that should not be. I have used the resistance setting and validated that the 5v power and the ground have a 10kOhm resistance, well over the 5k suggested as minimum in the tutorial. There is no connectivity at all from my ground to the unregulated power.

In terms of voltage, the regulated power reads a consistent 5v. The unregulated reads around 6.4, again consistently.


When I connect the programmer, I am able to flash the program on and AVR studio's 'verify' step completes successfully.


Some things of note: The LED does not come on, no matter how I play with flipping the ports on/off. The voltage on the output D pins of the controller (which is an ATMega168A) varies from .1 to as high as 1v when I play with code flipping them on or off - the only exception to this is the pin attached to the LED. That pin, D4, always reads about 3.6 - which seems to me to be the 5v power minus the value of the resistor I have in series with the LED. On the right hand side, when I upload the code for the robot, it is sending signals to where the photoresistors (not yet in use) would be connected. I know this because if I plug the servos in over there they start making noises and twitching, though not spinning - no doubt due to lack of capacitor and sufficient power and whatnot. So I seem to be getting signals over in the 'C' paths but not 'D'. When I use the programmer to erase the flash, this stops and the servos are quiet.


When attached to the correct, unregulated side pins, the servos do nothing - not even a hum.

Here is an example of code I have compiled and uploaded successfully which causes the sensor side to activate in some way but the port D side with unregulated power to do absolutely nothing:

Code: [Select]
int main(void)
{
//declare variables here
//int i=250;//a 'whatever' variable int sensor_left=0;//left photoresistor
int sensor_right=0;//right photoresistor
int threshold=8;//the larger this number, the more likely your robot will drive straight


/****************INITIALIZATIONS*******************/
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
/**************************************************/


/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_off();//turn LED on


while(1)
{
//store sensor data
sensor_left=a2dConvert8bit(5);
sensor_right=a2dConvert8bit(4);

servo_left(25);
servo_right(44);

delay_cycles(500);//a small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/

return 0;
}

I will post some pictures shortly after this post goes up of my current controller circuit.

I am hoping in particular maybe somebody can help me understand:

Is it right that the voltage on the D pins of the ATMega vary only between ~0.1 (ports off) and 0.9 (ports on) when I force this via code using the PORT_On and PORT_Off as supplied in the $50 robot header file?

Is it right that the voltage on the pin connected over to the LED should be about 3.6 no matter what, regardless of whether the pin is hardcoded on or off?

Is there something else I should be checking other can using the connectivity sensor to ensure connections are where they should be, and the resistance setting to ensure connections aren't where they shouldn't?

Is it right that the sensors seem to be getting pulses from the controller, given my code setup?

What rookie mistake am I making?
« Last Edit: February 21, 2011, 02:19:44 PM by dmclifton »

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
Here are pictures - a couple things to note.

As this was my fourth attempt, and I had purchased multiple of some parts from mouser, I picked up a couple from radioshack to speed up the process. In particular, you can see the LED, ceramic capacitor, and radial capacitor are a bit different. The radial capacitor is 220uF and the ceramic one is 0.1uF as described - the reason these are bigger is they are both rated up to 50v - overkill for this but it was what was in stock at the store. The led is a clear, red LED though shaped into a square rather than the smooth shape on the one used in the tutorial.

You'll also note that the board itself has some pre-done connections, which I used to help guide my 'bridge' soldering - it also happened to be what was available at radio shack. The one thing you'll note is that because of this, I could not wire the resistor in where it is placed in Admin's tutorial - this is because if I did, it would be connected to the pin next to it, when what we want is the LED connected to that pin on the positive side. So I have the led in that spot on one pin to simplify things, and the resistor is off to the side - the connections are the same however, controller power line to led, to resitor, to controller D4 pin.








Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
If this is your fourth attempt and all tries have shown the same behaviour it is unlikely to be related to your soldering. If the programmer reports it is working ok but you don't see stable logic voltages on the output pins it is likely there is some factor preventing proper code execution.

Worth a try would be:
Using separate supplies for the processor and the servos. 6.4V gives a very small drop out margin for the typical 5V regulator so it is possible that under load you simply don't have a regulated supply for your processor and are seeing brown out. Try feeding the regulator with 7.5V - 12V, or use 3 AA/AAA batteries to make a 4.5V supply and bypass the regulator completely (connect them in series using wire and insulating tape). Use the 6.4V battery to feed the servos only. Take care not to feed the servos with a higher voltage, or connect supply positives in any way.

Adding a 10KOhm pull-up resistor from the reset pin (pin 1) to VCC/+5V. If this pin sees a logic low it will reset the processor so pull it up to logic 1 (and test it) to make sure.   

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
If this is your fourth attempt and all tries have shown the same behaviour it is unlikely to be related to your soldering. If the programmer reports it is working ok but you don't see stable logic voltages on the output pins it is likely there is some factor preventing proper code execution.

Worth a try would be:
Using separate supplies for the processor and the servos. 6.4V gives a very small drop out margin for the typical 5V regulator so it is possible that under load you simply don't have a regulated supply for your processor and are seeing brown out. Try feeding the regulator with 7.5V - 12V, or use 3 AA/AAA batteries to make a 4.5V supply and bypass the regulator completely (connect them in series using wire and insulating tape). Use the 6.4V battery to feed the servos only. Take care not to feed the servos with a higher voltage, or connect supply positives in any way.

Adding a 10KOhm pull-up resistor from the reset pin (pin 1) to VCC/+5V. If this pin sees a logic low it will reset the processor so pull it up to logic 1 (and test it) to make sure.   

Thanks much for the reply. In the previous attempt, I did the two battery configuration - a 9v going into the regulator and separately 4xAA batteries in series for driving the servos. I actually went with the battery pack to try to 'simplify' things, but I can fairly easily switch this circuit with a couple quick wiring changes - would this be a good test?

On the pull-up resistor, just want to make sure I understand the right way to do this. So I would solder in a 10KOhm resistor to the board, then connect reset to one end of the resistor and run a wire to the 5V regulated power from the other end of the resistor - this would then cause it to receive 5V unless the programmer grounds it, keeping it 'high' - right?

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Changing the supplies is certainly worth a try. Use the 6.4V pack for the servo power bus and the 9V for the regulator input. Strictly speaking 6.4V is slightly high for powering your servos but the voltage should soon drop under load. Possibly try your 4AA solution again too just in case.

For the pull-up resistor that's exactly right.

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
So - I wasn't able to get my soldering iron out as I'm watching my son today and don't want to be running off with a hot iron on. However, I was playing around and pulled up some 'world's most basic code examples' from some intro to AVR websites. I took Photovore_v1.c and commented out everything including the include and the configure ports and all that.

I then added a direct include to avr/io.h. Then I did DDRD = 0xFF and then PORTD = 0x00 or 0xFF

I now have a blinking red LED - where I could get never anything before. I can only assume I couldn't before due to something with configure_ports or similar code...but I'm needless to say quite excited to see it.

I'll be testing things out with just software changes and see how it goes, then come back to the hardware adjustments as needed. I'll post here with results.

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
I now have servos that spin as well as a LED that lights - so it looks like the problem I had was totally software based.

In case anybody would like to use it in some future testing of their own robots, here's the code I have working - I haven't yet figured out why, specifically, using the code provided did not work - probably something I did wrong, I'll do some digging later after I get the sensors together and working as well.

I'm using an ATMega168A.

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

#include "global.h"
#include "a2d.h"

void delay_ms( unsigned long int ms ) {

_delay_ms( ms );

}

void delay_cycles( unsigned long int cycles ) {

while( cycles > 0 )
cycles--;

}

void PORTD_HIGH( int position ) {

PORTD |= (1 << position);

}

void PORTD_LOW( int position ) {

PORTD &= ~(1 << position);

}

void LED_ON( void ) {

PORTD_LOW(4);

}

void LED_OFF( void ) {

PORTD_HIGH(4);

}

void servo_left( signed long int speed ) {

PORTD_HIGH( 0 );
delay_cycles( speed );
PORTD_LOW( 0 );//keep off
delay_cycles(200);

}

void servo_right( signed long int speed ) {

PORTD_HIGH( 1 );
delay_cycles( speed );
PORTD_LOW( 1 );//keep off
delay_cycles(200);

}

void configure_ports( void ) {

  DDRD = 0xFF; // Set Port D pins as all outputs
DDRC = 0x00; // Set all C ports for input
PORTC = 0x00; // Make sure pull-up resistors are turned off

}

int main( void ) {

    // Setup input and output ports as such
  configure_ports();

// Turn on the LED for visual effect
LED_ON();

while(1) {

//go straight
servo_left(25);
servo_right(44);

// Delay to avoid "crazy" oscillations
delay_cycles(500);

}

return 1;

}
« Last Edit: February 21, 2011, 02:36:45 PM by dmclifton »

Offline dmcliftonTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 1
Re: [SOLVED] Desperate request for help - fourth time building controller
« Reply #7 on: February 21, 2011, 09:52:57 PM »
I was able to get the photocell sensors attached and have a fully working photovore. I realized after building the sensors that I should have paid more attention to the tutorial on what resistors to use rather than just putting on the 1.6KOhm resistors that were listed in the parts list - I found that I have one light sensor that is much more sensitive than the other. I pulled out my multimeter and found about a volt difference between the two when pointed at the same light.

The obvious real answer, which I'll do at some point, is build better light sensors by doing the math and taking the time to get it right. In the meantime, in case anybody else finds it useful, I found doing this worked for 'getting it done' if not perfectly, then enough to sit back and watch my robot wander around finding light.

Code: [Select]
sensor_left=a2dConvert8bit(5);
sensor_right=a2dConvert8bit(4)+62;

You can see I have a manually added factor to 'sensor_right' so that when it does the if statements further down to decide which way to turn, the right sensor has been skewed in order to make up for the skewing I am getting from having different resistance on the one sensor.

It isn't perfect, as I think that sensor is definitely acting less 'sensitive' than the other, but it does the job without spending any cash - and while the local electronics store is closed.

I also adjusted the #'s on the speed in order to go straight - the others seem to be fine, but going straight was way off...I purchased the servos that were already full rotation so not having to center them at any point may be part of it - don't know.

Thanks again to everybody that helped - this has really been a fantastic learning experience - I am very glad to have done it.

 


Get Your Ad Here