Author Topic: Used to Arduino's - How to program a processor for product?  (Read 2178 times)

0 Members and 1 Guest are viewing this topic.

Offline smibaTopic starter

  • Contributor
  • Posts: 13
  • Country: nl
Used to Arduino's - How to program a processor for product?
« on: October 18, 2017, 01:08:58 am »
Hi!

I was thinking about posting this in the microprocessor subforum, but since its such a beginner question I decided this was a better place. If it's not please move it :)

I've finished most of the design of my product and its all working alright, but I would love to have some more control of some of the chips and settings. Right now I can set some basic I2C commands on the bootup of the device which is enough to make it work. But I can't dynamically change settings, it can run a set of predefined commands but not apply logic to them.
Also having a processor with a couple of analogue inputs would allow me to check the voltage of the power lines before I allow the system to continue booting :)

I'm not a programming superstar, but I have enough experience to make this work on an Arduino. What would you recommend for me to use for a production product? What tools are there available? Is there a way to work with just an atmega chip while keeping a friendly interface to do the programming with?

Thanks!
 

Offline TK

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: us
  • I am a Systems Analyst who plays with Electronics
Re: Used to Arduino's - How to program a processor for product?
« Reply #1 on: October 18, 2017, 01:26:41 am »
AVR MCUs can be programmed using C and you will have total control.  All the peripherals are accessible as registers, so basically you are setting/resetting a bunch of bits on different registers.  By peripherals I mean GPIO ports, i2c, SPI, UART and so on.  ATMEL/Microchip offers free IDE for AVR programming.

Depending on your application, AVR MCU can be limiting and you should look for cortex-M MCUs from a lot of vendors like ST Micro, TI, NXP and many others.  All of them offer free IDE.

You can start with the Teensy (3.2, 3.5, 3.6...) that has cortex-M MCU and can be programmed with Arduino IDE, then you can transition to pure cortex-M code.
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12351
  • Country: au
Re: Used to Arduino's - How to program a processor for product?
« Reply #2 on: October 18, 2017, 01:58:03 am »
While the true embedded fan-boys will wince at the idea, there's nothing wrong with implementing an Arduino program on a production platform unless you have efficiency and/or timing constraints that preclude it.  So long as the board you want to use is in the board library and you program within the capabilities of the board, it should be fine.

However, if you want to spin your own board, then things get significantly more "interesting"...
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Used to Arduino's - How to program a processor for product?
« Reply #3 on: October 18, 2017, 02:05:11 am »
Yes, it is actually not that hard to use an AVR chip on its own. You only need to take care of a few things and it will happily do its work. Most AVR chips aren't fussy about the conditions either, so there's quite a bit of room for error. You can make it as simple or complex as you want. Adding a JTAG connector is probably the easiest way to program the chip in your own circuit. The Arduino board has one*, so you can see how that works and figure out the wiring before you make your own attempt.

If you build a board with a JTAG connector, an oscillator circuit consisting of just one crystal and two capacitors, one or two decoupling capacitors and a linear regulator, you basically have an Arduino without the USB capabilities. That sounds like quit a list, but is actually a small number of very doable tasks. The best part is that you get to use the IDE you already know, and the Arduino can be used for testing and as an example. When you get more comfortable with how things work, you can migrate to Atmel Studio for some proper low level control and efficiency. AVR chips are simple enough to understand, but complex enough to do some very interesting things.

One thing to note is that the choice of microcontroller in a production product depends on many things, amongst which your experience with various microcontroller families, cost, power consumption, processing power, licensing and more. However, that tends to be less critical in smaller production runs. If you don't launch a product into a mainstream market with razor thin margins, any chip that gets the job done and doesn't have some prohibitive property, like excessive cost, should do fine.

*Technically the Arduino board has two, but only one for the ATmega328P.
 

Offline hermit

  • Frequent Contributor
  • **
  • Posts: 482
  • Country: us
Re: Used to Arduino's - How to program a processor for product?
« Reply #4 on: October 18, 2017, 02:21:36 am »
Agreed.  The ease of popping DIP version of the chip on the board is a great starting point for learning micro-controllers. 

This guy posts a lot on the Arduino forum and this page will give you lots of what you are looking for.

link
 

Offline TK

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: us
  • I am a Systems Analyst who plays with Electronics
Re: Used to Arduino's - How to program a processor for product?
« Reply #5 on: October 18, 2017, 10:39:23 am »
Also having a processor with a couple of analogue inputs would allow me to check the voltage of the power lines before I allow the system to continue booting :)
This is something that the AVR MCU does.  Even if you have analog inputs, you cannot use it unless the power is already at the level that the MCU needs, so there is no need to program this feature.  You need to take care of when the MCU loses the power, which is controlled by the BROWN OUT detection settings (something similar to a grace shutdown).  Maybe it is already done inside the Arduino Core, but if you do pure AVR coding, you need to control BROWN OUT by yourself.
 

Offline smibaTopic starter

  • Contributor
  • Posts: 13
  • Country: nl
Re: Used to Arduino's - How to program a processor for product?
« Reply #6 on: October 18, 2017, 10:54:46 am »
Thanks! I'll look into AVR chips and Atmel studio!

I'll see what chips are available that suit my needs.

I currently have 3.3V and 1.0V voltages on the board for digital ICs with 8mV ripple or less at very high frequency in the Mhz. Could I simply use these to connect the processor? Not sure how sensitive these chips are to ripple

This is something that the AVR MCU does.  Even if you have analogue inputs, you cannot use it unless the power is already at the level that the MCU needs, so there is no need to program this feature.

There are about 12 different LDO and buck converters on the board and 6 different voltages. Some of them like the main 3.3V are indeed useless to check because the chip itself powers from it, but analogue circuitry will function just fine with their voltages being off... Only not in the way that's expected.
 

Offline TK

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: us
  • I am a Systems Analyst who plays with Electronics
Re: Used to Arduino's - How to program a processor for product?
« Reply #7 on: October 18, 2017, 10:59:47 am »
I currently have 3.3V and 1.0V voltages on the board for digital ICs with 8mV ripple or less at very high frequency in the Mhz. Could I simply use these to connect the processor? Not sure how sensitive these chips are to ripple
3.3V with 8mV ripple should be fine, but you are limited how fast the AVR MCU can run.  It is rated 20MHz @ 5V, I think it goes down to 8MHz for 3.3V.  I am not sure if the AVR MCU is 5V tolerant when run @ 3.3V
 

Offline Fire Doger

  • Regular Contributor
  • *
  • Posts: 208
  • Country: 00
  • Stefanos
Re: Used to Arduino's - How to program a processor for product?
« Reply #8 on: October 18, 2017, 11:55:24 am »
Atmega328 doesn't have JTAG, only ISP.
2.7V-5.5V can go up to 10Mhz (page 2 Datasheet)
1.8V-5.5V up to 4Mhz

Its ok if you want to use Arduino compiler, at the end everything becomes Assembly instructions.
It's not the best solution for many reasons.
But If its gonna work or not its up to you, if you protect your code its up to you, if you use watchdog and Brown Out its up to you.
atmega328P is just like any other MCU, you can tweak every register from arduino IDE.

In conclusion, to make a robust product you will have to get your hands dirty, I would suggest to start with an arduino compatible chip and then start digging into registers.
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2497
  • Country: gb
Re: Used to Arduino's - How to program a processor for product?
« Reply #9 on: October 18, 2017, 12:17:59 pm »
I've finished most of the design of my product and its all working alright, but I would love to have some more control of some of the chips and settings.
Even in the Arduino environment you can drop down to the hardware level by addressing the registers directly so if the 328P meets your design requirement that is no excuse to change.  Arduino or more specifically the "wiring" implementation does introduce some features you may wish to work around or disable... specifically if your code is in loop{} you will find work gets done outside loop (specifically Serial I/O)... you can disable that by never leaving loop.  Additionally you will find Timer0 is working and interrupting in the background to run the millis() behaviour... if you don't need millis() you can disable Timer0 or just leave it as is.  You will also find some functions are painfully slow (e.g. digitalWrite) but you can avoid these by writing to the PORT registers directly. (It's even possible to write down to the assembler level within the IDE if you need to).
Finally, when you get to the product stage you will want to avoid the Arduino Bootloader and program direct to the chip, setting code protection bits as you go to stop the bad guys reverse engineering your killer product.
Good luck!
 

Offline TK

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: us
  • I am a Systems Analyst who plays with Electronics
Re: Used to Arduino's - How to program a processor for product?
« Reply #10 on: October 18, 2017, 12:47:04 pm »
It is true you can reach hardware level with Arduino IDE, but it can change key settings like timers used by delay().  I use direct port manipulation when I need high speed pin access.
 

Offline TK

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: us
  • I am a Systems Analyst who plays with Electronics
Re: Used to Arduino's - How to program a processor for product?
« Reply #11 on: October 18, 2017, 12:48:52 pm »
2.7V-5.5V can go up to 10Mhz (page 2 Datasheet)
1.8V-5.5V up to 4Mhz
This is the information I got from page 2 of the datasheet:

Speed Grade:

0-4MHz@1.8-5.5V
0-10MHz@2.7-5.5.V
0-20MHz@4.5-5.5V
 

Offline Fire Doger

  • Regular Contributor
  • *
  • Posts: 208
  • Country: 00
  • Stefanos
Re: Used to Arduino's - How to program a processor for product?
« Reply #12 on: October 19, 2017, 02:47:06 am »
2.7V-5.5V can go up to 10Mhz (page 2 Datasheet)
1.8V-5.5V up to 4Mhz
This is the information I got from page 2 of the datasheet:

Speed Grade:

0-4MHz@1.8-5.5V
0-10MHz@2.7-5.5.V
0-20MHz@4.5-5.5V
Exactly! Higher clock requires higher voltage. Ofc on 5V everything will work. But if for example you want 10Mhz you must have at least 2.7V. And vice versa if you have 2.7V you can go only up to 10Mhz.

Also keep in mind that if you change the clock then you have to reconfigure every (clock dependent) peripheral and library to work on the new clock to keep the same timing. Arduino runs on 16Mhz and everything is configured for 16Mhz (both hardware and libraries).
Wiring is made to hide this from user so a clean project on Atmel studio maybe is better solution rather than digging in arduino's config files.
Its up to you and what your project needs to decide if you want to go on arduino or Atmel and 3.3V or add 5V.

Check out if there is any 3.3V arduino variant with proper configs (plug n play) and what clock its using etc...
 

Offline TK

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: us
  • I am a Systems Analyst who plays with Electronics
Re: Used to Arduino's - How to program a processor for product?
« Reply #13 on: October 19, 2017, 10:49:49 am »
Check out if there is any 3.3V arduino variant with proper configs (plug n play) and what clock its using etc...
The Seeeduino board has a user selectable 5V - 3.3V switch and it runs the ATMEGA328P @ 16MHz even when 3.3V is selected, and it seems to be running reliably.  I have been using it for years and it is excellent for testing all the sensors that require 3.3V logic.
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2497
  • Country: gb
Re: Used to Arduino's - How to program a processor for product?
« Reply #14 on: October 19, 2017, 11:43:50 am »
The datasheet for the ATmega328P is quite explicit.... to be in the "Safe Operating Area" you need to be at 4.5V or above to operate at 16MHz.   If you are operating at 3.3V and are not hugely timing accuracy dependent then you could just use the 8MHz internal oscillator.  (You can actually still use a 16MHz XTAL and use CKDIV8 to operate safely at 2MHz if that was your sort of thing).    CKSEL fuse bits are used for the different modes  (http://www.instructables.com/id/How-to-change-fuse-bits-of-AVR-Atmega328p-8bit-mic/ shows someone tinkering).  Changing a bootloader to a different frequency is well-doable (necessary if you don't want to confuse your UART and timer rates!)
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Used to Arduino's - How to program a processor for product?
« Reply #15 on: October 19, 2017, 12:37:22 pm »
The datasheet for the ATmega328P is quite explicit.... to be in the "Safe Operating Area" you need to be at 4.5V or above to operate at 16MHz.   If you are operating at 3.3V and are not hugely timing accuracy dependent then you could just use the 8MHz internal oscillator.  (You can actually still use a 16MHz XTAL and use CKDIV8 to operate safely at 2MHz if that was your sort of thing).    CKSEL fuse bits are used for the different modes  (http://www.instructables.com/id/How-to-change-fuse-bits-of-AVR-Atmega328p-8bit-mic/ shows someone tinkering).  Changing a bootloader to a different frequency is well-doable (necessary if you don't want to confuse your UART and timer rates!)
Note that the accuracy of the internal oscillator is dreadful. Even if you're aiming to something very foregiving when it comes to timings, using an external crystal isn't a bad idea.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Used to Arduino's - How to program a processor for product?
« Reply #16 on: October 20, 2017, 06:14:40 pm »
I use Bascom AVR for programming AVR micrcontrollers. If I were starting out from scratch today though I would probably just go with C. Especially if you're used to Arduino, you already almost know C.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf