Sonsivri

Electronics => AVR, 8051 Family and ARM Area => Topic started by: nanocycle on March 30, 2009, 11:13:38 11:13



Title: How to write this program?
Post by: nanocycle on March 30, 2009, 11:13:38 11:13
Hi everybody,

Suppose that we have a AVR micocontroller and some inputs and outputs (digital and analog and serial) as picture.We have a process and micro is checking all inputs and outputs and answering to all of them.
The question is this.I want to write value in EEPROM of micro by pressing Set button and increasing and decreasing value by up and down buttons Withou disordering the rest of process of micro.In fact micro is doing it's process but also gives us capability for writing value in EEPROM.(Similar to parallel processing).
Also i don't want to use another micro.
How is it possible?

(http://i39.tinypic.com/2dvonth.jpg)

Regards,
 


Title: Re: How to write this program?
Post by: alberto110 on March 30, 2009, 03:34:20 15:34
the micro has only on core (cpu ) and can do one thing at a specific of time . you can write a program that check inputs write to outputs and answer
to buttons ( consequently increasing and decreasing value ) . the micro run your program very fast and it seems all  functions runing parallel .
surly when cpu checking switches can't read from digital inputs . but if cpu is much faster than the inputs ( like switches ) you will not have any problem .
for very fast inputs , you should use interrupt . also include timers into your project for timing .

best regard


Title: Re: How to write this program?
Post by: pablo2048 on March 30, 2009, 07:06:28 19:06
If You have free timer try to write simple periodic interrupt handler. In this handler You can do what You need...


Title: Re: How to write this program?
Post by: metal on March 30, 2009, 08:11:22 20:11
Why do you want to do that? What do you mean by disorder here? What are those processes being read and output so important that prevents you using an interrupt to handle another task, buttons, etc... Even intel processor slices processing time among different processes, it also uses interrupts to handle the mouce...

As long as you have a single CPU/core, you will never have parallel processing... When you say "disorder" it means that your program is being executed by diffrerent CPUs/cores such that tasks/threads don NOT interfer with each other, which is another story... or that you don not understand how the interrupt is working... Interrupts don not disorder program execution, they redirect it somewhere else that you specify, and then return back to the next instruction that was supposed to be executed if there was no interrupt...

First of all, you should have read resources about handling buttons.. Your diagram implies that you have no idea... You might have found a readily available routine somewhere... or you are still a beginner...

Now introduce to other members what exactly on your mind buddy.. so they can help you further... forget the term "parallel processing" for one AVR chip  :-*

You might want to disable the interrupts when you read/output data, this is a wise thing to do inorder not to miss your data, but don not disable them for a long time, then you will miss button pressing events.


Title: Re: How to write this program?
Post by: samir on March 31, 2009, 04:01:00 04:01
if all above suggestion won't work then you need processor with more than one core like Freescale's XGATE,so you can have two process running parallel.


Title: Re: How to write this program?
Post by: nanocycle on April 05, 2009, 09:37:31 09:37
Thanks my friends.Very good points and useful information.
Now if i want to use another micro,which type of connection is good?
SPI is good?
is it possible that two micro communicate by I2C?

regards,
Alireza


Title: Re: How to write this program?
Post by: oldvan on April 05, 2009, 06:25:04 18:25
SPI or I2C would be good if the processors are close together. 
One-Wire can move data with minimum pin count.

For greater distances you could use RS232, CAN, or even
something of your own creation.


Title: Re: How to write this program?
Post by: flyback on April 07, 2009, 08:02:59 20:02
Please note that you already take MISO, MOSI, CLK pins to read switches, so you no longer can use SPI communication. Or you may modify your schematic. :)


Title: Re: How to write this program?
Post by: ali_asadzadeh on April 14, 2009, 07:44:19 07:44
maybe you can solve the problem by using a RTOS!
there are several free ones out there.use www.freertos.org it's free and have good stability.


Title: Re: How to write this program?
Post by: LabBoy on May 08, 2009, 02:52:04 02:52
The real-time processing is necessary for your work. You can use a timer interrupt to construct the software timers and use them for manage the operation timing. This technique was called "The Software Timer". With this solution you will get the Multitasking Real-Time processing style without using any RTOS like FreeRTOS or uC-OS.


Title: Re: How to write this program?
Post by: sittichoke on July 06, 2009, 02:07:01 02:07
between process will have gap time, it's enough for write EEPROM, by do not interrupt main process
try to measure time of each process, you will found the gap time


Title: Re: How to write this program?
Post by: Mega32 on July 07, 2009, 06:39:09 18:39
Just start en eeprom write , and poll for the write completion in the "main loop".

Or check for completion in a timer interrupt.

Writing eeprom on a M32 is quite slow , so dont loop around the write completion.

You don't need multicores or anything like it , the M32 will do this fine.

Do take note of flyback's comment and move the buttons away from MISO/MOSI/SCK , they are used for SPI and for ISP programming. Watch out for using SS for digital input , if you want to use SPI.

You could move them to the free pins of PORTC .
Remember to disable JTAG (fuse setting) , if you use PORTC.
 
Remember to power AVCC and decouple both VCC & AVCC with 100nF to GND.

If you want to use RS232 , don't rely on the internal oscillator it is too unstable , use an XTAL or oscillator.


Mega32