The MASM Forum

Miscellaneous => Miscellaneous Projects => Topic started by: felipe on October 26, 2017, 04:11:54 PM

Title: Microcontrollers
Post by: felipe on October 26, 2017, 04:11:54 PM
I was reading about what microcontrollers are (didn't know too much about them) and looks that can be fun (specially if you do the programming stuff in assembly and not in a high level language). But the main problem is to design the thing, buy all, etc, etc. It would be better to work in the programming part in a project with more people i guess. Have any of you worked with these toys? For your own or in a colective project?  :bgrin:
Title: Re: Microcontrollers
Post by: Siekmanski on October 26, 2017, 10:07:49 PM
Yes, microcontrollers are a lot of fun to play with. I've done projects using the ATmega's and ATtiny's.
The datasheets are very clear and complete and you can program the microcontrollers in assembly.
You can buy very cheap sensor module kits to make a start using the microcontrollers.
The Arduino's are very populair at the moment and come with a compiler (C/C++) and a lot of libraries and code examples.
I prefer to buy the microcontrollers separately ( they are very cheap +/- $2 ) and program them with the assembler from ATMEL's AVR Studio.
Title: Re: Microcontrollers
Post by: felipe on October 27, 2017, 03:24:27 AM
That's very cool siekmanski. Did you made an artifact that were controlled by the micro if not, can i ask you where did you used the microcontroller?  :icon14:
Title: Re: Microcontrollers
Post by: felipe on October 27, 2017, 04:51:12 AM
I was seeing some PIC microcontrollers. You are right they are very cheap. I think i will start learning the assembly for them and i will use some virtual environment first, to program them. Maybe i can found some job later on that.  :bgrin:
Title: Re: Microcontrollers
Post by: Siekmanski on October 27, 2017, 05:54:41 AM
I have used them in a car computer, CNC machine, dog race timing system ( fully running on an ATmega 328 ), Radio communications etc.
And together with my little nephew we did some funny projects.

I must warn you, once you get started it can become an addiction.  :bgrin:
Title: Re: Microcontrollers
Post by: felipe on October 27, 2017, 12:56:42 PM
That sounds awesome, congratulations!  :greenclp:

Even the part of the addiction sounds awesome.  :biggrin:
Title: Re: Microcontrollers
Post by: dedndave on October 30, 2017, 02:26:38 AM
over the years, i've worked with a few - 8048, 8051, older PIC's

recently, i spent a little money on some arduino "stuff" - i am just getting started, really
i got a few different arduino models, some displays, sensors, and dev kits
i am good to go as soon as i make a little space to work with it - lol
for now, i can get some reading out of the way  :biggrin:

what i find a little overwhelming is that there are so many different boards out there to play with

at first, i dug into the atmega2560 (used on Arduino Mega2560) and the SAM 3X8E (used on Arduino Due)
then, i thought - wait a minute...
if i figure out which chips are used on the different boards,
i can organize my studying to avoid duplicate time and effort
(many of the atmel chips have similar instructions sets, for example)

it was a good experience to just go back and figure out which boards have what features
some of them, i am not really interested in at this time (maybe later)
to give you an example, one of the arduino models is intended to be a game controller of sorts
there are other models that are meant to be sewn into clothing for "gadgets" - whatever - lol

this is a list that i found very helpful - maybe it will help you, too...

http://platformio.org/boards (http://platformio.org/boards)

select page on bottom-left
select number per page on bottom-right
if you select 1000 per page, all boards are on one page
Title: Re: Microcontrollers
Post by: felipe on October 30, 2017, 04:35:48 AM
Thanks dedndave. Yesterday i was reading about the 8051 of intel. Looks pretty good, also there are some good assemblers and simulators for free for it. I also read that for arduino is near impossible to write in assembly for it.

You are right about the "engineering part" of knowing what do you want and then choosing one microcontroller. For now i'm familiarising with the microcontrollers world. When i get ready i will start a real project with one. I'm sure it will be very fun!  :biggrin:
Title: Re: Microcontrollers
Post by: dedndave on October 30, 2017, 04:50:21 AM
not true at all

in fact, newer versions of the arduino IDE support assembly language
the older versions may be modified (changing a few text files) to accommodate assembler

another way is to use an ICE programmer (not very expensive) with atmel's AVR assembler
Marinus was saying that he likes the AVR assembler syntax, etc

both are free to download (only the ICE costs money)

i plan on trying both methods, just to see which is easiest for me
Title: Re: Microcontrollers
Post by: dedndave on October 30, 2017, 04:54:32 AM
.... the 8051 is a fine chip, for it's day
these newer chips do kind of make it obsolete (well, old hat, at least)

for one thing, the 8051's that i'm familiar with were 40 pin dip packages, running 12 MHz max
the 8051 also lacks multiply and divide instructions - you have to write your own

if you want to play, i don't think there's an easier way than an Arduino Uno to get started
they run something like $25   :P

... they use an Atmega328P microcontroller running at 16 MHz
all the docs are available on the microchip website

http://www.microchip.com/wwwproducts/en/ATmega328P (http://www.microchip.com/wwwproducts/en/ATmega328P)

https://www.arduino.cc/ (https://www.arduino.cc/)
Title: Re: Microcontrollers
Post by: dedndave on October 30, 2017, 05:06:41 AM
the arduino IDE

https://www.arduino.cc/en/Main/Software (https://www.arduino.cc/en/Main/Software)

AVR Assembler

http://www.atmel.com/webdoc/avrassembler/
Title: Re: Microcontrollers
Post by: Siekmanski on October 30, 2017, 11:36:44 AM
The cheapest and most direct option is buying these items on aliexpress.com

Search for: isp+programmer ( 1 dollar, incl. delivery costs )
Search for: ATMEGA328P-PU ( 1.50 dollar incl. delivery costs, DIP28 type which can be used with a breadboard )
Search for: breadboard (1 dollar incl. delivery costs) and jumper wires (65 pieces 1 dollar incl. delivery costs)
Search for: breadbord usb power regulator ( 1 dollar incl. delivery costs )

Buy some capasitor and resistor assorted kits and some leds and your ready to start writing your first blinking led project.

You can use the ATMEL avr assembler for writing your asm code and download AVRdude for writing the hex file to your microcontroller via the isp programmer.

Connection Pinout ATmega48P/88P/168P/328P ( and ATmega8 )

(http://members.home.nl/siekmanski/Atmega_basis aansluiting.gif)

Title: Re: Microcontrollers
Post by: felipe on October 30, 2017, 11:50:01 AM
Thanks a lot dedndave. I eventually will find wich microcontrollers to program. I know that arduino is used here in my country. There's also the ARM flavour. I readed that they (the microprocessor's cortex-a series, i think) are in almost every celullar phone in the world (90%).
I think that a lot of microcontrollers of today are based in the 8051.

What i want to do is to know more about this fantastic world, including the assembly language of one of them. Do some programming (i already have done very little of this using mplab-ide for a PIC microcontroller). Then, when i get more serious on a project, i will find the appropiate board and do the whole stuff.  :idea:
Title: Re: Microcontrollers
Post by: felipe on October 30, 2017, 11:51:37 AM
Thanks siekmanski  :icon14:
Title: Re: Microcontrollers
Post by: felipe on November 22, 2018, 12:25:39 PM
Siekmanski i have been studying to learn assembly programming for an ATmega microcontroller. I'm using the avr studio 4.18. Is this version what you use?  :bgrin: Btw, the assembly for microcontrollers is very fun. And interfacing with the i/o world..exciting!  :greensml:
Title: Re: Microcontrollers
Post by: Siekmanski on November 22, 2018, 12:41:33 PM
Yes, I use AVR Studio Ver 4.18.716

What kind of projects have you done?
Title: Re: Microcontrollers
Post by: felipe on November 22, 2018, 01:13:06 PM
Not one yet, i'm beginning to learn. But this time i won't quit. I will try to master a little bit this programming art.  :icon_mrgreen:
Title: Re: Microcontrollers
Post by: felipe on November 22, 2018, 01:18:53 PM
Btw i think the least number, i.e. x.xx.716 is the build number of that version of the avr studio. I can't remember now what version i installed (i mean what build number). It took me a while to find this version because i was looking the version 4 (because i'm learning with a book that uses this version). But i wasn't sure if a version like 4.x.xx was the indicated. Also there are a lot of other versions. I don't have the link of the archive with all those version (which are all free if i recall correctly). But i know it was from a microchip page.
Title: Re: Microcontrollers
Post by: Siekmanski on November 22, 2018, 01:31:09 PM
Good luck, it will be a lot of fun.  :t
Which book are you learning from?
Title: Re: Microcontrollers
Post by: AW on November 22, 2018, 02:08:20 PM
I have used Atmel Studio 7 to make programs in ASM and C, mostly in C, and build them directly to Arduino boards. The advantage is twofold:
1- You don't have to mess with soldering irons which can be frustrating for a software-only guy. Arduino boards are not very expensive, some clones are even less expensive but may not be 100% compatible.
2- You don't have to use Arduino IDE which uses a very high-level sort of C++ which remembers Microsoft Foundation Classes and don't let you know what happens behind the scenes.
Title: Re: Microcontrollers
Post by: daydreamer on November 22, 2018, 10:31:56 PM
Microcontroller is fun,we had oldest intel 8008 cpu,250khz ,many clock cycles for simple operations,first learn and final projects was make something with help of microcontroller+ electronics,some made vectorgraphics game connecting two da converters to x,y inlets on oscilloscope
Its more fun to optimize on slow microcontroller,because each clock cycle matters much more than on a modern 3+ghz multicore
Assembler <-> digital electronic circuits is twoway
Wonder if two da converters,transistor controlling voltage-> analog /digital 16bit resolution could produce a MUL circuit?
Title: Re: Microcontrollers
Post by: felipe on November 22, 2018, 11:15:16 PM
The book name is: "Some assembly required. assembly language programming with the avr microcontroller ". I think is pretty good  :icon14:.
Btw i found the arm arquitecture very interesting  :icon14:. Also there are a lot of books teaching you the assembly language of an arm microcontroller/processor  :icon14:. I like that arm is used in many know devices, like phones, smartphones, tablets and even the raspberry pi  :icon14:. But what i found frustrated is that i couldn't find no one free and reliable assembler for it nor and IDE (mainly because the need for a simulator/debugger) with assembler for it. Keil tools looks great but they are not free  :(. I must suppose that an arm microcontroller is more expensive too  :redface:.
Anyway first i will be coding and learning the assembly for the microcontrollers that i found interesting and that count with a free assembler/simulator/debugger environment. I then, when i can (i'm truly poor right now  :redface:) i will buy all that is needed to donwload the code to a real microcontroller  :icon_mrgreen:.
Title: Re: Microcontrollers
Post by: daydreamer on November 23, 2018, 01:07:54 AM
Felipe,there was earlier a great ARM coder that made 3d game on a 180mhz arm device
Maybe he knows some assembly,maybe there is one cross assembler that can take different opcode data for different cpus

Me going to try the tool I and most are skilled with and make macros for opcodes: the great macro assembler we have here
Title: Re: Microcontrollers
Post by: AW on November 23, 2018, 01:42:33 AM
By far and large the best ARM compiler is the ARM Keil. For learning purposes and knowing we have some limitations on the project allowed size (I think 32KB, but I am not updated on this) it is a free compiler, otherwise it is a very very expensive one. The alternative is the gcc/eclipse route which is much more difficult to tackle with. However, ARM is not as fun as AVR, much less documented which makes it more difficult to learn and with much more families and variations with a significantly higher price. And  trying to embrace it without some background is a pure suicide. Both the Keil and GCC support ASM but it is not intensively used nowadays because microprocessors are faster and have more memory than in the old days.
Title: Re: Microcontrollers
Post by: daydreamer on November 23, 2018, 03:57:42 AM
Z80 assembler and emulator free AW?
I found some dead links, I need emulator because I don't want total car
crash/ restore whole TI calculator all the time
Maybe good idea to share tiny add/ bitshift etc snippets for all who end up with assembly programming cpu with limitations like no div,mul,sqrt, no fpu etc share those mul,div... Snippets between us
Title: Re: Microcontrollers
Post by: AW on November 23, 2018, 04:36:55 AM
Searching for Z80 emulator on google reveals some URLs, but I have not checked them up. May you can refine your search.
Title: Re: Microcontrollers
Post by: felipe on November 23, 2018, 08:04:02 AM
I think aw that you are exaggerating with the difficulty for the arm assembly programming. Also there are good books around and in keil page are good documentation too. The problem with the keil's tools is that i don't know if they support the microcontroller/processor that i want to program.  :idea:
Title: Re: Microcontrollers
Post by: AW on November 23, 2018, 09:04:08 AM
Quote
The problem with the keil's tools is that i don't know if they support the microcontroller/processor that i want to program
Keil belongs to ARM.  :badgrin:

Quote
I think aw that you are exaggerating with the difficulty for the arm assembly programming
All right, good luck then.
Title: Re: Microcontrollers
Post by: felipe on November 23, 2018, 09:16:51 AM
@aw:
Of course i know that.
And i will continue with arm someday, probably...

As you said there are a lot of families and variations, so i don't know if keil supports what i want...Is not that hard anyway  :idea:
Title: Re: Microcontrollers
Post by: felipe on November 23, 2018, 12:49:47 PM
Siekmanski the build version of the avr studio that i have is the 684. So is not the same as you use. Btw, do you like to define (.def) the registers to some name? Like in .def temp =r17. I don't. But i think is ok to equate (.equ) the input/ouput registers, because they are named like literal numbers: like 0x17. So using .equ PORTB =0x17 seems ok to me. What do you think?  :idea:
Title: Re: Microcontrollers
Post by: felipe on November 23, 2018, 01:09:44 PM
Here it is a sample program:
Code: [Select]
.cseg
.org 0

.equ PORTB =0x18 ; Port b's output register.
.equ DDRB  =0x17 ; Port b's data direction
;  register.

ldi r17,0xff ; Configure port b as output.
out DDRB,r17

ldi r16,0x00 ; Init the counter.

lp:
out PORTB,r16 ; Put the count in port b.
inc r16

rjmp lp ; Infinite loop.

I want to explain a little just some instructions (and directives). Just like a service for those who want to get closer with assembly programming with a microcontroller... :idea:
LDI = LOAD IMMEDIATE
RJMP = RELATIVE JUMP
.CSEG = USE THE PROGRAM (FLASH) MEMORY FOR THIS PIECE OF CODE
.ORG  0= START THE PROGRAM EXECUTION IN ADDRESS 0 FROM PROGRAM MEMORY

...Isn't super fun?  :bgrin:
Title: Re: Microcontrollers
Post by: hutch-- on November 23, 2018, 01:38:22 PM
I have seen long ago people who wrote their own assembler for various non x86 hardware and it was usually because the instruction set is nowhere as complicated as the x86/64 sets. Where you have close matching between common mnemonics for a particular processor and the opcodes they represent, the task is not all that difficult as you have the logic,

mnemonic = opcode

and a method of keeping track of the arguments AND basically line numbers for each mnemonic.
Title: Re: Microcontrollers
Post by: AW on November 23, 2018, 06:51:11 PM
In general it is easy to learn those RISC instruction sets. Not so easy for Arm because there are many variations and specificities, if you have a book make sure you do have the specific microprocessor available otherwise you are largely waisting your time.
Title: Re: Microcontrollers
Post by: Siekmanski on November 24, 2018, 01:36:09 AM
Hi Filipe,

A "hello world" example for the Atmega, it's a blinking led. ( the Atmega88 runs on his max. with a 20 MHz crystal )
Included the whole project for AVR Studio and pictures to show the pin connections and a simple 5V voltage regulator.

Code: [Select]
;Siekmanski's led project

.include <m88def.inc>   ; Atmega88 definitions

.equ F_CPU = 20000000   ; Crystal = 20 MHz "cpu clock speed for Wacht-macro"
.include "_wachten.inc" ; Wacht-macro --> _Wacht_us 1000 == 1 milisecond, 1000000 == 1 second


.cseg                   ; Code Segment
.org 0x0000             ; Code load adres 0x0000

    rjmp    Init        ; Make Relative jump to Init Lable


Init:
    ldi     r16,low(RAMEND) ; Init STACK
    out     SPL,r16
    ldi     r16,high(RAMEND)
    out     SPH,r16

    ldi     r16,0b11111111  ; r16 = set all 8 pins as output
    out     DDRC,r16        ; Save in PORTC Data direction Register


Start:                   
    sbi     PORTC,PC5       ; set pin 28 (PC5) high ( led on )

    _Wacht_us 1000000       ; wait 1 second

    cbi     PORTC,PC5       ; led off

    _Wacht_us 1000000       ; wait 1 second

    rjmp    Start

Title: Re: Microcontrollers
Post by: felipe on November 24, 2018, 03:17:21 AM
That's great siekmanski, thank you very much.  :icon14:
Title: Re: Microcontrollers
Post by: AW on November 24, 2018, 03:34:57 AM
For people interested in more recent versions of Atmel Studio this is a snapshot of version 7, which is composed from a Visual Studio Isolated Shell. Very cool.

(https://www.dropbox.com/s/3ey4yfhotc7466a/ProcessorWindow.jpg?dl=1)
Title: Re: Microcontrollers
Post by: Siekmanski on November 28, 2018, 06:37:26 AM
Build your own computer for less than $5.00 and play Music and Demo graphics on an Atmega88 microcontroller ($1.50)  8)

https://www.youtube.com/watch?v=sNCqrylNY-0

Linus Akesson shows you how to do it: http://www.linusakesson.net/scene/craft/
Title: Re: Microcontrollers
Post by: felipe on November 28, 2018, 11:24:26 PM
 :greenclp: This guy is a genius. First i thought, sure he write all in c...but voila, all in assembly  :greensml: Amazing project.  :t
Title: Re: Microcontrollers
Post by: felipe on November 28, 2018, 11:32:52 PM
Ok, i was wrong. There are a few sources in c. But still is a great project.   :icon14:  :icon_mrgreen: