Hooking up AVR

Discussion in 'Embedded Systems and Microcontrollers' started by Mazaag, Aug 21, 2007.

  1. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    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
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  4. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    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..
     
  5. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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.

    You should be able to power an led from an AVR output with the proper series current limiting resistor.
    The STK is introducing the inversion you are encountering. The AVR output is not inverted.
    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
     
  6. Mazaag

    Thread Starter Senior Member

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

    Thread Starter Senior Member

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


    Thanks
     
  8. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  9. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  10. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    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 .. )


    Code ( (Unknown Language)):
    1.  
    2. #include <avr/modifiedio.h>
    3.  
    4. int main(void)
    5. {
    6. DDRB = 0xFF;
    7. DDRD = 0;
    8. int temp = 0;
    9.  
    10.  while(1)
    11.  {
    12.   temp = PIND;
    13.  
    14.   if(temp == 1)
    15.   {
    16.    PORTB = 1 ;
    17.    delay(5000) ;
    18.    PORTB = 2;
    19.    delay(5000) ;
    20.  
    21.    PORTB = 4;
    22.    delay(5000) ;
    23.  
    24.    PORTB = 8 ;
    25.    delay(5000) ;
    26.   }
    27.  
    28.   else if (temp == 2)
    29.   {
    30.  
    31.    PORTB = 8 ;
    32.    delay(5000) ;
    33.    PORTB = 4;
    34.    delay(5000) ;
    35.  
    36.    PORTB = 2;
    37.    delay(5000) ;
    38.  
    39.    PORTB = 1 ;
    40.    delay(5000) ;
    41.  
    42.   }
    43.   else
    44.   {
    45.    PORTB = 0;
    46.   }
    47.  
    48.  }
    49.  
    50.  
    51. }
    52.  
    53.  
    Please excuse my sloppy code :p
     
  11. hgmjr

    Moderator

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

    hgmjr
     
  12. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    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.
     
  13. Mazaag

    Thread Starter Senior Member

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

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  15. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  16. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  17. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    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?
     
  18. Mazaag

    Thread Starter Senior Member

    Oct 23, 2004
    255
    0
    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
     
  19. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    You can enable internal pull-ups also to set them at a defined state.

    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.
     
  20. nanovate

    Distinguished Member

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