8 ms·
Pi Zero will never directly replace something like the arduino. Running linux (or any OS) can be a huge liability when you need to talk to some other bit of ha
by simcop2387 11y ago
Pi Zero will never directly replace something like the arduino. Running linux (or any OS) can be a huge liability when you need to talk to some other bit of hardware that has strict timing requirements. That said, things like the ESP8266 and Arm Cortex M* processors are definitely becoming far more attractive than the AVRs in the lower end Arduino products (Due and others are also using ARM).
- mschuster91 11y ago> Running linux (or any OS) can be a huge liability when you need to talk to some other bit of hardware that has strict timing requirements. Not just the timing is critical, also the failure causes (and modes) are far bigger in number when running an OS. E.g. if you properly code in C or ASM for a microcontroller and avoid things like recursion, it's very hard to crash due to OOM errors.
- marcosdumay 11y agoTo be fair, a 8MHz (16MHz?) CPU is also a huge liability when you have strict timing requirements. For almost anything, the Pi will probably give you better guarantees by sheer speed... and you can always compile the kernel with a real-time patch. Not saying running on the bare metal is worthless, but an Arduino is a really low end board.
- joshvm 11y agoI think that's confusing liability with speed. Running interrupt-free code on an ARM or AVR is incredibly reliable. I would argue much more reliable than going to the length of patching the kernel. Just because it's slow doesn't mean you can't predict what's going to happen, they're two separate issues.
- Sanddancer 11y agoYes, but even with rt-linux, you've got a jitter of potentially several dozen microseconds, and each interrupt routine will vary. With an AVR, your delay is 4 clock cycles every time, which comes out to .2 microseconds at 20 Mhz. This is the kind of guarantee you can get with being on an intimate level with the chip which you can't get with any OS.
- deleted 11y ago[deleted]
- eru 11y agoAt least not any OS that's not geared for realtime from the ground up.
- tremon 11y agoIt's not just about the OS, it's about the platform (hardware). Even with a fully-optimized RTOS on a standard PC platform, you might run into millisecond-latency due to non-maskable interrupts, cache misses or bus contention (DMA bus-mastering kills any real-time guarantees). That's not even considering the stalls introduced by SMM or TPM instructions.
- jevinskie 11y agoI would think it would be difficult to achieve the low jitter of a simple, fixed # of cycles / instruction, architecture like AVR in a superscalar, cached, speculative architecture like modern X86 CPUs. A hard RTOS is necessary, but perhaps not sufficient with most X86 microarchs. Maybe you can disable some of that dynamic behavior via MSRs but probably not all.
- Unklejoe 11y agoTiming requirements don't necessarily translate to _speed_ requirements. Microcontrollers like the Arduino/Atmel are perfect for situations where you need to guarantee that some signal will be asserted exactly 250 (no more, no less) nanoseconds after some other external event, _no_matter_what_. Since there's usually no OS running on something like an Arduino, you're basically forced to write very deterministic event driven programs. Also, since most (maybe all) instructions on those Atmel microcontrollers execute in a single clock cycle, you can easily dissect your C functions and know exactly how long they will take to execute. I wouldn't trust Linux for such an application even with a "real time" scheduler. Linux as a RTOS certainly has it's place, but it's best left for systems that can actually benefit from the added complexity. For most typical microcontroller projects, the extra features of a full Linux kernel would just get in the way. Note: There's nothing stopping someone from using a RPI in such a way as well (bare metal), but they are really geared for more complex applications, so there isn't as much support in that area. Also, the hardware is probably a little more complex. Therefore, my statements assume we're comparing an Arduino to an RPI running Linux.
- blhack 11y ago>Microcontrollers like the Arduino/Atmel are perfect for situations where you need to guarantee that some signal will be asserted exactly 250 (no more, no less) nanoseconds after some other external event, _no_matter_what_. What is an example of something like that?
- viraptor 11y agoSampling from external sensors for example. If you're measuring something changing over time, you may need very precise timing.
- quanticle 11y agoMusic, for example. If you're doing audio processing for music, it's much more preferable to have something that takes 20ms consistently to transform an input than something that takes 5ms 90% of the time and 50ms 10% of the time (due to, e.g. interrupts). That 50ms gap will show up as a note that's audibly behind the beat, while the improvement from 20ms to 5ms isn't really that beneficial. EDIT: another example is controlling a UAV. You can design around a system that consistently takes 20ms to process an input (e.g. by limiting the max speed). It's a lot more difficult to design around a component that takes 5ms most of the time, but will randomly take 50ms here and there, because you don't get to control when those lag spikes happen.
- winter_blue 11y agoCouldn't you write a really simple kernel[1] or bootstrapping program, and effectively run your program without an OS? Does an architecture (ARM / AVR / x86) limit the possibility of writing real-time code if the code is the OS, and just runs on the bare metal? Your program would run in ring 0, be the only "process" and have full access to RAM. You decide whether you want to handle interrupts or not. (I assume there's a way to select what interrupts you want to handle.) [1] For e.g., this tutorial explains how to write a basic x86 kernel: http://www.jamesmolloy.co.uk/tutorial_html/ http://www.jamesmolloy.co.uk/tutorial_html/
- mnw21cam 11y agoThere's no such thing as bare metal any more. https://en.wikipedia.org/wiki/System_Management_Mode https://en.wikipedia.org/wiki/System_Management_Mode - the CPU itself may at times spend some time doing "other things" such as changing the spin speed of the cooling fans, or interpreting the signals from the USB keyboard. The OS (running in ring 0) has no control over this - the CPU effectively just pauses for a little bit every now and again.
- pjc50 11y agoI'm not aware of any ARM systems that have this yet.
- jevinskie 11y agoTrustZone. It is "one level deeper" just like any other hypervisor or monitor. As far as I know, it is quite common in Android phones for HSM and DRM purposes. Yay? =\ http://www.arm.com/products/processors/technologies/trustzone/ http://www.arm.com/products/processors/technologies/trustzon... Edit: And, of course, it is probably exploitable in some way. See http://bits-please.blogspot.com/2015/08/exploring-qualcomms-trustzone.html http://bits-please.blogspot.com/2015/08/exploring-qualcomms-...
- sklogic 11y agoCan you bit-bang a 640x480 VGA on a Pi? No. Not even in bare metal, no OS. But a lowly attony85 can do it easily.
- hatsunearu 11y agoGenerally there is a trade-off between latency and throughput. Embedded Linux is generally geared towards more throughput than latency. Microcontrollers have less throughput-oriented features (threads, for instance), which makes them very well suited for latency-critical real time stuff.
- rorosaurus 11y agoFor what it's worth, you can code bare metal on the Raspberry Pi as well. It just doesn't have the community and support that Arduino currently has. https://github.com/dwelch67/raspberrypi https://github.com/dwelch67/raspberrypi
- danellis 11y agoIt also doesn't have the easily available official documentation like you get for a Cortex-M from ST, Atmel, etc.
- onnoonno 11y agoBut you still have a lot less predictability: - DRAM refresh - cache hits/misses
- mnw21cam 11y agoThere are quite a lot of systems out there with real-time requirements, where the system is not running a real-time predictable operating system - instead the likelihood of a missed deadline are averted simply by over-provisioning. You can get away with murder pretty much this way by just making your processor several times faster than is strictly necessary, provided you don't have any really long pauses in processing (like for instance having to swap in a page from disc). It works well enough most of the time for video playback. In essence, a job that requires 90% of the CPU time on predictable hardware can often be solved by just throwing faster hardware at it. If the RasPi can do it using 5% CPU, then it's probably fine. YMMV. Don't do this on medical equipment, space rockets, or self-driving cars.
- tremon 11y agoIn the literature, that's often distinguished as soft real-time vs hard real-time requirements. Hard real-time is for when you absolutely cannot miss a deadline without adverse effects (production stalls, equipment crashes, etc), while soft real-time is for situations where missing a deadline is recoverable (like your example, a video renderer would simply skip the current frame and start processing the next frame).
- tyingq 11y agoNot in the Pi Zero price range, but the AM335x processor inside the BeagleBone Black has an interesting way to deal with the need for strict timing. The AM335x has a pair of "PRU" units on the die, that are roughly little microcontrollers that have access to the main ARM's memory. So, you can write to main memory from Linux, jitter and all, and then let the PRU stream it out to anything that needs high speed, predictable data. This guy put a BB black inside an old MAC SE, and is driving the CRT with the PRU...very cool: http://www.nycresistor.com/2014/02/02/30th-anniversary-mac/ http://www.nycresistor.com/2014/02/02/30th-anniversary-mac/
- lee_s 11y agoThe AM335x PRU is exactly the Cortex-M core that they were talking about :). It just happens to be on-die with the main core. Very cool project, thanks for linking!