ATMega128 Number Display Assembly Project

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

I intend to simulate a coffee dispenser with a maximum capacity of 9 capsules.

The act of placing or removing capsules are controlled by the 5th and 6th buttons (SW5 and SW6).

When the maximum capacity is reached, the VE valve (D8) is activated, that blocks the entrance of more capsules, and it will only open again when the tank's capacity is below 30% of the maximum value intended.

The maximum capacity can be either 4, 6, or 9 capsules.

The selection of the maximum capsule quantity is made by activating the respective switch (SW4, SW6, SW9).

There's also a display (the further right one) which indicates the number of existing capsules in the deposit.

To determine the 4th, 6th, and 9th switches values, there must be done, for each switch, two readings that have a delay of 1.5 ms relatively to each other and both must have the same logic value so there is a valid reading.

Can anyone help me with this project, or provide information on how to solve this?

This topic has a solution.
Last Edited: Sat. Oct 13, 2018 - 07:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do not expect people to do your home work for you.

what have you done sofar ?

start with making a flow chart / state diagram of what action should get what reaction.

Break that up in ever smaller parts and when at a sufficient low level ( you will see were that is) you will be able to write things in pseudo code format.

All you then have to do is convert that code to actual code.

 

when I personally start coding, I always try to get a debug output available. That being an LCD, or the uart, or sometimes a simple LED depending on the project and what interfaces I have available for it.

In your case, perhaps best is to get the LCD up and running and use that for displaying debug information when you get into problems.

Note that I asume you do not have an ICE available else, that might also be an interesting route to take ( I do not have one)

 

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

Let me guess, this is a school project? You haven't told us much about what hardware you're using or how you intend to program the code. Or do you want us to do your homework for you?

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

I am not really looking for anyone to do it for me. I just dont understand how to even start coding this project. I have only learnt assembly for 2 weeks now. I tried doing the state diagram and I guess it is kinda right but my problem is passing this to code. It looks overwhelming when all I have done is coding a led sequence for example.

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

I am using am ATMega128, like the tag specifies it. As I said in the other comment I am not looking for someone to give me the code simply, IM asking for help in something I barely Know and can't understand by simply reading

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

Well all software design whether it be Asm or C or C++ or something else should start in the same place - some kind of flow diagram, state transition chart or similar which says. "It starts in this state", "I expect this, this or this to happen" (perhaps button presses, perhaps something else?), "As a result I now get to here". "While I'm here, this or that could happen", "That gets me to here or here". 

 

When you have the sequence of operation (which, with enough detail might also act as the user manual for the end user!) then you have a plan. It's then just a case of how you recognise the input events (buttons, sensors, water levels, voltage readings, whatever) and how you then use that information to move to the next place. Obviously somewhere in your particular design you are going to have to have some kind of sensing as to exactly many capsules you have seen or that you can detect.

 

Also consider how you are going to handle things if this is turned off at the wall. At next turn on can you still sense how many capsules are there? If not then you need to store away the count as it goes up/down so that if power is interrupted you can resume from where you last left off (EEPROM is possibly a good place to hold this kind of "non volatile" data such as capsule count)

 

Bottom line: it's all about clear design (it always is).

 

As long as you design clearly then the actual implementation should be trivial.

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

And how can I learn the "coding language"? For example, I kinda know how to initialize my program and such but there are so many functions besides LDI SBIS SBIC etc.. that I don't even know they exist nor how to implement them.

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

Jonaas18 wrote:
The act of placing or removing capsules are controlled by the 5th and 6th buttons (SW5 and SW6).

Jonaas18 wrote:
The selection of the maximum capsule quantity is made by activating the respective switch (SW4, SW6, SW9).

 

Seems button 6 has two different purposes? 

Or you don't yet have a clear understanding of the problem to be solved.

Spend some time (with your teacher if needed) to clear up what is needed.

The rest of the advise above is very good!  

Come back and ask more questions if you get stuck.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

If you do the design work e.g. flowchart, state diagram, ... we are happy to help with specific questions about writing code.
.
You do not need any fancy CAD software to create your flowchart, ... pencil and paper work fine. Just post a photo of your chart.
.
Your diagrams should be sufficient for anyone to translate into code. If there is a specific area or question, a reader needs to be abe to identify it e.g. numbered steps or arrows.
.
David.

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

Will do. Thanks a lot for the help!

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

Alright, thanks a lot. I already did part of the flowchart but I will try to make it more clear as some people said above!

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

AVR Instruction Set Manual

 

Maybe it's a little too heavy on information for a newbie, but it should contain any information you would need on interesting assembler instructions! laugh

- Brian

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

It's going to be quite tricky to turn a design into an implementation if you don't actually know AVR asm. Before attempting the project itself I'd maybe run a few experiments (simulator will be fine) so see how some of the basic opcodes like LDI, ADD, OR, STS and so on work. You won't be able to turn design into implementation if you don't know what the tools in the box are.

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

Right. One thing I found tricky in past projects was the fact that at home I had to work with the debug system, which I have no idea how to. Sometimes I had no errors on the building part yet the program wouldnt work on the the ATMega128

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

Jonaas18 wrote:
Sometimes I had no errors on the building part yet the program wouldnt work on the the ATMega128

 

That's a normal part of programming, don't sweat it, we all have those problems from time to time.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

Geronimo wrote:

AVR Instruction Set Manual

 

Maybe it's a little too heavy on information for a newbie, but it should contain any information you would need on interesting assembler instructions! laugh

IIRC the AtMega128 does not have all the instructions in that manual, so also have a look at the datasheet, there you will find an overview of what instructions are actually available on your processor.

 

With regard to the non error compilation but not running as expected code.... that is what you would call a bug ;) Your code will for sure be doing something, but not the thing it needs to do or that you expect it to do.

You should be able to see what is happening using either the simulator or a debug interface.

As you are able to blink a LED (at least that is my understanding from what you wrote earlier....) you have a simple debug interface available. So finding out what your code is exactly doing should be a bit time taking, but doable.

 

Have fun in learning, positive side is that when you start with learning assembler, and then switching to C code later on you will have a better feeling of what is going on on the lower level then.

and don't be afraid to ask questions, just do not expect us to do your homework ;) So if you get stuck, first try to find out what is going on your self and when you really get stuck, post your program, with what you expect it to do, what you have observed it actually is doing and how you did that.

 

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

Alright! Should I then start a new post or simply reply to the current one in case I get stuck or have a question?

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

Do you think you would be capable of programming this in any language?  What is your level of programming skill?

 

If, for example, you would be capable of programming this in C, then I might suggest that you program it in C, get it running, then start converting each C statement and function into ASM.  You could even use the same ABI, application binary interface, to have a standard for passing data to and from functions.

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

I would say I'm average at C. I must learn how to work with the ATMega128 in the assembly language before working on it with C language. Besides that, I'm decent on C. In my current "course" I don't learn intensive programming. It's kind of a soft learning in a way that I only know how to program the things I'm required to use. For example, I really don't know what to do if you ask me to do a 1+1 code in Assembly because I literelly haven't learnt anything about it. I'm mainly using it to configure the micro.

 

I'm starting all over again tomorrow. State diagram and such and hopefully it will be easier with the feedback I recieved. Asked my teacher aswell and he advised me to start from the smaller picture to the bigger one, this meaning, starting by simply configuring inputs and outputs and then working all the way up to the extra functionalities.

Last Edited: Thu. Oct 11, 2018 - 11:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jonaas18 wrote:

Asked my teacher aswell and he advised me to start from the smaller picture to the bigger one, this meaning, starting by simply configuring inputs and outputs and then working all the way up to the extra functionalities.

At least a teacher that seems to be helping. First get the "simple things" to work and from that expand. when you know how to configure your IO (suggest looking at "PORT", "PIN" and "DDR" but scroll through the datasheet first to find these as it will also gain you knowledge in how to read and interpret datasheets which also is a very very crucial part of programming embedded) you will be able to do a lot already.

 

 

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

Yes that was really my main point of asking for help. Configuring ports is something I know how to do, aswell as turning leds on or off when a switch is pressed, for example. However, if we are talking about making math and checking if this happens or that happens or etc etc I kinda feel overwhelmed. It just seems way out of my league, but yea. I really do not know if I will be able to finish it but whatever I do is already good.

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

I suggest having a evening read through the AVR instruction set then.

You know how to do it in C code......

if you just read through all the instructions and have a quick look at what they all do, you should be able to find the instructions needed to do so.

Then take a instruction that you think is correct and work from there. with the instructions there is an indication as to what information that instruction needs.

Then go and have a look at instructions that will full fill that need...

That is also why I suggest to first go through the entire instruction set such that you might have ringing bells as to what instructions you need.

 

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

I find the best way to learn the Asm of a new micro is simply to study the opcodes generated for simple sequences of C. Read it alongside the published manual for the opcodes.

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

For experienced programmers the best way to write a program is often to start with plain old pen and paper and figure out exactly what has to be done and how to do it before even starting with writing code.

But when learning all this stuff this is almost impossible because you do not have the background yet to know in which direction to take a design to make it a succes.

There are so many things you have to learn all at the same time:

- ASM instruction.

- How to use asm instructions effectively.

- How to divide a big project into smaller pieces.

- State machines, programming structures.

- How to use the tools.

 

Therefore I agree with the above (Meslopmp #2 and others).

Start with something simple, a sub project that is a piece of the bigger part.

Whenever buttons are involved, debouncing them is an important, but non trivial task.

Just writing an asm program that toggles a led when a button is pressed seems a simple task, but is already a part of your program.

Once you have the button working, you can exchange the led with another part of your coffee machine.

And then you can ad-hoc add functions and tinker with it.

 

But don't only add stuff.

Refactoring is also an important aspect of software development.

Once you gain more experience you will notice that you have done things in a weird way, or that old code does not work well with functions you want to add.

Don't be afraid to re-write the old code to make parts fit together better.

 

When I was learning asm a long time ago I made a cheat sheet. It had all asm instructions on a single sheet of paper with a single line explanation of what the instruction did and side effects.

Making that cheat sheet was a whole day of work, but  I learned a lot from making it.

After that day I had a reasonable understanding of what ASM instructions were available, and the sheet helped with filling in details during software development.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

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

How are you going to simulate placing/removing capsules?

Maybe a report via USART saying "Capsule added. There are x capsules available from a maximum of y."

 

edit: Never mind, there is a display... cheeky What kind of display?

Last Edited: Fri. Oct 12, 2018 - 06:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The display is the 4 digit segment display (I believed it's called that). Basically I have 4 squares in my ATMega128 and each one shows a number. In my project I have to choose the furthest one to the right (already chose it) and then "write" the number there (whatever the number is, depends on the current capsules). I'm currently "forgetting" that at the moment as I'm focusing first on the base of the program. One thing I'm having trouble is where to store the number of capsules. For example, in C you can easily increment a variable (call it "N") and then print the number into the display but I can't seem to find a way to increment a variable in assembly (??). I'm currently thinking about using the INCrement and DECrement functions in a random register (call it R22) and then start from there.

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

To increment a variable, you want some variation of ADD or INC (increment).  The exact instruction will depend on the size of the variable, for one thing.  INC will work for a single register (8-bit variable), but for larger variables (16 or 32 bits) you need add and carry.  Or you can use the nice ADIW to add from 0 to 63 to a register pair (16 bits).

 

This is where it helps to write simple code in C and look what the compiler generates.

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

Ok, so one of the things you will have to do for sure is a function to display the numbers 0-9 in the segment display. Do you have a datasheet or at least a pinout for the display?

You will need to create a character set for the display, this is not difficult.

The details of how to create and handle asm variables depends on the exact tools you are using, so please tell us. In general, you will use a data section to reserve parts of the RAM for your variables, and access them via asm labels.

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

I managed to do a decent ammount of code with all your feedback. I decided to create a new post so I can focus in the subject with more detail. I also added some screenshots and such. 

 

Here

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nothing to do with Studio issues or bugs, moving to AVR forum. I will also lock this thread as you have another running.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Topic locked