Author Topic: Arduino  (Read 13410 times)

0 Members and 1 Guest are viewing this topic.

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: Arduino
« Reply #25 on: July 17, 2014, 05:42:03 pm »

getting further off topic, but just because one processor only can write on what the other processor can read it doesn't mean they can't maintain a count.
In that case you will need an interprocessor communications mechanism to implement a semaphore which would make semaphores unnecessary. As I said in the beginning your description wasn't really a semaphore.

I've been writing operating systems since 1993, and for about 15 of those years I was doing it professionally. I'm not mentioning this to try to "prove" I'm right by some appeal to authority, it's just that I've implemented a few semaphore primitives in my time and never before have I heard or seen your locking scheme described as a semaphore. I'm actually interested to see the source of such a system if you had it available.
The semaphore is the interprocess communication.

Before mutexes and locks they all were referred as semaphores before, then the industry came with the term mutex to describe a binary semaphore.

At work now but maybe I'll draw some diagrams on how both counting and binary semaphores can be achieved with share memory. What else could you use anyways?

as for your other point about concurrency, the only difference between concurrent and parallel is that concurrent is independent of other processes and parallel might be dependent on other processes.

One is about dealing with events at the same time the other is about processing tasks at the same time. But Richard never said one was the other
Quote
Yes, and no. NO single-coreprocessor can ACTUALLY run concurrent threads. However,they CAN keep track of manythreads and switch between them so fast that to us"slow" humans, they APPEAR to be doing multiplethings concurrently.

Erlang for example is concurrent, and it has no problem running on a single core.
« Last Edit: July 17, 2014, 05:44:06 pm by miguelvp »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Arduino
« Reply #26 on: July 17, 2014, 05:51:00 pm »
... when you start communicating with others, especially beginners, it starts to be a problem.

I think this thread is any way above beginners heads.  :)

The right answer is yes, an Arduino can do multiple things at the same time (e.g. blinking leds, operating a stepper motor and writing to serial port), just the same as one can take three university classes at the same time or participate in multiple chat threads at the same time.
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: Arduino
« Reply #27 on: July 17, 2014, 06:12:07 pm »
The semaphore is the interprocess communication.
Then you're doing it wrong. As I mentioned earlier a semaphore is about cooperation not communication. You can build interprocess communication mechanisms on top of a semaphore but a semaphore is not an interprocess communication mechanism. The only communication is between the processes and the common data structures (a counter and possibly a priority queue for blocked processes which is usually in the kernel). The cooperating processes do not communicate with each other via the P and V interface functions. They may use P and V to enable communication.

Before mutexes and locks they all were referred as semaphores before, then the industry came with the term mutex to describe a binary semaphore.
I know, I gave you a link to the PDF that introduced the semaphore to the world.

At work now but maybe I'll draw some diagrams on how both counting and binary semaphores can be achieved with share memory. What else could you use anyways?
You maybe misunderstood me. I'm looking for an implementation not diagrams. I would rather see you provide an implementation that is constrained by the description you gave earlier. I've never claimed it was not possible with shared memory. I'm just saying your private memory mechanism isn't a semaphore unless you add counters and, it now seems, an interprocess communication mechanism.

as for your other point about concurrency, the only difference between concurrent and parallel is that concurrent is independent of other processes and parallel might be dependent on other processes.

One is about dealing with events at the same time the other is about processing tasks at the same time.
No that's not correct.  Events have nothing to do with it.

But Richard never said one was the other
Quote
Yes, and no. NO single-coreprocessor can ACTUALLY run concurrent threads. However,they CAN keep track of manythreads and switch between them so fast that to us"slow" humans, they APPEAR to be doing multiplethings concurrently.

Erlang for example is concurrent, and it has no problem running on a single core.'
I really am not going to say any more on this as I feel like I'm going round in circles. Please look up the term using several sources.
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: Arduino
« Reply #28 on: July 17, 2014, 06:57:08 pm »
I come from an unix background so:
http://tldp.org/LDP/lpg/node7.html

But I agree with zapta, this is way beyond what the OP asked and more for academics.

BTW what Operating Systems did you write? just curious.
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: Arduino
« Reply #29 on: July 17, 2014, 07:15:51 pm »
I come from an unix background so:
http://tldp.org/LDP/lpg/node7.html
Fair enough, they call it a communications primitive but I, as you may have noticed by now, disagree! I think they've just lumped everything together.

But I agree with zapta, this is way beyond what the OP asked and more for academics.
Yeah but you've probably thought more about these things in the last 24 hours than you have in the last year. Getting these things put down into words helps solidify understanding. That's not such a bad thing.

BTW what Operating Systems did you write? just curious.
I've worked mainly in the telecoms field. I've worked on operating systems for telecoms infrastructure products used in fixed line, GSM, and LTE. (switches, base stations, network controllers etc.). I've also worked on the terminal side writing device drivers for Symbian smartphones. Obviously these are closed systems but I once wrote a little booklet/tutorial on hard real-time kernels where I develop a simple kernel. You can download the pdf (http://barrywatson.se/download/Everyman.pdf) and the code (http://barrywatson.se/download/Everyman.tar.gz). It's a quick read and feedback is appreciated.
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: Arduino
« Reply #30 on: July 17, 2014, 07:35:10 pm »
BTW what Operating Systems did you write? just curious.
I've worked mainly in the telecoms field. I've worked on operating systems for telecoms infrastructure products used in fixed line, GSM, and LTE. (switches, base stations, network controllers etc.). I've also worked on the terminal side writing device drivers for Symbian smartphones. Obviously these are closed systems but I once wrote a little booklet/tutorial on hard real-time kernels where I develop a simple kernel. You can download the pdf (http://barrywatson.se/download/Everyman.pdf) and the code (http://barrywatson.se/download/Everyman.tar.gz). It's a quick read and feedback is appreciated.

I once though about doing that but they been closing down so many over the last decade that I'm glad I did not go to that field, and today M$ got rid of most Nokia employees it seems.

Edit: 1,100 of them from your neighbors in Finland.

I'll take a look later after work.

« Last Edit: July 17, 2014, 07:41:26 pm by miguelvp »
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: Arduino
« Reply #31 on: July 17, 2014, 07:42:36 pm »
The telecoms infrastructure field is a great place to work if you like building solid systems. The terminal side (telephones etc.) is horrible as the number one priority is get it delivered for the Christmas market and worry about quality later.
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Arduino
« Reply #32 on: July 17, 2014, 09:30:54 pm »
... a semaphore is about cooperation not communication. You can build interprocess communication mechanisms on top of a semaphore but a semaphore is not an interprocess communication mechanism.

To paraphrase a great man, it depends on the meaning of the word 'communication'. If 'I just grabbed this resource so don't use it until I will tell you I am done",  or "I just inserted 7 items to this queue so you can process them" is not communication than you are right.  ;-)
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: Arduino
« Reply #33 on: July 18, 2014, 06:04:00 am »
Before mutexes and locks they all were referred as semaphores before, then the industry came with the term mutex to describe a binary semaphore.
I know, I gave you a link to the PDF that introduced the semaphore to the world.
Looking at the Dijkstra paper again. He uses the term mutex in the appendix so the term is as old as semaphore itself in this context. That was news to me.

... a semaphore is about cooperation not communication. You can build interprocess communication mechanisms on top of a semaphore but a semaphore is not an interprocess communication mechanism.

To paraphrase a great man, it depends on the meaning of the word 'communication'. If 'I just grabbed this resource so don't use it until I will tell you I am done",  or "I just inserted 7 items to this queue so you can process them" is not communication than you are right.  ;-)
No, this is all about the scheduling of operations not communication. The semaphore enables communication, it is not the communication itself. There are three types of concurrency primitives we see in programming languages [Reppy]
  • A mechanism for introducing independent sequential threads of control, called processes.
  • A mechanism for processes to communicate. Communication involves the exchanging data, either through shared memory locations or by explicit message passing.
  • A mechanism for processes to synchronize. Synchronization restricts the ordering of execution in otherwise independent threads, and is used to limit the program's nondeterminism where necessary.

To quote the inventor of the semaphore [Dijkstra]
Quote
Explicit mutual synchronization of parallel sequential processes is implemented via so called "semaphores"

I really can't see me calling a semaphore a communication primitive so I'll say no more. Feel free to continue calling it what you wish.

[Dijkstra] Dijkstra, E. W. http://www.cs.virginia.edu/~zaher/classes/CS656/p341-dijkstra.pdf
[Reppy] Reppy, John H., Concurrent Programming in ML, Cambridge, 1999.
« Last Edit: July 18, 2014, 06:14:14 am by bwat »
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Online Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Arduino
« Reply #34 on: July 19, 2014, 04:31:19 am »
I think the OP is confused by marketing (that you need more core to do more things)...  One does not need multi-core for the machine to multi-tasks. 

Concurrency does not start with multicore or even hyperthread.  Pre-hyperthread late Pentiums has multiple instruction pipelines and multiple instruction decoders.  So, multiple things are going on within the same clock-cycle and within the lone core.  Mean time, time-slicing and time-sharing was nearly as old as the first computer.

If I may inject a reminder as a segway back to the OP's question.

The Arduino UNO is a dual processor board.  The ATMEGA16U2, and the ATMEGA328.  The 16U2 subsystem handles communication and other board-management tasks at the same time while 328 handles the user-written logic. 

But, these are too esoteric for typical users.  However, it explains why the question "what do you mean by doing things at the same time" matters...

Now to the questions:

Can it run two application at the same time?  No.
Can a single application do multiple tasks at the same time?  Yes

One can view the loop() function as a time-slices, and you can have it call say 4 different things - each one returning gracefully if it has nothing to do or if it completed what it must do.  so the loop() essentially do:

void loop() {
    doTask1();
    doTask2();
    doTask3();
}

**  The tasks are done in sequence, however, the time delta between tasks is so short it can be view as "at the same time" in most cases.  You may view it as cheating, but even multi-core system shares the same memory so they can not really both read the same memory at the same clock cycle.  (or the same USB port, or the same whatever)


This requires each task to come back quickly when it is done, and not sit there and waste time such as a delay(nnnn) blocking everyone else.  This was called "cooperative multi-tasking" by some, and was the cornerstone of early (pre Windows95) Microsoft Windows  and other "Operating Environments".  Many did not call Windows an "Operating System" then since it was on-top of the real OS which was PCDOS or MSDOS).

So, task1 could be running your thermostat, task2 could be running your air-pump for the fish tank and task3 could be a simple clock display.  Key is, they are all integrated into the same single program.

So, you can do multiple tasks as long as you integrate all the tasks into the same program.

Even while Windows was doing cooperative multi-tasking, other systems implemented preemptive multi-tasking.  Notably DoubleDos which partitions the system into two, preemptively take control away from one application and switch over to the other based on time.  So you have one physical machine divided logically into two, each one has a slice of time (time-slicing).

Preemp or not, how ever many cores you got, you merely decreases the percentage of the time one task waits on another - as no doubt at some point, it will hit a piece of hardware inside that is not sharable.  Arduino has one core, so everything is serialized.  With say a two-core arduino, some things still must be serialized (such as the ADC).

The OS (in this case, everything under the loop() call) controls how it time-slices and your lone loop() is your time-slice which is "all the time Arduino management doesn't use".  You can serialize your many tasks you want it to do, giving each a part of your time to do it with, and write it each task with in mind to "cooperate" - others are waiting.    You can do as many tasks as you want within the resource limit.

So, I think that answers your question about "can Arduino do multiple things at the same time" and explained a bit why others are kick the question back with "what do you mean..."
« Last Edit: July 19, 2014, 04:35:19 am by Rick Law »
 

Offline Skimask

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Arduino
« Reply #35 on: July 19, 2014, 04:33:00 am »
I don't think the O/P cares anymore!  :-DD
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: Arduino
« Reply #36 on: July 19, 2014, 07:54:11 am »
If I may inject a reminder as a segway back to the OP's question.

The Arduino UNO is a dual processor board.  The ATMEGA16U2, and the ATMEGA328.  The 16U2 subsystem handles communication and other board-management tasks at the same time while 328 handles the user-written logic. 
The ATMEGA16U2 is a dedicated microcontroller used as an I/O chip according to http://arduino.cc/en/Main/ArduinoBoardUno. It could be replaced with a nonprogrammable digital circuit and it would not make a difference to the programmer. Your calling the Arduino UNO a "dual processor board" is no different to saying that a desktop PC with a single core CPU is a multiprocessor machine because it has microcontrollers in the keyboard, the harddisk controller, and the monitor. The term uniprocessor meant that the board has one general purpose CPU that can run a user program. If anybody can get the Arduinos's ATMEGA16U2 to run user defined code they should let me know so I can correct my statement.

Edit: Just seen that you can program the ATMEGA16U2 via the DFU bootloader. It looks like the bus between them would be TXD and RXD pins. So you could call it a multiprocessor machine if you replaced its firmware.
« Last Edit: July 19, 2014, 08:06:58 am by bwat »
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Online Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Arduino
« Reply #37 on: July 19, 2014, 09:37:43 am »
If I may inject a reminder as a segway back to the OP's question.

The Arduino UNO is a dual processor board.  The ATMEGA16U2, and the ATMEGA328.  The 16U2 subsystem handles communication and other board-management tasks at the same time while 328 handles the user-written logic. 
The ATMEGA16U2 is a dedicated microcontroller used as an I/O chip according to http://arduino.cc/en/Main/ArduinoBoardUno. It could be replaced with a nonprogrammable digital circuit and it would not make a difference to the programmer. Your calling the Arduino UNO a "dual processor board" is no different to saying that a desktop PC with a single core CPU is a multiprocessor machine because it has microcontrollers in the keyboard, the harddisk controller, and the monitor. The term uniprocessor meant that the board has one general purpose CPU that can run a user program. If anybody can get the Arduinos's ATMEGA16U2 to run user defined code they should let me know so I can correct my statement.

Edit: Just seen that you can program the ATMEGA16U2 via the DFU bootloader. It looks like the bus between them would be TXD and RXD pins. So you could call it a multiprocessor machine if you replaced its firmware.

re: "our calling the Arduino UNO a "dual processor board" is no different to saying that a desktop PC with a single core CPU is a multiprocessor machine "

Indeed all my PC's were multi-processor machines.
- My single core 486 PC was a multi-processor machine.  It has a 80486 CPU, an 80487 FPU, a GPU, another CPU managing the SCSI...
- My PC Limited (renamed to Dell) 286 PC had an 80287 FPU, an ATI GPU...
- My Atari 800 (6502) had a separate processor for graphics with "collision detection" (to detect game images colliding indicating a hit).
- My SOL20 (Z80, I think) had another processor doing the 650K "hard sector" Micropolis floppy...  Could be 8080, but too long ago, I forgot.

Even a lowly SD card has it's own build-in processor to do the memory management...  So add another processor to the count.

The "UNO being dual processor" was to make the to the OP that multi-tasking has nothing to do with whatever CPU you are running.  The CPU, however many cores, is not the world.  There is a lot more to a machine than the cores - and - however lowly the machine, there is always something going on in parallel.  Even my 8086/8088 (HP200 with TimesTech upgrade to CPU speed and Ram) was quite happy doing multi-tasking with DoubleDOS.

Multi-tasking is not dependent on multi-threading or multi-cores or multi-processors SMP machines.  It just depends on how the OS and the apps are written.  To think of multi-tasking requiring multi-processors or multi-core or as a pure CPU function is just way way way outdated thinking back when analog computers were the only game in town.

Rick
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: Arduino
« Reply #38 on: July 19, 2014, 10:01:07 am »

There is a lot more to a machine than the cores - and - however lowly the machine, there is always something going on in parallel.  Even my 8086/8088 (HP200 with TimesTech upgrade to CPU speed and Ram) was quite happy doing multi-tasking with DoubleDOS.
Your 8086/8088's multitasking had nothing to do with things going on in parallel, at least not at the level of instruction parallelism and above.

To think of multi-tasking requiring multi-processors or multi-core or as a pure CPU function is just way way way outdated thinking back when analog computers were the only game in town.
Nowhere in the thread has anybody made the claim that that multitasking requires more than one CPU.
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Online Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Arduino
« Reply #39 on: July 19, 2014, 10:33:11 pm »

There is a lot more to a machine than the cores - and - however lowly the machine, there is always something going on in parallel.  Even my 8086/8088 (HP200 with TimesTech upgrade to CPU speed and Ram) was quite happy doing multi-tasking with DoubleDOS.
Your 8086/8088's multitasking had nothing to do with things going on in parallel, at least not at the level of instruction parallelism and above.

To think of multi-tasking requiring multi-processors or multi-core or as a pure CPU function is just way way way outdated thinking back when analog computers were the only game in town.
Nowhere in the thread has anybody made the claim that that multitasking requires more than one CPU.

re: Nowhere in the thread has anybody made the claim that that multitasking requires more than one CPU.

I infer from the OP's question "can you make the arduino do multiple things at the same time" that he/she is concerned about the ability of the MCU to do multitasking.  I therefore want to share with him that even something a lot slower can do multitasking and that multitasking is not "made possible only by something special" in the hardware such as multi-thread/multi-core/multi-processor.  Something as slow (by today's standard) a PDP8 or a lone 8080 can multitask just fine.

I think the OP is just getting started.  It is good for him/her to know that this whole "do more than one thing" really depends on what he means by that statement, and that if he learns to maximize what is there smartly, he can do a lot with what he got.
 

Offline gxti

  • Frequent Contributor
  • **
  • Posts: 507
  • Country: us
Re: Arduino
« Reply #40 on: July 20, 2014, 01:52:50 am »
OP did a hit-and-run. Post a vague and unanswerable question and watch in glee as dozens of speculative responses pile up.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Arduino
« Reply #41 on: July 20, 2014, 04:27:39 am »
OP did a hit-and-run. Post a vague and unanswerable question and watch in glee as dozens of speculative responses pile up.

We the suckers :)

Actually it clarified to me the difference between concurrency and parallelism (check the Rob Pike's video).
 

Online Rick Law

  • Super Contributor
  • ***
  • Posts: 3442
  • Country: us
Re: Arduino
« Reply #42 on: July 20, 2014, 04:35:25 am »
OP did a hit-and-run. Post a vague and unanswerable question and watch in glee as dozens of speculative responses pile up.

We the suckers :)

Actually it clarified to me the difference between concurrency and parallelism (check the Rob Pike's video).

Naaa...  Look at the bright side, we did more idea exchange and we learned more from each other; or at the very least, blew some steam by arguing with each other.

The one thing I appreciate from reading this forum is the vast spectrum of experience and knowledge this forum's participants shown.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf