Author Topic: Upgrading to ARM  (Read 6947 times)

0 Members and 1 Guest are viewing this topic.

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Upgrading to ARM
« on: October 24, 2015, 03:54:15 pm »
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?? 
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Upgrading to ARM
« Reply #1 on: October 24, 2015, 04:38:12 pm »
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.
« Last Edit: October 24, 2015, 04:48:56 pm by Yansi »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Upgrading to ARM
« Reply #2 on: October 24, 2015, 05:09:48 pm »
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.
 

Offline max_torque

  • Super Contributor
  • ***
  • Posts: 1275
  • Country: gb
    • bitdynamics
Re: Upgrading to ARM
« Reply #3 on: October 24, 2015, 06:13:55 pm »
Hey guys, 
                   I am using arduino for quite a while

Important 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!)
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: Upgrading to ARM
« Reply #4 on: October 24, 2015, 06:15:55 pm »
I done that program for some one so I cannot share. 
Do you have any suggestions on how should I improve my coding technic
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: Upgrading to ARM
« Reply #5 on: October 24, 2015, 06:17:54 pm »
Yeah I just read some where that it takes 42-44 clock cycle to complete a digital write
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline CrashO

  • Supporter
  • ****
  • Posts: 164
  • Country: nl
Re: Upgrading to ARM
« Reply #6 on: October 24, 2015, 06:29:08 pm »
Yeah I just read some where that it takes 42-44 clock cycle to complete a digital write
If you use AVR assembler you can do 8 writes (one full register) in 2-3 clockcycles  ::)
« Last Edit: October 24, 2015, 06:31:19 pm by CrashO »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Upgrading to ARM
« Reply #7 on: October 24, 2015, 09:16:54 pm »
Important question:  Are you using the Arduino development language, or coding in native C?

There is no such thing as 'arduino development language' . Arduino development is done in C++.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Upgrading to ARM
« Reply #8 on: October 24, 2015, 09:18:56 pm »
Yeah I just read some where that it takes 42-44 clock cycle to complete a digital write

This 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)
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: Upgrading to ARM
« Reply #9 on: October 24, 2015, 09:48:48 pm »
Yeah I just read some where that it takes 42-44 clock cycle to complete a digital write
If you use AVR assembler you can do 8 writes (one full register) in 2-3 clockcycles  ::)

What 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...
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline rx8pilot

  • Super Contributor
  • ***
  • Posts: 3634
  • Country: us
  • If you want more money, be more valuable.
Re: Upgrading to ARM
« Reply #10 on: October 24, 2015, 10:32:59 pm »
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.

I 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.

What 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...

I 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.
Factory400 - the worlds smallest factory. https://www.youtube.com/c/Factory400
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: Upgrading to ARM
« Reply #11 on: October 24, 2015, 10:56:56 pm »
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 to write assembly, though. Most examples of that I can find seem to come from a poor understanding of compiler optimizer behavior, things like volatile, 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 is highly unlikely 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.

 :-//
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: Upgrading to ARM
« Reply #12 on: October 25, 2015, 12:27:51 am »
"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.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4099
  • Country: us
Re: Upgrading to ARM
« Reply #13 on: October 25, 2015, 01:30:50 am »
Quote
The compiler knows full well how to make proper use of the sbi/cbi/in/out instructions...
IOW, 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.
« Last Edit: October 25, 2015, 01:59:30 am by KL27x »
 

Offline daybyter

  • Frequent Contributor
  • **
  • Posts: 397
  • Country: de
Re: Upgrading to ARM
« Reply #14 on: October 25, 2015, 04:17:26 am »
Did you check stm32?

There is an Arduino port for it.

http://www.stm32duino.com
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: Upgrading to ARM
« Reply #15 on: October 26, 2015, 08:37:33 am »
Hey guys cool down it not about which is better c or assembly or arduino

The 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.!!
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Upgrading to ARM
« Reply #16 on: October 27, 2015, 10:45:32 am »
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 are not the 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
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline yashrkTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: in
  • A MAKER, AN ENGINEER, A HOBBYIST FOR LIFE
    • My Personal Blog
Re: Upgrading to ARM
« Reply #17 on: October 29, 2015, 06:22:11 pm »
yeah thank you !!
Find me and things I'm working on - https://www.yashkudale.com/
 

Offline JacquesBBB

  • Frequent Contributor
  • **
  • Posts: 829
  • Country: fr
Re: Upgrading to ARM
« Reply #18 on: October 29, 2015, 09:27:56 pm »
The 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.

You can use TI Launchpad with Energia. It will be exactly as  arduino.
 

Online rsjsouza

  • Super Contributor
  • ***
  • Posts: 5985
  • Country: us
  • Eternally curious
    • Vbe - vídeo blog eletrônico
Re: Upgrading to ARM
« Reply #19 on: October 30, 2015, 07:12:28 pm »
The 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.

You can use TI Launchpad with Energia. It will be exactly as  arduino.
I 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).
Vbe - vídeo blog eletrônico http://videos.vbeletronico.com

Oh, the "whys" of the datasheets... The information is there not to be an axiomatic truth, but instead each speck of data must be slowly inhaled while carefully performing a deep search inside oneself to find the true metaphysical sense...
 

Offline AlxDroidDev

  • Frequent Contributor
  • **
  • Posts: 471
  • Country: br
    • Arduino Web Brasil
Re: Upgrading to ARM
« Reply #20 on: November 06, 2015, 11:33:06 pm »
Important 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!

"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.
"The nice thing about standards is that you have so many to choose from." (Andrew S. Tanenbaum)
 

Offline logictom

  • Supporter
  • ****
  • Posts: 336
  • Country: au
Re: Upgrading to ARM
« Reply #21 on: November 07, 2015, 04:54:44 am »
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.

If 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.
 

Offline logictom

  • Supporter
  • ****
  • Posts: 336
  • Country: au
Re: Upgrading to ARM
« Reply #22 on: November 07, 2015, 04:58:48 am »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf