Author Topic: Caught up between a rock (Arduino) and a hard (ARM) place.  (Read 17987 times)

0 Members and 1 Guest are viewing this topic.

Offline CM800Topic starter

  • Frequent Contributor
  • **
  • Posts: 882
  • Country: 00
Caught up between a rock (Arduino) and a hard (ARM) place.
« on: July 23, 2015, 07:22:01 pm »
Hi All,

For a while now I have been wanting to progress myself beyond Arduino and begin to learn more about microcontrollers and become more capable, I need to home my skills.

Problem is, I know Arduino and I feel I keep diving off into the deep end, I have spent quite a bit of money on devkits for microcontrollers I think may be too complex for me.

Now, I have stepped back a bit and I want to start again into microcontrollers, I feel Arduino has just kinda messed it up, making it too simple to the point I feel lazy not understanding or doing anything beyond simple Arduino 'stuff'.

I want to try get into protocols, timing and so on, controlling Switching systems (Transformer drivers) and communications and busses, get involved with motor drivers and all sorts.

The real question I have... Where should I truly start and how? Tutorials etc. I have been kidding myself into thinking 'I know all this' for too long. When I don't really.

What I have already:
TI Launchpad Tiva C Series.
A Huge pile of Arduino products (Nanos, Megas and Unos)
Cypress CY8CKIT (the USB stick one)
Freescale FRDM-KL43Z
SAM4S-EK2 Dev Board


What would you recommend I get or start with (I don't mind buying more if it is worth while...)

What tutorials can I look at.

I really appreciate any response or advice, feedback or thoughts! :)
 

Offline chicken

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: us
  • Rusty Coder
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #1 on: July 23, 2015, 07:35:12 pm »
You could reuse the Tiva-C and take this embedded systems course on edX:
https://www.edx.org/course/embedded-systems-shape-world-utaustinx-ut-6-02x

The course was discussed in detail on a recent embedded.fm podcast:
http://embedded.fm/episodes/107

EDIT: Never mind, course enrollment is closed for now :(
« Last Edit: July 23, 2015, 07:37:05 pm by chicken »
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #2 on: July 24, 2015, 01:10:40 am »
One of the "annoying" things you may notice is that TI, Cypress, Freescale, and Atmel ARM boards will all want you to use their own special libraries that will "make things easier" and probably hide the same things that the Arduino is hiding from you.  (Just not as successfully.   And all different from one another.  Sigh.)

The UT online class would be a good starting point, if it's offered again.  It was a really good intro.

Depending on how much you don't know, one useful idea is to translate some of the Arduino projects you have done (or have become familiar with) intro code that is NOT dependent on the Arduino framework.  Go ahead and read the Arduino source code, or figure out how to do each thing that an Arduino library has done without using their code.  Use the other vendor code, or don't (both are useful exercises.)
 

Offline Mr.B

  • Supporter
  • ****
  • Posts: 1237
  • Country: nz
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #3 on: July 24, 2015, 01:25:23 am »
...one useful idea is to translate some of the Arduino projects you have done ...

I agree.
That is basically what I did to move to the next phase.
I am using Atmel Studio for the majority of my work.
I still buy arduino pro mini clones to use as cheap quick project boards, but use Atmel Studio and not the arduino framework, bootloader and IDE.
I approach the thinking of all of my posts using AI in the first instance. (Awkward Irregularity)
 

Offline ralphd

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #4 on: July 24, 2015, 01:38:35 am »
I'd look at programming the AVRs with the Atmel toolchain (avr-gcc/avr-libc).  AVRs are much simpler than ARM MCUs.  As Bill said different ARM vendors will have you use their custom libs, while in comparison its much easier to write AVR code that directly manipulates the registers.
If you want to do protocols, then I recommend learning assembler.  You can't bit-bang a high speed protocol like a UART in C.
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #5 on: July 24, 2015, 01:41:31 am »
Download the Atmel Studio, get yourself a JTAGICE3 (or preferably, a cheap clone), and start programming your Arduino that way using the 2x3 header on the Arduino itself. At that point, you're not "doing Arduino" per se, you're programming an ATMega328P.

Or even better, just stay with the Arduino IDE, but wean yourself off the Arduino libraries and try coding things directly, referring directly to the ATMega328P datasheet. For example:
-- Replace digitalWrite and digitalRead with direct manipulation of the DDRx, PINx, and PORTx registers.
-- Replace analogWrite with direction manipulation of the timer/counter registers
-- Replace Serial.begin and friends with direction manipulation of the UART registers

Once you've done that, you'll have pure, bare metal ATMega328P source code that is not Arduino in any sense of the word, and ready for direct use in gcc-avr or Atmel Studio.

I'm not advocating coding like this for the rest of your life; libraries are useful and time-saving and they exist for a reason! (Having said that, digitalWrite is horrendously bloated for something that should take a single clock cycle.) But by changing things one feature at a time, you'll never be too far out of your depth, and by the time you've converted your code to being purely register-based, you'll be confident at tackling the other preipherals (SPI, ADC, etc), and you'll be far more confident that you can tackle any other reasonably simple MCU.

If you get stuck interpreting the ATMega328P datasheet, ask us.
 

Offline Muxr

  • Super Contributor
  • ***
  • Posts: 1369
  • Country: us
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #6 on: July 24, 2015, 02:11:06 am »
You need a purpose in order to really learn. I mean sure some things you can learn by just tinkering or reading about it, but real learning comes from doing and accomplishing goals, learning from the mistakes you make.

Decide on a project you want to do, find out what tools are needed and how you want to go about accomplishing that project. Learn the tools by doing.

No one can tell you what that project should be. What I can tell you is that you will hit obstacles, so picking the right project which will keep you motivated to keep going is half the battle.
 

Offline ralphd

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #7 on: July 24, 2015, 03:04:55 am »
(Having said that, digitalWrite is horrendously bloated for something that should take a single clock cycle.)
With Wiring (which Arduino is based on), digitalWrite(13,HIGH) compiles to a single sbi instruction (which is 2 clock cycles).
http://wiring.org.co
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #8 on: July 24, 2015, 03:41:03 am »
(Having said that, digitalWrite is horrendously bloated for something that should take a single clock cycle.)
With Wiring (which Arduino is based on), digitalWrite(13,HIGH) compiles to a single sbi instruction (which is 2 clock cycles).
http://wiring.org.co

Since when? I've fixed many a slow bit-banging sketch in the past by getting rid of digitalWrite. Does that optimization fail with a dynamically determined output value (e.g. digitalWrite(13, bitOut);)??
 

Offline FreddyVictor

  • Regular Contributor
  • *
  • Posts: 164
  • Country: gb
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #9 on: July 24, 2015, 06:32:45 am »
Now, I have stepped back a bit and I want to start again into microcontrollers, I feel Arduino has just kinda messed it up, making it too simple to the point I feel lazy not understanding or doing anything beyond simple Arduino 'stuff'.

this is my main gripe with arduino....

how about trying to program the arduino as an ATmega chip instead ?
all info you need regarding hardware registers/modules is in the datasheet
this is a small jump rather than the giant leap into ARM which I fear will be too great

you just need a programmer. The AVR ISP MkII was the std one to use but is now OOP, replaced by the ICE, but cheaper alternatives are available

as per rs20 !
 

Offline CM800Topic starter

  • Frequent Contributor
  • **
  • Posts: 882
  • Country: 00
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #10 on: July 24, 2015, 06:50:06 am »
Huge thanks to all of you for your responses.

I will take a look at programming the Arduinos 'manually'

Is this what I need to get for it?
http://uk.farnell.com/atmel/atatmel-ice-basic/debugger-atmel-arm-avr-basic-kit/dp/2407172?MER=en-mer-0713-pd-r2-acce
 

Offline Chris C

  • Frequent Contributor
  • **
  • Posts: 259
  • Country: us
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #11 on: July 24, 2015, 08:20:54 am »
[TCWilliamson], I have not worked with Arduino.  But as I understand it, it works as a Hardware Abstraction Layer (HAL) that hides the complexity of the hardware, and differences between platforms.

One way you might approach this is by starting to write your own HAL.  You might even choose to start this on the Arduino.  That offers the advantage of being a familiar platform to you, and allows you to gradually replace Arduino calls with calls to your own HAL.

Start with plain old digital I/O.  As you write this, you'll obviously learn how to directly access the AVR's digital I/O registers.  But perhaps more importantly, you'll learn more about some general coding practices, that the Arduino experience might have deprived you of.

For example, even though I haven't used an Arduino, I know that:

With Wiring (which Arduino is based on), digitalWrite(13,HIGH) compiles to a single sbi instruction (which is 2 clock cycles).

This type of optimization is only possible when the pin number is a constant (at very least).  In this example, the address of the hardware register, bit position within the register, and value are all known at compile time; therefore the compiler has the opportunity to condense it to a single instruction.

Otherwise, the digitalWrite function is called, which even I know is notoriously slow.  So is the one in my HAL.  Every time it's called, it must:

1) Check that the pin number is within the valid range of physical pins, and that the pin supports digital I/O.
2) Convert the pin number to both a register address and bit number within the address.
3) Modify the bit.

