7 Segment up/down counter with preset value

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

How to write program for 7 Segment up/down counter with preset value using push buttons.

sushant

Last Edited: Mon. Jan 15, 2018 - 11:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Homework?

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

No I am new to AVR. Learning basics. I completed interfacing 7 segment display with atmega32 and up /down counter. But I don't understand how to give input by preset value and control the output...!!!

sushant

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

sushantsm3 wrote:
No I am new to AVR. Learning basics.

Simply asking people to solve your problems for you isn't a great way to learn how to solve problems yourself!

 

But I don't understand how to give input by preset value and control the output...!!!

The first thing to do is to come up with a clear description of what you want to do.

 

Don't worry about how to achieve it before you have a clear idea of what you want to achieve!

 

Probably the most common beginner's mistake is to simply jump straight in to typing  code into an editor (ie, concentrating on the how) without a clear idea of the what.

 

Your first step on this road is to break down the problem into mageable parts; 

 

eg,

  • What do you mean by "provide input" - a set of buttons? a link to a computer? thumbwheel switches? etc, etc, ...

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An example on the issue of 'what'...

 

How many buttons? You could use just one; it would not be fun to use but it can be done. Or you could use two per digit; very easy to code and very easy to use but expensive on buttons.

"This forum helps those that help themselves."

"How have you proved that your chip is running at xxMHz?" - Me

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

This is also a counter?  What will you be counting, how fast (milliseconds, microseconds, hours), how many digits, etc?  You need to provide many more details.  Should the preset button(s) just load in a number to count down from? Say, push button A , loads counter with 1234 and counts input pulses down from there?

 

I completed interfacing 7 segment display with atmega32 and up /down counter

What do you mean?  Hopefully the counter IS the mega32 & not some other chips. 

When in the dark remember-the future looks brighter than ever.

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

Not sure what you mean by "preset value". I don't think that's an input, I think that'd be part of your code. Like, instead of "start at zero", you would set it to "start at 23" or something. That's the preset value.

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

the_real_seebs wrote:
Not sure what you mean by "preset value".

It's not entirely clear that the OP is even sure of that!

 

Hence the importance of having a clear definition of the what.

 

 

I don't think that's an input, I think that'd be part of your code. Like, instead of "start at zero", you would set it to "start at 23" or something. That's the preset value.

Maybe; maybe not.

 

It could be a value that the use enters; eg, as I suggested, on thumbwheels or DIP switches or suchlike.

 

But it's really up to the OP to define what (s)he wants... 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sushantsm3 wrote:

I completed interfacing 7 segment display with atmega32 and up /down counter.


Post the project here so everybody can take a look and help.

MG

I don't know why I'm still doing this hobby

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

7 Segment up/down counter with preset value using push buttons :

 

There are 4 Seven Segment displays and 
4 push buttons......1= Up Key(UP) , 2= Down Key(DN) , 3 = Function Key (FN),  4 = Set Key(SET).

 

When I press Set key for 5 sec it will go to Enter Mode.

Here , I can insert the preset value from from 0001 to 9999 in seven segment display.

For example : If my preset value is 0025.

Then when I press SET key for 5 sec, it goes into Enter mode. And now I can enter 0-9 in the last display , in this case its 5.
Then using FN key the cursor shifts to next display and now enter 2 then 0 and 0.

 

When I am done with entering my preset value i.e 25 then I press the set key again and the value is stored.

 

Now , an external input is given such as push button, on pressing it the seven segment counter starts from
0000 and when it reaches 0025 it drives an output such as Led is on.

Attachment(s): 

sushant

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

So there you have your "top-level" definition of the what.

 

Now you need to break that down into smaller parts.

 

And keep breaking it down until you reach something that is easy to implement.

 


It sounds like a job for a State Machine (aka "Finite State Machine", FSM, or "Finite State Automaton").

 

For a tutorial on State Machines, see: https://www.avrfreaks.net/comment... - the specific example is parsing GPS data, but the concepts are general.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can break the states into substates, in a hierarchy (perhaps even using multiple state machines, but not necessary).

for example:  operating & editing & update output states

 

Operating could be broken down into  restart, updating count & value reached states

Editing could be broken down into changing 1st digit, changing 2nd digit, etc states

 

Each state will have some things that occur when first entering that state, and possibly when leaving that state (if it is a common occurrence for all exits from that state)..these are things that should be done only once (activate the pump, trigger the alarm)

Each state will have rules for going to the other state(s)

Each state can do things repeatedly while in a state (monitor temperature, read the keypad, update the display)

 

These are just arbitrary examples; you can make you own.   There's many ways to organize and pack your luggage. 

 

 

When in the dark remember-the future looks brighter than ever.

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

All true - but probably a bit advanced for the OP at this point ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...