Program avr microcontroller to have 3V on one output pin

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I am not very experienced with avr microcontrollers but I need to code the following program for ATmega328 microcontroller:

When I press the 1st pushbutton, i would like to have 3V on the output pin 1.
And when I press the 2nd push button, I would like to have 3V on the output of the 2nd pin. 
How could I code something like that with my microcontroller ? And which components do I need to add for that ( which component  should I use to amplify the output voltage when the pushbutton is pressed)?

What is the voltage at the output pin of those micro controllers generally?

 

Thank you

Amigo Alex

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the voltage at the output pin of those micro controllers generally?

Whatever VCC is, ie 5V, 3.3V or other.  The M328 can work from 1.8V - 5.5V.
 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In theory, you could use PWM and a low-pass filter, but I'm with JS on this - Just use as Vcc the voltage you need on the pin.  Or get an Xmega what has a DAC built in.

 

For amplifying voltage you need a) higher voltage rails to start with and b) an 'operational amplifier', also known as an 'op amp'.  Incidentally you could use one of those to make 3V outputs on a 5V Vcc AVR too, if you wanted to.  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suspect that Amigo2 wants something like

repeat
    set output_1 to zero
    set output_2 to zero
    if ( button_1_pressed ) then set output_1 to one
    if ( button_2_pressed ) then set output_2 to one
until some_condition occurs

 

However, there are questions ;

- what does the 3 (or 5) volts on the output actually do ? Does it control a motor, a lamp, a solenoid, ... ??

- which programming language is to be used ?  (C, ASM, ... )

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Amigo2 wrote:
I am not very experienced with avr microcontrollers

This is not specific to AVR microcontrollers: the behaviour is the same for any and all microcontrollers and microprocessors - and, in fact, for any digital output in general.

 

Digital outputs take only one of two[1] possible states: they are either "high" or "low" - for convenience, often referred to as 1 and 0.

 

As js said, "high" will generally be at the supply voltage level, and "low" will be at the "ground" level.

 

You will find these specified in datasheets as

  • VOH - for Output High Voltage, and
  • VOL - for Output Low Voltage.

 

 

[1] Some outputs have a third state, in which they are just OFF - hence often called "tri-state"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

On the general topic of reading switches from a microcontroller, clawson made an excellent explanation recently:

 

http://www.avrfreaks.net/comment...

 

You will also have to pay attention to contanct bounce; ie, provide debouncing.

 

Also some good basic electronics stuff here:  https://electronicsclub.info/ 

 

EDIT

 

And some general beginner's "Getting Started" tips for working with microcontrollers: http://www.avrfreaks.net/comment/2079906#comment-2079906

 

And, specifically: http://www.avrfreaks.net/comment/1138166#comment-1138166

 

Last Edited: Tue. Nov 7, 2017 - 08:41 AM