Author Topic: Starting with microcontrollers  (Read 14836 times)

0 Members and 1 Guest are viewing this topic.

Offline akisTopic starter

  • Frequent Contributor
  • **
  • Posts: 981
  • Country: gb
Starting with microcontrollers
« on: June 28, 2014, 11:31:42 pm »
I am thinking of starting with a simple microcontroller for a device that I am making and it seems it would be easier done in programming rather than analogue.

I think the materials I would need would be the programmer and preferably on USB, the PIC itself, and some guides to read. I know C and assembly so the programming aspect should be the easiest bit.

I have looked at the PIC12F1572 (or similar) which is 8 pins only, DIP-8 package, has 4 A/D channels, 1 D/A as well, and it looks simple?

I presume the onboard A/D will allow it to sense various voltages, eg from thermistors, and then take some action onto the A/D channel or may be it has dedicated output pins that it can control?

As an example my need is for a control system to monitor 4 thermistors and depending on the temperature do one of three things: (1) do nothing, (2) increase power (3) decrease power.

Many thanks for any pointers
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Starting with microcontrollers
« Reply #1 on: June 29, 2014, 01:19:26 am »
At a minimum, you will need a chip (the mcu), a power source, a programmer, a compiler and IDE.

PIC has a large installed base but some hardware limitations. The worst of which is a lack of vector'd interrupt controller - you don't get that until PIC24. If I were to start today, I would pick the AVR in the 8-bit land (oro STM8), PIC24 in the 16-bit land and ARM in the 32-bit land.

A power source can be a simple usb charger, or a battery pack.

For PIC, the PICKIT2 is very good but with limited support for new devices - you should check if your particular PIC is supported by it. Otherwise, get a PICKIT3.

XC8 is the latest compiler for newer chips and offers fairly good performance even in the free mode.

A good IDE is a fairly severe downside for PIC. MPLAB X is simply unusable to me in terms of long delays in start-up and at compilation. MPLAB is severely 1980s. Because of that, I usually use PICC compilers and limit myself to older chips.

For AVR, I would recommend CB + gcc-avr / Atmel AVR toolchain + Arduino boards + USBASP programmers, particularly because you have C background. Those arduino boards are incredibly cheap. They have most of the necessary parts on them, like oscillators + regulators + headers - connect a usb cable and you are ready to go. I usually get those boards cheap and blow out the arduino bootloader and use them as AVR boards.

If you have to stay with PIC, I would recommend PIC24 + emBlocks (a variant of CB). It is light years ahead of anything Microchip has to offer.

It is fairly easy to do what you wanted, in either PIC or AVR/Arduino.
================================
https://dannyelectronics.wordpress.com/
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5183
  • Country: ro
  • .
Re: Starting with microcontrollers
« Reply #2 on: June 29, 2014, 01:46:02 am »
avr:  atmega, attiny etc - cheaper programmer, more expensive chips

pic: a more expensive programmer (pickit3), cheaper chips (from about 35 cents and up)

For simple programs, you'll be just fine with mplab x and xc8 compilers. 

I think a Pickit3 is a good investment, it's worth it.

ps. Go straight for a pic16f, no reason to pick a pic12, not much of a price difference.
« Last Edit: June 29, 2014, 01:48:24 am by mariush »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28711
  • Country: nl
    • NCT Developments
Re: Starting with microcontrollers
« Reply #3 on: June 29, 2014, 09:01:05 am »
I'd go for an MSP430. Nicer architecture and better analog performance.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: Starting with microcontrollers
« Reply #4 on: June 29, 2014, 09:30:18 am »
Akis.  I started with assembler and PIC16F84 back when... Now getting good results & fun with PIC24FV32KA304 and MPLABX 2.10 and  PK3 . my C is that of a 4 year old, but that's how you learn, MPLABX seems to run better on XP / win7  I try not to import libraries , write subs and manipulate registers like in asm , I2C, serial , AD , RTCC . no problem.   
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline Fred27

  • Supporter
  • ****
  • Posts: 727
  • Country: gb
    • Fred's blog
Re: Starting with microcontrollers
« Reply #5 on: June 29, 2014, 09:47:25 am »
I'd also go for MSP430, although the main reason for doing so would be the cheap dev kits to get started and the really friendly helpful community at 43oh.com.
 

Offline akisTopic starter

  • Frequent Contributor
  • **
  • Posts: 981
  • Country: gb
Re: Starting with microcontrollers
« Reply #6 on: June 29, 2014, 10:34:30 am »
Thanks for all the replies. I have only just started looking at it and have basic questions:

1) The development kit would be a USB powered device which will communicate with the IDE/compiler/assembler so I could download code to it.
2) The IDE is important and would make life easy with debugging, single step and so on? Can I download a few IDEs before buying anything to see which IDEs are better?
3) Are there simulators so I could plug my IDE to a simulator and execute code without actually having the chip or the development kit? For example the Android development kit offers a simulator so you can try running and debugging your applications on a simulated Android phone (running under Windows).

*****************

In terms of on chip functionality:

1) FLASH is persistent memory that I can write with the aid of the development kit board?
2) RAM is volatile memory used by the CPU
3) oscillator is important so we do not need to add external components
4) A/D is important so the chip can interface with analogue circuits
5) D/A is important so the chip can drive analogue circuits
6) clock and word size (eg 8 bit or 32 bit) is unimportant unless we want to write very complicated applications? For example I cannot even imagine why I would need anything better than a 1MHz, 8 bit device. In the 80s those chips used to power personal computers. Can someone give me examples of what the extra bits/power would be used for?

Thanks
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28711
  • Country: nl
    • NCT Developments
Re: Starting with microcontrollers
« Reply #7 on: June 29, 2014, 10:59:14 am »
6) clock and word size (eg 8 bit or 32 bit) is unimportant unless we want to write very complicated applications? For example I cannot even imagine why I would need anything better than a 1MHz, 8 bit device. In the 80s those chips used to power personal computers. Can someone give me examples of what the extra bits/power would be used for?
Ease of programming. Soft floating point is not a problem when using an ARM for signal processing. Having more CPU power can be the difference between working 2 weeks to optimize an algorithm for integer only processing or spending 5 minutes on linking with a soft floating point library.

edit:typo
« Last Edit: June 29, 2014, 11:42:25 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Starting with microcontrollers
« Reply #8 on: June 29, 2014, 11:04:58 am »
For most of the 8-bit chips, hardware debugging is generally not available or limited - STM8 being one of the exceptions.

32-bit chips aren't superior to 8-bit chips for most of the applications and can be much more of a challenge for a newbie. Starting on 8- or 16-bit in my view is the way to go for most people.
================================
https://dannyelectronics.wordpress.com/
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5183
  • Country: ro
  • .
Re: Starting with microcontrollers
« Reply #9 on: June 29, 2014, 12:25:17 pm »

1) The development kit would be a USB powered device which will communicate with the IDE/compiler/assembler so I could download code to it.

Pickit3 connects through USB and you connect it to your microcontroller on a prototyping board using 4 wires. Easy to program to, easy to read from. it's straight forward. 
Arduino boards have a usb to serial chip (either a ftdi chip or a another atmel chip) and the microcontroller on the board has a built in bootloader which lets the IDE transfer code to the board. If you get a single microcontroller and put it on a prototyping board, you need a programmer.. the serial based ones are cheaper, usb based ones are pricier.

2) The IDE is important and would make life easy with debugging, single step and so on? Can I download a few IDEs before buying anything to see which IDEs are better?

On PICs, MPLAB X is free, you can download it from Microchip. Same for XC8 compiler.  You can play with it without having pickit3 or microcontrollers.  You can also evaluate MikroC Pro for example, to have a feel about other IDEs: http://www.mikroe.com/mikroc/pic/
On AVR, the Arduino IDE is very light. You can download the Microsoft Visual Studio based IDE for AVRs and try that out as well. I don't have much experience on this area, I work mostly with PICs. Mikroe also has lots of stuff for AVR, you can try those as well:http://www.mikroe.com/mikroc/avr/

3) Are there simulators so I could plug my IDE to a simulator and execute code without actually having the chip or the development kit? For example the Android development kit offers a simulator so you can try running and debugging your applications on a simulated Android phone (running under Windows).