It's #1 and #2 that consume most of the time!  In the process of writing my HAL, I realized that there was a better way.  (Which oddly, I have never seen reference to being used on the Arduino.)

Assume one wants to write a digital pin, which is not a constant, and so cannot be optimized at compile time.  But that pin will typically be written repeatedly, and that's where the slowness of a function like digitalWrite really hurts; because it has to check and convert that pin repeatedly, when that isn't really necessary.  So instead, when we know we're going to be writing a pin repeatedly, we could do something like this:

1) Define a structure in the HAL (FASTPIN) that will store the register address and bit number.
2) Create a function in the HAL (FastPinInit) that when passed an instance of the structure and a pin number, checks the pin for validity, converts the pin to register address and bit number, and stores this in the structure.
3) Create macros that when passed the initialized structure, will set (FastPinSet), clear (FastPinClear), or toggle (FastPinToggle) the pin based on the info stored in the structure.

And in your code:

1) Create an instance of FASTPIN.
2) Initialize it by calling FastPinInit.
3) Repeatedly write it by calling FastPinSet, FastPinClear, or FastPinToggle.

Which accelerates writing the pin greatly!  It's not as fast as a single instruction, obviously; but still an order of magnitude of faster than calling digitalWrite.

Assume you've implemented something like this on the Arduino, that handles both writes and reads.  As well as some bit-banged (software) I2C and SPI routines, that use your FastPin implementation.

Later you want to convert it to ARM.  Digital I/O is a little different there, but not much.  You might need to change what information is stored in FASTPIN, but that's no big deal, you only need to change the structure definition in one place; all your code that uses FASTPIN will use the new definition.  Then rewrite FastPinInit, and the FastPin* macros, and...

Voila.  In a few hours, you have reasonably fast digital I/O on ARM.  As well as I2C and SPI, on any pin.  Eventually you may implement hardware I2C and SPI, perhaps even driven by DMA.  But you might not need that level of performance right away, so you can do that later - when needed, or at your leisure.  This helps make moving to a new platform faster and less intimidating.

(I took that concept even further in my own HAL.  Once I get a single timer, its associated interrupt, and a few other things working on the new platform, I use it to drive a C state engine that functions as a scheduler.  This lets me simulate additional timers, PWMs, and other "virtual" peripherals.  Not high performance by any means, but it gets me up and running on new platforms really fast.  After just a week on PIC32 I have all this running, and can port useful code to it; I'm just taking some time to learn and tweak before moving on to gradually implementing the real peripherals.  Of course, writing the original scheduler was difficult, but at least for me, it was fun.  You need not take things this far!)

Sorry for the length of this post, but I think it demonstrates how writing your own HAL can be both educational and useful.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #12 on: July 24, 2015, 09:05:38 am »
Huge thanks to all of you for your responses.

I will take a look at programming the Arduinos 'manually'

Is this what I need to get for it?
http://uk.farnell.com/atmel/atatmel-ice-basic/debugger-atmel-arm-avr-basic-kit/dp/2407172?MER=en-mer-0713-pd-r2-acce

Think you will find one of these £5 programmers will do a lot of chips you have, use one myself.
http://www.ebay.co.uk/itm/USBASP-USB-ISP-Programmer-10-Pin-ISP-interface-Cable-AVR-ATMEL-ATMega-/171863554646?pt=LH_DefaultDomain_3&hash=item2803ddba56

Sure you could readily sell and unwanted  dev boards on this forum or ebay/preloved.

While every one has talked about other high level options for you to program with, don't forget there is also Assembly code which really takes you much deeper into the hardware; its main drawback is, though possible, its not really suited to complex code used in high end code like USB ,Can  etc.
 

Offline FreddyVictor

  • Regular Contributor
  • *
  • Posts: 164
  • Country: gb
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #13 on: July 24, 2015, 09:20:22 am »
Is this what I need to get for it?
http://uk.farnell.com/atmel/atatmel-ice-basic/debugger-atmel-arm-avr-basic-kit/dp/2407172?MER=en-mer-0713-pd-r2-acce

yes, thats the official programmer (it also will do PDI programming if you should want to play with ATXmegas).

TBH, it's a bit pricey, others have had success with the cheap USBASP programmers such as these
make sure you get a 10pin->6pin adaptor tho' such as the one shown in this pic
nb: I have an AVR ISP MkII so havn't tried these other options, others should be able to help on this forum

 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #14 on: July 24, 2015, 09:29:43 am »
...glad that at least someone woke up and wrote "I feel Arduino has just kinda messed it up, making it too simple to the point I feel lazy not understanding or doing anything beyond simple Arduino 'stuff'."

'd be nice if more people would come to the same conclusion.

Thumbs up for your decision, keep the good work man!
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #15 on: July 24, 2015, 09:31:12 am »
...glad that at least someone woke up and wrote "I feel Arduino has just kinda messed it up, making it too simple to the point I feel lazy not understanding or doing anything beyond simple Arduino 'stuff'."

'd be nice if more people would come to the same conclusion.

Thumbs up for your decision, keep the good work man!
+1, well put. I was trying to say the same thing, but couldn't put it into words.
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #16 on: July 24, 2015, 09:33:49 am »
Quote
Is this what I need to get for it?
http://uk.farnell.com/atmel/atatmel-ice-basic/debugger-atmel-arm-avr-basic-kit/dp/2407172?MER=en-mer-0713-pd-r2-acce
That's the one to get, if you get anything.  Unlike the earlier models (the jtagICE3 that someone mentioned), the newer Atmel ICE will program and debug Atmel ARM *and* AVR chips.  The cheap USBASP type programmers won't do debugging either.

The cheapest route to AVR debugging would probably involve an "ATmega328 Xplained Mini" board, which is sort-of Arduino compatible, about $10, and includes a debugging interface...  (Your TI and Freescale boards already have debugging support as well.)  TI is supposed by the Arduino-like "Energia", so a similar learning progression should be possible.   But it IS a much more complex chip than the AVR.

But you don't "need" to get it; you can load bare-C applications onto the Arduino using the arduino bootloader just fine.  (you won't have debugging, though.)

As for DigitlaWrite() on Wiring vs Arduino, the original Wiring and Arduino code have the "slow" implementation that permits variable and abstract pin numbers and values.  Later, the original wiring author jumped back on the bandwagon with his own newer version of "Wiring" that has the "improved" digitalWrite().   (it hasn't gained a lot of users, as far as I can tell.)   Faster "smart" digitalWrite() implementations have been written several different ways, but the Arduino powers aren't particularly interested.  For one thing, it wouldn't be a great thing for slightly different calls to digitalWrite() to have 20 or 30 to 1 performance variations.

Understanding and re-writing digitalWrite() in various ways would be one of the exercises you should do in your quest for deeper knowledge...


 
The following users thanked this post: I wanted a rude username

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: pl
  • Troll Cave Electronics!
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #17 on: July 24, 2015, 10:08:46 am »
Other than ARM, PIC microcontrollers (despite being shit in general) give you a possibility to debug the code with genuine Microchip tool that costs like $40. Obviously ARM debug tools are cheaper.

BTW, stating that ARM microcontrollers are complex is bizarre. It'a not hard.

-get IDE that supports chosen chip
-create new project. In almost every case the IDE will create the startup script, linker script and such automatically.
-start writing code

in order to use a peripheral just enable the peripheral clock (otherwise it won't answer or will produce a system fault of some sort) and write values to the registers.
To check what to write where and in what order just read the datasheet (or other reference manual there is for peripherals) same as you would do programming any other microcontroller.

That's it.

Stuff like interrupts is common to all ARM microcontrollers, as it is built into the core itself.
I love the smell of FR4 in the morning!
 

Offline ralphd

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #18 on: July 24, 2015, 01:14:26 pm »
Here's the detaila on the speed of digitalWrite in Wiring (good) vs. Arduino (bad):
http://nerdralph.blogspot.ca/2014/04/a-better-digitalwrite-for-arduino.html

Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #19 on: July 24, 2015, 02:10:56 pm »
Shouldn't it be better to learn how to use the GPIO registers directly, instead of using any of these higly limited bullshitware functions? (The same applies for most ARM vendor libraries...)
 

Offline tech5940

  • Supporter
  • ****
  • Posts: 85
  • Country: ca
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #20 on: July 24, 2015, 02:52:17 pm »
To the OP,

I was in a similar situation as you. I was happy with Arduino's ease of use and the available pre made library's. It was a great introduction into what can be done with microcontrollers but I just knew there was so much I was missing and it really shouldn't be this simple to plug this board into another board and upload a "sketch" and just have it all work. The first thing I did was order some bare ATMEGA328P chips and wire them up like an Arduino by hand, and then learn to burn the Arduino's boot loader to the blank chip. I moved on from there and would make projects that still used the Arduino framework but I would put the ATMEGA328P in the project and only wire up what was needed. I was still left with the feeling that there is way more to all this that I don't yet understand..

So my approach was to completely separate from ATMEL and give PIC microchip's a try. I'm not saying this is the correct approach for you but it's what I chose. This isn't an attempt at starting a PIC/ATMEL war either, my reasoning was along the lines of wanting to completely separate from Arduino/Atmel and learn from scratch. I was worried if I chose to stay with ATMEL that I would be constantly crossing paths with the "Arduino" way of programming which may have been hard to separate and cause confusion.

So I purchased a PicKit3, a selection of midrange pic microcontrollers, downloaded MPLAB X IDE and the XC8 compiler.  I picked the cheapest micro I had purchased, downloaded its Data sheet and got to work trying to figure out how to make a LED flash.  I quickly learned that YES there was lots going on behind the scenes with Arduino that was hidden from its user, and that just getting a simple LED to flash from scratch was much more involved. I stuck with using C code and that is where some of my experience with Arduino helped out.

One thing I came across that helped me tremendously (aside from the EEVBlog) was a website with two free books (if you view them online). It is based on PIC micro's and just seemed to explain everything in a very visual way which is how I learn. It might not be for everyone, but here are the links if your interested. The creator of the book has his/her? own PIC micro compiler software for sale, I didn't use that and just skipped over the part in the book specific to that compiler. The rest of it was great and useful information.

http://www.mikroe.com/chapters/view/14/chapter-1-world-of-microcontrollers/
http://www.mikroe.com/chapters/view/1/introduction-world-of-microcontrollers/


MPLAB X can be a bit intimidating at first but keep with it, and try and keep things simple to start. It has many features that will help you configure the chip and it's functions which may be of use later but to start I'd recommend a blank main.c file with Datasheet in hand and get to work with simple tasks like flashing a LED. Once you have got that to work then you need to decide on projects, what do you want the micro to do for you and from there you will be forced to learn what is needed while at the same time having a goal so you don't give up on it.

The path you choose is up to you, and I'm really not partial to PIC, however I am glad that I decided to do things the "Hard" way and really learn what's going on behind the scene's. Even though I'm still using a compiler and C code (rather then machine code) I feel what your still close enough the the internals of the micro to get an idea of what is actually going on.

If I could tell you only a few things they would be:

Registers, Registers, Registers! Data sheets are your friends learn how to read them and understand them. Learn the difference / relation to Binary, Hex, and Decimal numbers.

I'm not sure on the OP's background so if some of this advice is a bit to simplistic I apologize. I just wanted to share the route I took from zero experience with digital electronics and what helped me learn along the way.  The website I linked to above I have no affiliation with, and I shouldn't discount the vast resources that the EEVBlog itself has to provide. Dave's video's have been extremely helpful, and this forum was frequently in the top of the list when searching online for help. Truth be told if it wasn't for the EEVBlog I'm not sure id even know what a Microcontroller is.

Good luck,

 

Offline ralphd

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #21 on: July 25, 2015, 01:01:11 am »
Faster "smart" digitalWrite() implementations have been written several different ways, but the Arduino powers aren't particularly interested.  For one thing, it wouldn't be a great thing for slightly different calls to digitalWrite() to have 20 or 30 to 1 performance variations.

I don't seem to get your point (or how you come up with 20:1).
digitalWrite() in Arduino is ~50 clock cycles.
digitalWrite(13,HIGH) in Wiring is 2 clock cycles.
digitalWrite(13,stateVar) in Wiring is 5/6 clock cycles.
digitalWrite(pinVar,stateVar) in Wiring I expect avr-gcc would use a jumptable and compile to ~15 clock cycles.  I've never seen such bad code in any Arduino libraries anyway, so it's more of a moot point.

So in real world code, you'll see a 5:2 variation in performance for Wiring's digitalWrite(), and it is an order of magnitude faster.  Can you give an example of where Arduino's predictably slow digitalWrite would be preferred?

And if consistently fast digitalWrite is what you need, with some inline assembler you could make a digitalWrite that for both constant and variable pin state compiles to 4 instructions/5 cycles:
Code: [Select]
sbrs stateVar, 0
cbi PORTMACRO, PINMACRO
sbrc stateVar, 0
sbi PORTMACRO, PINMACRO
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline Chris C

  • Frequent Contributor
  • **
  • Posts: 259
  • Country: us
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #22 on: July 25, 2015, 01:11:06 am »
Also helpful might be some mention of primitive debugging methods.  Without an initial framework to support you, you might initially lack serial and USB.  Depending on the hardware/software used to program the MCU, you might even lack in-circuit debugging.  Or perhaps any of those methods are too intrusive for what you want to test, skewing the test results.

So at some point, you may find that all you can do to diagnose your code is something simple, like toggling a pin.  In which case a digital storage oscilloscope would be handy to read the results, but maybe you don't have that either.

You can still:

1) Hook that pin up to a LED (obviously).
2) Perhaps the LED is blinking too fast to see, and just looks constantly on?  Try rapidly moving your eyes from left-to-right across it.  Persistence of vision will allow you to briefly see faster signals than you normally could.  Not useful in all circumstances, but I've been able to determine the approximate duty cycle of a PWM this way.
3) Or if the signal is in the audio range, hook the pin up to a little piezo tweeter.  Your ears excel at decoding other information.  For a repetitive signal in the audio range, I can typically detect jitter of just a few percent.
4) You can record audio range signals from the tweeter into a computer or smart phone, giving you some limited oscilloscope functionality.

I get a lot of use out of a $10 frequency counter as well.  Just used it to profile a repetitive interrupt.  Coded a loop to toggle a digital pin as fast as possible.  Ran it once with the interrupt disabled to get a baseline measurement, then again with the interrupt enabled; a little math then gives me the average of how long that interrupt is taking to execute.  Next I tested interrupt latency.  In the interrupt, I recorded the min, max, and average cycles of latency.  Recoded the loop so that once every second, it rapidly blinks three different pins, with the number of blinks being the value of the associated statistic.  By attaching the frequency counter to each pin in turn, I was able to collect the stats.
 

Offline ralphd

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #23 on: July 25, 2015, 02:05:12 am »
So at some point, you may find that all you can do to diagnose your code is something simple, like toggling a pin.  In which case a digital storage oscilloscope would be handy to read the results, but maybe you don't have that either.

For up to 100kHz or so, a modern PC sound card line in can make a decent storage oscilloscope.

A basic cypress-based 8-channel 24msps LA is <$6.
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline peter.mitchell

  • Super Contributor
  • ***
  • Posts: 1567
  • Country: au
Re: Caught up between a rock (Arduino) and a hard (ARM) place.
« Reply #24 on: July 25, 2015, 02:24:26 am »
You should get an ARM devboard that is compatible with ARM Mbed. It provides an Arduino like environment for ARM devices, however, it allows you to interact with all the libraries that make that environment, so you can see what is needed to get started. After using it a while you will stop using the Mbed libraries and just migrate over to your own stuff.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf