Hooking up AVR

Thread Starter

Mazaag

Joined Oct 23, 2004
255
Hey guys...

I have just been experimenting with atmel's SKT500, and its time for me to remove the AVR from the development board and replicate the desired circuit on a breadboard.

I had a few questions regarding the power that has to be supplied to the AVR...

I'm looking at the data sheet of the AVmega8515and it says that max Power Supply current (with 5v VCC) is about 12mA. I am planning on using a battery pack (4x1.5 = 6v) .. How is it possible to limit the current and voltage going into the VCC pin ? is it neccessary to do that ?

Thanks guys
 

hgmjr

Joined Jan 28, 2005
9,029
No need to limt the current. That specification is just indicating that at 5 volts the device consumes 12 milliamps.

I have had a lot of luck starting with only two 1.5 volt batteries (3V) together with a boost regulator such as the LT1110 made by Linear Technologies.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,029
Here is the lt1110 datasheet. I just used the example shown on the first page of the datasheet. I used a fixed 5V version of the lt1110 and it worked quite well. The parts count is very low and the regulation is very good. It works down to 1 volt so you can squeeze almost every drop out of the two batteries. It even has a built-in comparator that you can wire up to provide a battery low signal to the AVR so that it can take a prescribed action under low battery conditions.

What other loads are you planning to power with the 5V power supply besides the AVR?

hgmjr
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
My main goal is to eventually use the AVR to drive stepper motors. I understand that they do not source enough current, so I would require amplifiers of some sort in order to drive the motors. I also need to look into how to control stepper motors ( i don't want to use a off-the-shelf controller).

But before achieving that, I just want to light up a few LEDs on a breadboard.

On the STK , when you set the outuput of a port to 0xFF , the leds are actually OFF, is that because of the way the LEDs are connected on the STK board ? or does the AVR always invert the output ?

Another question about "Fuses" .. what exactly are they ? are they some sort of configuration bits? I want to use the internal oscillator, and I know AVRstudio allows you to set it up using the "Fuses", you pick the desired oscillator and frequency, but what I don't understand is the " + xx ms" written after the oscillation frequency..
 

hgmjr

Joined Jan 28, 2005
9,029
My main goal is to eventually use the AVR to drive stepper motors. I understand that they do not source enough current, so I would require amplifiers of some sort in order to drive the motors. I also need to look into how to control stepper motors ( i don't want to use a off-the-shelf controller).
You are correct. To drive a stepper motor you will need to provide the driver hardware between the AVR and the stepper motor. This is typical of most microcontrollers. They are usually able to drive a few milliamps but that is about all.

I have written code that runs on an AVR to control a unipolar stepper motor and it worked just fine. I did not want to use an off-the-shelf controller either.

But before achieving that, I just want to light up a few LEDs on a breadboard.
You should be able to power an led from an AVR output with the proper series current limiting resistor.
On the STK , when you set the outuput of a port to 0xFF , the leds are actually OFF, is that because of the way the LEDs are connected on the STK board ? or does the AVR always invert the output ?
The STK is introducing the inversion you are encountering. The AVR output is not inverted.
Another question about "Fuses" .. what exactly are they ? are they some sort of configuration bits? I want to use the internal oscillator, and I know AVRstudio allows you to set it up using the "Fuses", you pick the desired oscillator and frequency, but what I don't understand is the " + xx ms" written after the oscillation frequency..
Fuse are internal configuration bits that are set or cleared to control the various features that are available in the AVR being used.

The millisecond time that is associated with the internal oscillator as I understand it is there to hold off the beginning of execution for the indicated period of time. For more details you can probably find an application note that describes this aspect of the AVR on Atmel's Website.

hgmjr
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
What type of amplifiers did you use to drive the stepper motor? was it MOSFET based or BJT based?
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
Is it neccesary to use Voltage Regulators to feed Vcc ? if not, when is it neccessary ?


Thanks
 

hgmjr

Joined Jan 28, 2005
9,029
What type of amplifiers did you use to drive the stepper motor? was it MOSFET based or BJT based?
Since I was using a unipolar stepper motor, the drivers I used were ordinary n-channel MOSFETs. All I needed was four of them. If you decide to use a bipolar stepper motor you would most likely want to use a couple of H-bridge drivers.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,029
Is it neccesary to use Voltage Regulators to feed Vcc ? if not, when is it neccessary ?

Thanks
I would strongly recommend you use a voltage regulator. The microcontroller needs a stable power supply to work best.

The lt1110 served my needs well since it produced the 5V out for an input voltage as low as 1.7 volts.

I used four AAA batteries in series in my design. I used the raw 6 volts to power the stepper motor and I tapped off at the 3 volt point in my battery pack to feed the LT1110 to produce the 5v to power the AVR.

Be aware that the stepper motor is a power hungry little bastard and so it tends to draw battery power at an uncomfortable rate. I'm still working on improving my battery consumption. I have even considered trying to design my own witricity power source to power the unit. It is a headbot so the distance over which the witricity would have to work would be a matter of inches.

hgmjr
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
Sounds cool !

I hooked up the stepper motor and managed to get it running :), what i'm trying to do now is to have an input control the direction of rotation of the motor... So far , I have pin 1 of PORT D to be forward, whilst pin 2 to be reverse direction, however, I can't seem to get it work... ( I use a wire straight from Vcc to the desired pin, but it doesn't seem to work .. )


Rich (BB code):
#include <avr/modifiedio.h>
 
int main(void)
{
DDRB = 0xFF;
DDRD = 0;
int temp = 0;
 
 while(1)
 { 
  temp = PIND;
 
  if(temp == 1)
  { 
   PORTB = 1 ;
   delay(5000) ;
   PORTB = 2;
   delay(5000) ;
 
   PORTB = 4;
   delay(5000) ; 
 
   PORTB = 8 ;
   delay(5000) ;
  }
 
  else if (temp == 2)
  {
 
   PORTB = 8 ;
   delay(5000) ;
   PORTB = 4;
   delay(5000) ;
 
   PORTB = 2;
   delay(5000) ; 
 
   PORTB = 1 ;
   delay(5000) ;
 
  } 
  else
  {
   PORTB = 0;
  }
 
 }
 

}
Please excuse my sloppy code :p
 

hgmjr

Joined Jan 28, 2005
9,029
What is the part number of the stepper motor you are using so that I can access the data sheet for the details?

hgmjr
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
its by Minbea electronics...

PM20s-020-NBA1

LOT NO. TC3701A ( whatever that is )

the problem isn't in interfacing with the motor, cause I tried running the " forward " code and the " backwards" code , and it worked fine, its only when I wanted to control it via an input is where i started getting the problem.... right now I have pin 9 ( RESET ) to HIGH ( since it is active low ) and I have Vcc also connected to PIN 10 , which is PIN 0 of PORTD , which according to the code should rotate the motor in one direction.
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
It seems like I have to reset the AVR if i want it to update the input.... ? kinda wierd :S
 

hgmjr

Joined Jan 28, 2005
9,029
Ok.

I was able to find the datasheet and you appear to have a unipolar stepper motor with 18 degrees per step. I think you have made a good first choice of a stepper motor to use for the purpose of learning more about operating one.

I will review your code to see if I can spot any bugs that need to be worked on.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,029
What you can try is masking the byte value you read from PORTD.

You have a statement temp = PIND.

Since all you are interested in is the least significant bit, mask the value something like the statement

temp = (PIND & 0x01);
Then you will need to change the "if" statements to look for a "1" or a "0" as the value for temp.

Does that make sense?

It appears that you have chosen to start with "full" stepping the motor. That is probably a good start. Later you can investigate "half" stepping.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,029
If I read your code correctly, depending on the length of time the statement "delay(5000)" is providing, you may want to break the delay up into two parts. The first delay would establish the length of time the stepper motor coil was energized after which you would de-energize the coil and then use a second delay statement to establish how long the motor pauses before energizing the next coil in the sequence.

This will have a direct impact on reducing how much power is consumed with each motor step.

Of course the drawback to denergizing the coil is that the only thing holding the motor at its present position is the "detent" torque which can be somewhat weak compared to the "holding" torque developed during the time the coil is energized.

You have got to be having too much fun by now.

hgmjr
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
I figured out the problem..

The problem was that I left the other pins of the port FLOATING (big mistake).. I fixed the problem by grounding everything else, and only have Vcc run to pin 1 for clockwise, and pin 2 for Anti-clockwise..

Now the next question is as follows :

If i wanted to use momentary switches to drive pins 1 and 2, (ie: Vcc to pin one when pushed, ground if not ), do i need to hook it up as follows ?

PIN1
|
Vcc ----RESISTOR -------
|
|
\
\
|
|
_____ Ground


This is the only way which i could think of to connect it, but when I push the switch, i'll be draining current unneccesarily... (btw, is this resistor called a pull-up resistor ?and if so , why is it called "pull-up" ? )

any better suggestions?
 

Thread Starter

Mazaag

Joined Oct 23, 2004
255
lol i just realized how crap the diagram turned out

the VCC is suppose to be further to the left, and the node to the right of the resistor is connected to the pin and to one side of the switch...


(another aside question, when using an external crysal/resonator, are capacitors required ? how do crystals/resonators work anyway ? )

in your previous post on the motor.... I didn't undersatnd much of what you said :S (half stepping and holding torque etc..), is there a good website or something which i could read on steppers ?

Thanks alot for your help.. and YES I AM HAVING A BLAST :D
 

nanovate

Joined May 7, 2007
665
The problem was that I left the other pins of the port FLOATING
You can enable internal pull-ups also to set them at a defined state.

Vcc to pin one when pushed, ground if not
I could not figure out your diagram for the switch interface. But a pull-up resistor "pulls" the input line to VCC. But you are describing a "pull-down". So it goes from the input line to GND and the switch goes from the input line to VCC (I assume NO-type switch). I'd also put a small resistor in series with the input pins just in case you accidently configure the pin as an output.
 

nanovate

Joined May 7, 2007
665
You need capacitors when connecting an external crystal above 32 kHz. I believe the datasheet has some recommendations.
 
Top