On PIC, I didn't have the need for a simulator so I never search for one. AFAIK debugging is a bit limited on 8 bit processors but you can write to a microcontroller and step through instructions and stuff like that.  I know there's something in the MPLABX about simulated chip, but I never tried it. There's third party simulation solutions like Proteus VSM for example : http://www.labcenter.com/products/vsm/pic16.cfm


1) FLASH is persistent memory that I can write with the aid of the development kit board?

Flash is where the binary you make is stored. You can write to Flash using your code, but you have to be careful not to overwrite parts of your binary that's stored in the microcontroller. Also depending on what microcontroller you plan to use, writing to flash is a bit complex and the functions would take up a bit of flash memory so on microcontrollers with very little flash space, it may not be worth it.
If you need to store something in the mcu temporarily, you could use built in eeprom more easily but that one has different characteristics (slower than flash)

2) RAM is volatile memory used by the CPU
Generally there's very little ram on 8bit microcontrollers, the cheapest PICs for example could have as little as 24-32 bytes of RAM.

3) oscillator is important so we do not need to add external components

Most microcontrollers have built in oscillator that's within 1% or less accuracy and stability. If they don't have built in, (at least the pics) you can use a separate oscillator or you can fall back to internal or external RC.

4) A/D is important so the chip can interface with analogue circuits

Most mcus have them. Some of the cheapest or with few pins don't have adc, but you can just check the specs. At least microchip has hundreds of versions and variants.

5) D/A is important so the chip can drive analogue circuits

This.. you have to be careful about. DAC is not as common as ADCs in microcontrollers, fewer mcu actually have it. However, you can produce a variable voltage out of a microcontroller by using PWM and a few external parts, or you can just buy a separate DAC (microchip makes them and they're not expensive) and connect the DAC to the mcu using spi or i2c.


6) clock and word size (eg 8 bit or 32 bit) is unimportant unless we want to write very complicated applications? For example I cannot even imagine why I would need anything better than a 1MHz, 8 bit device. In the 80s those chips used to power personal computers. Can someone give me examples of what the extra bits/power would be used for?

On PICs, the instructions can take more than 8bit in the Flash memory, it's common to see 12bit or 14bit but when you choose a microcontroller the flash memory size is specified in 12bit or 14 bit words so you know exactly how much you could theoretically write in it. For example on this PIC12F1571 you can see it has 1.75KB of flash memory and you see there it says 1KB x 14 bit  so you can in theory write to it 1K of 14 bit instructions.

But when you write C code, you don't care about that, you have the same char, int, long,float etc that are 8bit, 16bit, 24bit etc the only situation where it may matter would be if you want to write to the flash. Only if you write straight assembly you may care about it.

The frequency matters mostly when you have a lot of stuff to be done within a time frame. If you only need to do a few things repeatedly, 1 Mhz may be enough, for other situations you may need more.

On PICs, most instructions take 4 ticks and a few take 2 ticks of an oscillator, so depending on your oscillator frequency you can estimate how much stuff you can do in a second or a time frame.. at 1 Mhz you'd have at best 250k instructions executed in a second

You can do a lot of stuff with 8bit microcontrollers. When you get to more complex stuff, you may want 32bit mcus which are more compiler friendly meaning they have more hardware functions optimized for C compilers and they have some improved functions like interrupt vectors with several levels. Those make for example running a very light operating system possible on such 32bit microcontrollers, whereas it would be very hard if not impossible to run an OS on a 8bit mcu.
Somewhere in between, chips like PIC24f have some dsp functionality or allow you to rearrange the pins the way you like it (there's some 8bit chips lately that also allow you to partially or fully rearrange the i/o pins)


 

Offline lgbeno

  • Frequent Contributor
  • **
  • Posts: 349
  • Country: 00
Re: Starting with microcontrollers
« Reply #10 on: June 29, 2014, 12:46:24 pm »
Checkout the MSP430 Launchpad.  TI has quite a bit of supporting documents and tools as well.

You can also do Energia with MSP430 which is the same as arduino.

Also choosing a micro isn't marriage, try one see how you like it and if it falls short, find another
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 10452
  • Country: nz
Re: Starting with microcontrollers
« Reply #11 on: June 29, 2014, 12:59:02 pm »
6) clock and word size (eg 8 bit or 32 bit) is unimportant unless we want to write very complicated applications? For example I cannot even imagine why I would need anything better than a 1MHz, 8 bit device. In the 80s those chips used to power personal computers. Can someone give me examples of what the extra bits/power would be used for?

As soon as you starting needing to do math on floating point numbers you run into issues with a 8bit cpu.
Floats are 32bits long so the CPU has to do multiple 8bit operations to do one simple add/sub/mul/div on a floating point number.
Now combine that with the fact that most mcus don't have a divide instruction, they simulate it with even more 8bit add/sub/mul/shift operations.

So here you are, trying to code some formula using floating point variables, like maybe
Result = (sqrt((MyFloat1 * (MyFloat2*MyFloat2)) / MyFloat3)) * 3.14159

And suddenly the MCU is bogged down running through 1000's of 8bit add/sub/mul/shift instructions to calculate your one line of C.

The result is understandable, it runs very slow. :D

I'm exaggerating a little, its not quite that bad, but you get the idea.
32bit cpus are much faster to work with 32bit variables :)
« Last Edit: June 29, 2014, 01:05:46 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: Starting with microcontrollers
« Reply #12 on: June 29, 2014, 01:04:40 pm »
Take a look at Microchip  DM240013-2   its a Microstick PIC24FV,  ticks all your boxes , and plugs into a bread board  , has its own programmer / debugger and USB cable and 5V  cost < 20 GBP.
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline Rasz

  • Super Contributor
  • ***
  • Posts: 2617
  • Country: 00
    • My random blog.
Re: Starting with microcontrollers
« Reply #13 on: June 29, 2014, 01:34:59 pm »
just buy few starter kits and try them, most are $5 anyway
something like arduidiotini pro mini +usb programmer is ~$5 on ebay
Who logs in to gdm? Not I, said the duck.
My fireplace is on fire, but in all the wrong places.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Starting with microcontrollers
« Reply #14 on: June 29, 2014, 02:51:36 pm »
Quote
it runs very slow.

Without FPU, the 32-bit chips aren't that much faster t han a PIC18F (or AVR) for floating point math, when the clock speed is matched.

32-bit chips win in terms of execution speed primarily due to their much higher clock speed.
================================
https://dannyelectronics.wordpress.com/
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28711
  • Country: nl
    • NCT Developments
Re: Starting with microcontrollers
« Reply #15 on: June 29, 2014, 03:15:52 pm »
Quote
it runs very slow.

Without FPU, the 32-bit chips aren't that much faster t han a PIC18F (or AVR) for floating point math, when the clock speed is matched.
32-bit chips win in terms of execution speed primarily due to their much higher clock speed.
That makes as much sense as stating that a Ferrari is just as fast as a Model-T Ford when they travel at the same speed  :palm:
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Starting with microcontrollers
« Reply #16 on: June 29, 2014, 03:57:20 pm »
Quote
a Ferrari is just as fast as ...

It depends on the driver. Grandma on her lawnmower can certain outrun you in your Ferrari, for example.
================================
https://dannyelectronics.wordpress.com/
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Starting with microcontrollers
« Reply #17 on: June 29, 2014, 05:05:03 pm »
Thanks for all the replies. I have only just started looking at it and have basic questions:

1) The development kit would be a USB powered device which will communicate with the IDE/compiler/assembler so I could download code to it.
2) The IDE is important and would make life easy with debugging, single step and so on? Can I download a few IDEs before buying anything to see which IDEs are better?
3) Are there simulators so I could plug my IDE to a simulator and execute code without actually having the chip or the development kit? For example the Android development kit offers a simulator so you can try running and debugging your applications on a simulated Android phone (running under Windows).

*****************

In terms of on chip functionality:

1) FLASH is persistent memory that I can write with the aid of the development kit board?
2) RAM is volatile memory used by the CPU
3) oscillator is important so we do not need to add external components
4) A/D is important so the chip can interface with analogue circuits
5) D/A is important so the chip can drive analogue circuits
6) clock and word size (eg 8 bit or 32 bit) is unimportant unless we want to write very complicated applications? For example I cannot even imagine why I would need anything better than a 1MHz, 8 bit device. In the 80s those chips used to power personal computers. Can someone give me examples of what the extra bits/power would be used for?

Thanks
Worrying about word size and MHz is a waste of your time at this point. The first thing you ought to do pick an IDE that you're comfortable with. You're going to be spending 95% of your microcontroller "play time" in that development environment and not so much time actually touching hardware. All microcontrollers can blink LEDs, and most have some sort of analog capability, so pretty much any mcu out there is sufficient for learning the basics.

Pick an IDE that makes you happy (mine is emacs) and let that choice dictate the hardware behind it.
« Last Edit: June 29, 2014, 05:08:47 pm by andyturk »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28711
  • Country: nl
    • NCT Developments
Re: Starting with microcontrollers
« Reply #18 on: June 29, 2014, 06:45:00 pm »
I agree you have to start somewhere but choosing a microcontroller based on the IDE is like chasing blinking beads and mirrors. Some IDEs may take some time to learn. The bottom line is: there is a good IDE available for every microcontroller so the IDE doesn't need to drive the choice for a certain controller.
I'd look for a good path into the future where more demanding requirements don't mean changing to a completely different architecture. At the moment ARM based controllers cover the widest range of microcontrollers you can get. From 8 pin DIP to >200 pin BGA. IMHO getting a simple low end ARM controller up&running isn't any different from getting an MSP430 going.

edit:
I think it is a good idea to get some starter kits for several ARM controllers from different brands and start with those. When I looked into switching from MSP430 to ARM I played with controllers from several different first before settling on one particular brand. There is a huge difference in ease of programming the flash, quality of documentation, quality/useability of the peripherals, etc.
I  know I wrote about the MSP430 before but that may run out of steam if projects get more complicated. It is easier to use an ARM controller for an easy task than to use an MSP430 for a difficult task.
« Last Edit: June 29, 2014, 07:31:00 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Starting with microcontrollers
« Reply #19 on: June 29, 2014, 09:39:54 pm »
I'd look for a good path into the future where more demanding requirements don't mean changing to a completely different architecture. At the moment ARM based controllers cover the widest range of microcontrollers you can get.
I was resisting the urge to say (again), "Go buy yourself a STM32 disco board for $15 and be done with it."

That tends to bring out the torches and pitchforks around here. Or should I say PICforks.  >:D
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28711
  • Country: nl
    • NCT Developments
Re: Starting with microcontrollers
« Reply #20 on: June 29, 2014, 10:12:27 pm »
Based on what I have read in similar threads the microcontrollers from ST don't seem like a good place to start. Some call their libraries and peripherals complicated. Recently I looked at the LPC800 from NXP. NXP claims they have made this controller as simple as possible to be an easy start. The ROM in this controller contains drivers for the PLL, UART and I2C interface.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Starting with microcontrollers
« Reply #21 on: June 30, 2014, 01:55:06 am »
NXP claims they have made this controller as simple as possible to be an easy start. The ROM in this controller contains drivers for the PLL, UART and I2C interface.
Sounds a bit like the Tiva chips from TI (ARM Cortex M4F). They have a fairly extensive library of code in ROM, including drivers for pretty much every peripheral. You don't have to use the library routines, and they don't take up any flash.

The LPC800s appear to have a GPIO switch matrix meaning you can assign just about any peripheral to almost any physical pin. That's a super-handy feature and also very nice for beginners, especially if you're building your own boards. The Nordic nRF51 chips (Cortex M0 + bluetooth) have the same kind of thing. The nRF isn't beginner friendly though.

The PSoC4 series from Cypress (yet another Cortex M0) is also worth considering for beginners. It's got the same GPIO switch matrix, and even allows you to route analog signals too. They offer a $4 bare-bones dev board, a fancy $25 version with an on-board debugger. But as I was saying before, the accessibility of the development environment is more important than the silicon when you're starting out.  Fortunately, PSoC Creator is easily one of the best microcontroller IDEs I've seen.

It comes bundled with GCC 4.7 and is a really smooth ride for simple demo projects written in C. Compared to other OEMs, I think Cypress cares more about their IDE because it's required to access any of the unique functionality of Cypress' silicon. It's not an afterthought, and it's not a revenue center.

You can export projects to IAR and Keil, but you still have to do the signal routing in PSoC Creator. It comes with tons of "datasheets" for virtual components that are built up from verilog and generated C code. Sounds scary, but it works really well.

Check out the PSoCs!
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
Re: Starting with microcontrollers
« Reply #22 on: June 30, 2014, 05:22:46 am »
Sounds a bit like the Tiva chips from TI (ARM Cortex M4F). They have a fairly extensive library of code in ROM, including drivers for pretty much every peripheral. You don't have to use the library routines, and they don't take up any flash.

But like with all ARM based processors it is not a walk in the park. TI screwed up a few things when moving/rebranding the library from SellarisWare to TivaWare, in addition to what they already had screwed up in StellarisWare. And the documentation is also typical. Incomplete, written in a hurry, and with the attitude that the MCU was hard to build, so it should be hard to use. Nothing out of the ordinary, but using the ROM functions essentially forces you to use TivaWare, because the ROM functions are just copies of the TivaWare functions.

Among the things I check when looking for a MCU, despite cost, fit for the purpose, etc., is availability of a command-line toolchain (so it can be integrate in our build system and whatever IDE we want), and documentation. And lots of example code. I am not a fan of blindly copying code without understanding it, instead code examples for me are to cross-check and clarify the documentation.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline bwat

  • Frequent Contributor
  • **
  • Posts: 278
  • Country: se
    • My website
Re: Starting with microcontrollers
« Reply #23 on: June 30, 2014, 06:01:47 am »
Among the things I check when looking for a MCU, despite cost, fit for the purpose, etc., is availability of a command-line toolchain (so it can be integrate in our build system and whatever IDE we want)

Same here. Some of us were taught not to just write code if we could write code that writes code instead. So, I've got lots of little languages that generate C code which in turn gets compiled by the target compiler. This needs something like make. If I can't get at the compiler and linker from the command line then it's restrictive.
"Who said that you should improve programming skills only at the workplace? Is the workplace even suitable for cultural improvement of any kind?" - Christophe Thibaut

"People who are really serious about software should make their own hardware." - Alan Kay
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: Starting with microcontrollers
« Reply #24 on: June 30, 2014, 06:15:13 am »
Same here. Some of us were taught not to just write code if we could write code that writes code instead. So, I've got lots of little languages that generate C code which in turn gets compiled by the target compiler. This needs something like make. If I can't get at the compiler and linker from the command line then it's restrictive.
Make? Code generators? We're talking about blinky and noobs here. Don't make 'em cry!
 

Offline eneuro

  • Super Contributor
  • ***
  • Posts: 1562
  • Country: 00
Re: Starting with microcontrollers
« Reply #25 on: July 01, 2014, 01:34:50 am »
avr:  atmega, attiny etc - cheaper programmer, more expensive chips

Even this AVR ATTiny85 could do this job, with fast PWM on PB1 for power control or use PB1,PB0 for software I2C ;)

It has 4 ADCs, but to use ADC0 on RESET pin High Voltage programmer may be needed for development if program reflash needed in the case of bugs.
However, it is possible write its 8KB flash (512 bytes SRAM) using... old laptop with LPT port and a few resistors  in AvrDude DAPA mode, using text editor to write C source code and compile under Linux of course >:D
AVR Microcontrollers in Linux HOWTO
Sometimes such simple tools have advantage-you know exactly what optimisations are made and what is passed to the compiler if you can do it in a few shell commands or from makefile.
Just finishing another project and pushed next ATTiny85 to the limits, but its 2 timers in fast PWM mode work as expected, so another DIP8 monster switched to internal 8 MHz clock is ready to go  8)
12oV4dWZCAia7vXBzQzBF9wAt1U3JWZkpk
“Let the future tell the truth, and evaluate each one according to his work and accomplishments. The present is theirs; the future, for which I have really worked, is mine”  - Nikola Tesla
-||-|-
 

Offline akisTopic starter

  • Frequent Contributor
  • **
  • Posts: 981
  • Country: gb
Re: Starting with microcontrollers
« Reply #26 on: July 01, 2014, 08:59:23 pm »
My simulator supports the PIC16F84 complete with assembler, C compiler, debugger and sample sims. So I decided to start looking at the PIC16F84 first. I downloaded the reference manual and I must admit with over 30 years professional experience starting with Z80, 68000, 80386 - I am finding this manual the most stupidly and badly written piece of trash. Which must say a lot about the company behind it.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Starting with microcontrollers
« Reply #27 on: July 01, 2014, 10:54:56 pm »
Quote
I am finding this manual the most stupidly and badly written piece of trash.

I think consensus seems to be that Microchip and Atmel both make fairly good datasheets.

Quote
Which must say a lot about the company behind it.

Or the folks making that statement.

Or both.

================================
https://dannyelectronics.wordpress.com/
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5183
  • Country: ro
  • .
Re: Starting with microcontrollers
« Reply #28 on: July 01, 2014, 10:57:55 pm »
What do you mean by "reference manual", the datasheet or something else?

I actually found the datasheet quite easy to understand, but I wasn't "damaged" by older architectures.

// ps. The PIC16F84 is ancient. You really should look into something more modern.
« Last Edit: July 01, 2014, 11:01:03 pm by mariush »
 

Offline boz

  • Regular Contributor
  • *
  • Posts: 79
  • Country: nz
    • Roving Dynamics Ltd
Re: Starting with microcontrollers
« Reply #29 on: July 01, 2014, 11:50:58 pm »
I'm the biggest Microchip Fanboy there is but seriously just get a base Arduino UNO

1. The IDE is a bit simple and crappy but it works out of the box and its also real "C" your programming in just like the big boys
2. There is a big community geared to newbies while you learn. (no ones going to jump on you if you ask a dumb question)
3. Its cheap (about $15 for a UNO clone)

Dont bother with anything more complicated yet such as an arduino mega, nanos or PIC ARM 'duino clones or you just end up with frustration due to 3.3V vs 5V or other silly issues, once you have got the basics you can move on to bigger/better AVR's PIC's, 430's or ARMS.
Fearless diver and computer genius
 

Offline akisTopic starter

  • Frequent Contributor
  • **
  • Posts: 981
  • Country: gb
Re: Starting with microcontrollers
« Reply #30 on: July 02, 2014, 12:01:49 am »
What do you mean by "reference manual", the datasheet or something else?

I actually found the datasheet quite easy to understand, but I wasn't "damaged" by older architectures.

// ps. The PIC16F84 is ancient. You really should look into something more modern.

No,  I am talking about the manual and the way it's thrown together, not the architecture which I can not express an opinion on as I have not seen enough of them.

I am reading now the Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf and it's so much better (the document, not the architecture).

 

Offline Kremmen

  • Super Contributor
  • ***
  • Posts: 1289
  • Country: fi
Re: Starting with microcontrollers
« Reply #31 on: July 02, 2014, 06:34:44 am »
I'm the biggest Microchip Fanboy there is but seriously just get a base Arduino UNO

1. The IDE is a bit simple and crappy but it works out of the box and its also real "C" your programming in just like the big boys
2. There is a big community geared to newbies while you learn. (no ones going to jump on you if you ask a dumb question)
3. Its cheap (about $15 for a UNO clone)

Dont bother with anything more complicated yet such as an arduino mega, nanos or PIC ARM 'duino clones or you just end up with frustration due to 3.3V vs 5V or other silly issues, once you have got the basics you can move on to bigger/better AVR's PIC's, 430's or ARMS.
+1 to this thought. And if you wish to improve on 1. above, there is a solution: grab the free Atmel Studio 6.2 and install the free Arduino extension from Visual Micro (available directly from inside AS 6.2 in the Tools/Extension Manager dialog). That links the AS 6.2 to Arduino IDe and then you can write you code in a "proper" IDE which is miles ahead of the original Arduino environment.
Nothing sings like a kilovolt.
Dr W. Bishop
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: Starting with microcontrollers
« Reply #32 on: July 02, 2014, 08:34:08 am »
Akis   You seem to be starting from a strange angle, what is your purpose ?, learning about mcu from a software aspect  , for a particular hw project  or just to get up to date. you mention sim , this will help with finding bugs, but will not take the place of actual hardware, you can sim  turning on a LED , but that's not to say it will actuall be ON .   I also came from Z80 to 16F84 and you can do loads with it but not what you had in your list ?  the "Manual" data sheet is basically a list of registers and how to set them up and use them , no more .  I learned from code examples for asm and C

Looks like some good advice posted below ....
 
boz, I am the biggest MC fan :)
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline akisTopic starter

  • Frequent Contributor
  • **
  • Posts: 981
  • Country: gb
Re: Starting with microcontrollers
« Reply #33 on: July 02, 2014, 10:11:25 am »
After I decided to look into MCUs I discovered that my real-time, interactive simulator supports the PIC16F84A, complete with assembler/C compiler, real time debugging etc. Since I have to start from somewhere I thought it would be a great idea to go with what my simulator already provides, including samples, assembly files, ROM files, configuration files etc. I also downloaded MPLAB X but the simulator is so much better for just starting on a basic circuit, modifying the assembly file, running again etc

After a while I needed the PIC16F84 reference manual to understand what the assembly was doing but I did not like it (hence my comments), so I gave up on it.

As per your suggestions I started looking at the ATMEL tinyAVR ATiny25/45/85 which has a very nice datasheet (should be called reference manual but anyway).

Once I am more familiar with MCUs my first project is to monitor 4 temperature sensors and then nudge up or nudge down the power of an amplifier. Because there is a lot of lag between changing the power and sensing some temperature change, it may even be an inverse correlation for a while, in other words, you sense the temperature is too high, you lower the power, and the next X readings are even higher. So unlike a current limit implementation where we adjust the current to stay below a level, and the feedback is instant, with temperature sensing the feedback is very very slow. If I employ an analogue solution, similar to current limiting, as soon as the temperature exceeds a threshold, the analogue system would switch the power off completely, because it will not be getting a quick feedback. So the device will be working in a "full power on" - "power totally off" cycle, which may succeed in keeping the temperature below a threshold, but is not what I want. So I thought an MCU would cope with this much better.

As an example:

1) get temperature reading
2) if temperature greater than X, decrease power by 10%
3) if temperature lower than Y, increase power by 10%
4) wait 10 seconds

That simple algorithm may produce better results than I can do in pure analogue, although I am sure it can be done in analogue with clever circuitry.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28711
  • Country: nl
    • NCT Developments
Re: Starting with microcontrollers
« Reply #34 on: July 02, 2014, 10:18:23 am »
This sounds like implementing a (PID) control loop. It may take some math to get that working properly though. May I suggest the book 'Applied control theory for embedded systems' by Tim Wescott?

OTOH with some understanding of control theory this problem can be tackled by analog circuitry as well.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline akisTopic starter

  • Frequent Contributor
  • **
  • Posts: 981
  • Country: gb
Re: Starting with microcontrollers
« Reply #35 on: July 02, 2014, 10:47:12 am »
Maybe there is a simple and completely analogue solution. I have experimented with adding RC delays to forbid the circuit from going fully on or fully off, but with little success. Here is the thread I have just posted, more knowledgeable people than me might have solutions.

https://www.eevblog.com/forum/projects/control-system-with-feedback-time-delay/
 

Offline Monkeh

  • Super Contributor
  • ***
  • Posts: 8207
  • Country: gb
Re: Starting with microcontrollers
« Reply #36 on: July 02, 2014, 10:49:54 am »
I am reading now the Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf and it's so much better (the document, not the architecture).

Take a look at the MSP430 documentation.

www.ti.com/lit/ug/slau144j/slau144j.pdf
www.ti.com/lit/ds/symlink/msp430g2553.pdf
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28711
  • Country: nl
    • NCT Developments
Re: Starting with microcontrollers
« Reply #37 on: July 02, 2014, 10:57:06 am »
Maybe there is a simple and completely analogue solution. I have experimented with adding RC delays to forbid the circuit from going fully on or fully off, but with little success. Here is the thread I have just posted, more knowledgeable people than me might have solutions.

https://www.eevblog.com/forum/projects/control-system-with-feedback-time-delay/
For this problem you need to understand/use control theory otherwise you are not going to crack it. Because of the huge lag between adding heat and sensing it you probably need some feed-forward compensation as well. If you know the thermal capacitance of what you are heating you can make an estimate on the temperature based on the amount of energy you put into the 'system'.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Starting with microcontrollers
« Reply #38 on: July 02, 2014, 10:57:49 am »
Quote
So I thought an MCU would cope with this much better.

What you want is a PID loop, which can be done either digitally (via an mcu for example) or analogly - tons of examples there as well.

If you do it digitally, it can be implemented with either full-on/full-off, or via pwm. Either way, not much of a difference.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf