Upgrading to ARM - Page 1
Forum section: electronics / beginners

author: yashrk
author_rank: Frequent Contributor
timestamp: October 24, 2015, 03:54:15 pm
content: Hey guys,I am using arduino for quite a while recently I was working on a project where I have to measure 3 analog inputs average the values and do some basics mathematical operation also controlling a pwm pin and lcd, due to it arduino had gone slow but the code worked.Now I am working on segway so for its real time performance I am thinking of using an arm processor, I am basically confused between teensy 3.2 or TI launched pad.!!If I use teensy I can use arduino platform for its programming which will help or if I should now graduate to TI launch pad and learn arm from basic??

author: Yansi
author_rank: Super Contributor
timestamp: October 24, 2015, 04:38:12 pm
content: If you can't make arduino measure 3 values, average them and control a PWM without overworking the AVR MCU, don't go for ARM in the first place! Learn how to code instead.It is likely that with your coding style you will quicky run out of computing power on anything, including ARM. And more like because of using that arduino software bullshit. If you need computing performance, go barebone programing.I do NOT say you have to write everything in assembly, god no, away are those times when that was essential... But to get reasonable performance it is a good start to have some progrming practice in the first place.EDIT: Have you tried to work out why the AVR goes slow? What math have you used? Goniometric functions in floating point? Would be indeed very bad coding practice. If you like to tell us about your project on the *duino thing, we can for sure help you optimize your code.

author: zapta
author_rank: Super Contributor
timestamp: October 24, 2015, 05:09:48 pm
content: Be aware that teensy 3.2 is not open source so if you plan to have later custom PCBs based on it you will need to buy that license chip (~6$ last time I checked).Otherwise, it's a fine choice for quick one offs.As for investing the time learning ARM (TI or other), it's depends on your goals.

author: max_torque
author_rank: Super Contributor
timestamp: October 24, 2015, 06:13:55 pm
content: Quote from: yashrk on October 24, 2015, 03:54:15 pmImportant question: Are you using the Arduino development language, or coding in native C? The first step to understanding "efficient" coding is to access the microprocessors resources at a low level. ie not through a large, slow, obfuscation like the Arduino language!(don't get me wrong, there are a lot of good things about using the Arduino language, and "beginner accessablility" is prime among them, but it's worth exploring the same processor with the wider, faster, more flexible approach of "C" before you write it off as "too slow" etc!)

author: yashrk
author_rank: Frequent Contributor
timestamp: October 24, 2015, 06:15:55 pm
content: I done that program for some one so I cannot share.Do you have any suggestions on how should I improve my coding technic

author: yashrk
author_rank: Frequent Contributor
timestamp: October 24, 2015, 06:17:54 pm
content: Yeah I just read some where that it takes 42-44 clock cycle to complete a digital write

author: CrashO
author_rank: Unknown
timestamp: October 24, 2015, 06:29:08 pm
content: Quote from: yashrk on October 24, 2015, 06:17:54 pmIf you use AVR assembler you can do 8 writes (one full register) in 2-3 clockcycles

author: zapta
author_rank: Super Contributor
timestamp: October 24, 2015, 09:16:54 pm
content: Quote from: max_torque on October 24, 2015, 06:13:55 pmThere is no such thing as 'arduino development language' . Arduino development is done in C++.

author: zapta
author_rank: Super Contributor
timestamp: October 24, 2015, 09:18:56 pm
content: Quote from: yashrk on October 24, 2015, 06:17:54 pmThis is with the standard arduino digital I/o library. There are arduino library with faster I/O. Search around. If you don't find I can send you a link (away from my computer)

author: c4757p
author_rank: Super Contributor
timestamp: October 24, 2015, 09:48:48 pm
content: Quote from: CrashO on October 24, 2015, 06:29:08 pmWhat is it with assembler people? C will take the same exact number of cycles for a tenth of the faff. The compiler knows full well how to make proper use of the sbi/cbi/in/out instructions...

author: rx8pilot
author_rank: Super Contributor
timestamp: October 24, 2015, 10:32:59 pm
content: Quote from: Yansi on October 24, 2015, 04:38:12 pmI would agree with that statement. I have never used Arduino, primarily because I was concerned about bloated code. I have done everything in C with AVR. When I look at my earliest projects - they were brutally inefficient. I made up for that by getting bigger and faster MCU's but still ran out of cycles. I took some time to shake down my code for clock cycle efficient and realized a massive improvement and did not need the faster hardware at all - not even close. It was a memorable moment in my learning curve to see the amazing benefit of efficient code.Quote from: c4757p on October 24, 2015, 09:48:48 pmI wonder the same thing. I have heard a few (very few) good arguments where something very time sensitive has to be coded very specifically. Maybe right at the point of ambiguity of the chosen compiler? The effort to learn and code in assembly is so severe that it is hard for me to imagine the benefit. I have only done an overview of assembly a long time ago and never really tried to use it for real. C has been able to get me rather far with some pretty tricky and sticky situations.

author: c4757p
author_rank: Super Contributor
timestamp: October 24, 2015, 10:56:56 pm
content: There are definitely points where the assembly is important - in fact, I just spent the last approximate hour poring over assembly dumps trying to get things running at the level of optimization I wanted. I've found very few points where I've wanted towriteassembly, though. Most examples of that I can find seem to come from a poor understanding of compiler optimizer behavior, things likevolatile, etc.There are a few examples where you might want to use assembly if you're really pedantic. For instance, the atxmega series has a number of system registers that must be unlocked first by writing a special key into a special register, and no more than four cycles may elapse between writing the key and writing the system register. With both the key reg and the system reg declared volatile, the compiler ishighlyunlikely to stick something in between, but if you really want to be pedantically sure, you should wrap the two writes up into an inline asm statement. volatile guarantees write order but it doesn't guarantee extra instructions won't be "rearranged" into the middle.Two instructions as inline asm are a far cry from writing your code in assembly, though.

author: c4757p
author_rank: Super Contributor
timestamp: October 25, 2015, 12:27:51 am
content: "assembler people" are the sort of people who point to assembler as advantageous because it can write to a port in exactly as many cycles as the C compiler can.

author: KL27x
author_rank: Super Contributor
timestamp: October 25, 2015, 01:30:50 am
content: QuoteIOW, the compiler recognizes assembly? You can write assembly in your C program? You can be an assembler people that uses C? Maybe you're an assembler people and you don't even know it!Technically, it is correct to say that assembly (or the ultimate machine code) can do it in x cycles, because sbi/cbi/in/out are assembly instructions that aren't compiled, no? If you are using the native instructions for the device I would think they are assembled, not compiled.A real assembler person can optimize a digital write routine to make it smaller and faster, rather than searching and downloading a better library with other bugs. Because the in/out instructions may be the fastest, but you may want to retain some of the features that are included in a digital write; just not all of them for a particular app... in case you need your pinouts to be flexible for future use/modification, for instance. Tracking down and changing several hundred in/out commands will not be fun.In PIC architecture, specifically, you can even optimize code in assembly for use within the same page and/or banks when using absolute code. Not that I would recommend it, but you can ditch part of the banking/paging instructions that are done (in this case, redundantly) over and over in a C or in a relocatable assembly code. How much do you want to squeeze out? The sky is the limit. It takes some understanding of the native instructions (i.e. assembly) and structure. You can take shortcuts that are not wise from a global perspective, but which can work exactly fine in a specific situation.

author: daybyter
author_rank: Frequent Contributor
timestamp: October 25, 2015, 04:17:26 am
content: Did you check stm32?There is an Arduino port for it.http://www.stm32duino.com

author: yashrk
author_rank: Frequent Contributor
timestamp: October 26, 2015, 08:37:33 am
content: Hey guys cool down it not about which is better c or assembly or arduinoThe point was I was any how going to upgrade to ARM anyway but I wanted to know should I stick to arduino (teensy) or go and program in C using launchpad.My last written code was slow FYI I wrote it ones, it worked. The code didn't need to be fast so it wasn't worth the effort to go back to the code and optimize it.But the whole thing led me to thinking two things either my coding tech is bad or the arduino is bit slow.Either way I have found a tutorial based on ti launchpad in which he explains C functions with its effects in assembly code and how to optimize it.I guess that's the way I should be headed.Thanx for your time friends.And ya I will work on my coding tech and try to improve it.And ya if any one hates arduino want to say that if it wasn't for ease of arduino lang, community and its hardware I may be wouldn't have got the exposure to electronics which I have got now.Again thank you for your time.!!

author: obiwanjacobi
author_rank: Super Contributor
timestamp: October 27, 2015, 10:45:32 am
content: To write faster code (if its more efficient... ;-) you can start by reading the ATmega328P datasheet (or the one you're using). Get to know the MCU you work with from the inside. It is a bit of a study and do not try to understand it all at once. Start with the GPIO ports.Use the registers explained in the datasheet to manipulate the output (remember these arenotthe Arduino Board Pins but the MCU pins!). Build from that to whatever it is you're trying to accomplish.For a better IDE experience (on Windows) you may want to check out Visual Micro and Atmel Studio.Hope it helps,Marc

author: yashrk
author_rank: Frequent Contributor
timestamp: October 29, 2015, 06:22:11 pm
content: yeah thank you !!

author: JacquesBBB
author_rank: Frequent Contributor
timestamp: October 29, 2015, 09:27:56 pm
content: Quote from: yashrk on October 26, 2015, 08:37:33 amYou can use TI Launchpad with Energia. It will be exactly as arduino.

author: rsjsouza
author_rank: Super Contributor
timestamp: October 30, 2015, 07:12:28 pm
content: Quote from: JacquesBBB on October 29, 2015, 09:27:56 pmI was going to say that as well. Energia 16 supports a bunch of different Launchpads, including the TivaC/MSP432 (Cortex M4) and some cortex M3 with wireless features (CC3200).

author: AlxDroidDev
author_rank: Frequent Contributor
timestamp: November 06, 2015, 11:33:06 pm
content: Quote from: max_torque on October 24, 2015, 06:13:55 pm"Arduino" is not a language. The language is C/C++"Arduino" is not just the IDE either. It is the entire ecosystem: the boards, the libraries, the IDE, the bootloader...Even if one is using the Arduino IDE as a development tool, all the implementation can be done without using the Arduino libraries (that is the slow part). You don't need, for example, to use DigitalWrite. You can simple use "PORTD = <some value>", and that will write the entire port (all of its 8 pins) at once.Granted, the libraries are a huge trade off: they make coding simpler and with a much softer learning curve, but are also painfully slow sometimes, but that's no reason to bash Arduino or its IDE like that, since it doesn't remove the ability for more knowlegeable users to code using a lower level approach.

author: logictom
author_rank: Unknown
timestamp: November 07, 2015, 04:54:44 am
content: Quote from: AlxDroidDev on November 06, 2015, 11:33:06 pmIf you're not using the libraries and writing lower level code why would you use the IDE then? It's got to be one of the worst out there, I think that's universally accepted, even by the Ardunio collective.

author: logictom
author_rank: Unknown
timestamp: November 07, 2015, 04:58:48 am
content: If you go down the TI route I would suggest looking what IDEs are available other than TI's Code Composer Studio, it's not the best written piece of software I've used for development.