Beginner looking for recommendations

Thread Starter

Wendy

Joined Mar 24, 2008
21,848
@djsfantasi

I have no favs in micro controllers, don't know enough about them. In my time I have programmed Z80 Assy and 6502 Assy, so I'm not a complete novice in coding.Having said that I find learning a new language intimidating.

I would like to code a simple 4-6 digit counter for a possible commercial application. It needs to be fast and simple, with a latch and hold. Think freq counter. As in the heart of several pieces of test equipment. Stick with the counter and display

So first question: What is the simplest and most documented platform I can use?

I could use websites too, as well as major help. I think I can work through my brain fog, but I'm not going to be able to do hardware experiments for what could be a very long while. If you help me be prepared for a very short attention span. I may drop it to chase a different squirrel with little to no notice. Just saying.

With all of that said, any takers?
 

dl324

Joined Mar 30, 2015
8,962
I recently bit the bullet and got an Arduino Uno. I was buying some ULN2803 at Tayda Electronics and somehow I ended up looking at an Arduino Uno workalike for $5.99 (the genuine is closer to $22). I couldn't wait for it to arrive and had already written a program to blank check some PROMs when it arrived. I had originally planned to put some counters and logic on a bread board, but I have half a dozen different PROM types and it would have been more work than the Uno.

It was much easier to do that using Uno versus something like Raspberry Pi Zero (which I've also started using because my Arm based SBC of choice is no longer available). Unfortunately, it looks like all of the PROMs are programmed and now I need to determine how much blank space they have and if any have duplicate code. That's going to be a job for Pi because it will be easier to manipulate the data than with Uno.

I have a couple new tools in my tool box now, so I'm happy.

The Arduino forum sucks. I can't believe how hard it is just to post a picture and they impose posting and editing restrictions until you get to 100 posts. Raspberry Pi forums aren't much better and the folks there aren't interested in making *any* enhancements. AAC and another forum I used to be a moderator on spoiled me.
 

jpanhalt

Joined Jan 18, 2008
7,931
If you plan to use Assembly and just for a 6-digit counter, you might also consider the mid-range or enhanced mid-range PIC's. The BCD routines are readily available and MPASM is rather intuitive. If you already can do C, then what you use probably doesn't matter.
 

jpanhalt

Joined Jan 18, 2008
7,931
Look up any PIC device (e.g., PIC16F1829) and check out the instruction set. I found them pretty intuitive and with help from one of the many tutorials, that is all I used to get started. Once that first LED flashed, I rarely turned back to the tutorials.

Here is a link to the Microchip manual for mid-range chips: http://ww1.microchip.com/downloads/en/devicedoc/33023a.pdf

You will want Section 29, which describes the mid-range instructions and gives more examples than you will find in the datasheets. Enhanced mid-range devices have only a few additional and quite helpful instructions to learn, but but the syntax, destinations, and so forth are identical.
 

djsfantasi

Joined Apr 11, 2010
5,621
Since you’re familiar with assembly, the Pic should be up there on your list. I’m investigating that platform, but have no experience.

I’m most familiar with the Arduino and microprocessors that support the Arduino IDE. Such as the ATTinyxx.

Learning Arduino C is fairly easy. First step is understanding the basic structure of a sketch (Arduino-speak for program).

The IDE has sample code for almost every feature, from which you can learn the language. And if you add devices (shields in Arduino-speak) they usually come with a library of routines and (again) sample code.

Sparkfun and Adafruit are two great resources. And in addition to the Arduino forum (of which I’ve never had an issue), they also have great forums. Their shields greatly expand the capabilities of the Arduino. LCD displays, real-time clocks, servo/motor drivers, current monitors, SD card support, MP3 music support with/without amplifiers,... are some peripherals

There is also a language reference manual on the official web site.

You can even develop in the IDE and use an Arduino to program a bare chip.

I’d say not knowing C is a potential roadblock. But the ease of use (free IDE, no programmer required, vast support) may ameliorate this issue.
 

danadak

Joined Mar 10, 2018
3,578
Another consideration is PSOC. Its a System on Chip solution, lots of analog
and digital, down to gate level, or LUT or high level like PWMs, Counters, Timers,
MSI like library, A/D, D/A, Vref, Mixer, Muxes........

You can do code less designs where you drag and drop components onto design
canvas, wire them up to each other internal and to pins, and hit the build button.
Generates startup code all designs need and then programs part. A component
is an onchip resource, catalog for 5LP parts attached. PSOC 4 family a subset of
catalog. Each component (except simple gates) you right click to config. Each
component accompanied by APIs to do f() calls in C if you want to alter in code
the parameters you set. Like one would do if changing PWM values, or using COM
in/out of chip.

Here is freq cntr example (again, one chip, notice right hand column tons of resources
unused) -

upload_2019-6-18_7-52-49.png

Note, above design done at 16 bits, just as easily could have been 32 bits.


Tool, IDE, PSOC creator, and compiler free.


Regards, Dana.
 

Attachments

Last edited:

DickCappels

Joined Aug 21, 2008
5,897
Just a couple words of encouragement: You are going to find modern integrated microcontrollers a delightful departure from the old days of the Z-80 and the MOS6502. For one thing, you don't need to wire five or six chips together in order to have a minimum system, and for another you don't need that UV light to erase those EPROMs anymore! The days of having a tray of a dozen or more EPROMs on hand so you can try quick code revisions are past!

Don't be intimidated by the idea of learning a new instruction set. The main thing is that you know that certain features are necessary and can be done somehow. If you don't remember the instruction just look at the instruction set card until you spot one doing what you need done.

If you ever venture off into C or another high level language for microcontrollers you will note that you can do everything necessary in that language. And it is sure a lot easier than pasting in multiprecision math routines. You can leave that until later.

There was about a 20 year gap between the last time I wrote code for a commercial project and retirement when I had a chance to dip my toes into assembly language again. For the record, I was an architect so I was not very hands-on during those years. After retiring one of my past employees told me told me about AVR controllers. Coming from mostly 6502/Motorola chips the AVR seemed a bit strange and even seemed limiting in some ways, but it was capable of doing everything I was accustomed to doing with those other architectures. It is still my favorite today.

Looking over at the other side of the fence I coveted the rich selection of peripherals available on PIC controllers. For a long time I the number of clock cycles per instruction turned me off, but since then they have boosted the clock rates to the point that it doesn't matter anymore.

I think that if you go with PIC or AVR you will find a rich assortment of examples to examine as well as great access to experts in their. Not sure what the others offer.

In any case, the main point is that you know how microprocessors work and that's all you need to know about microcontrollers to begin with. That, and you won't need that UV lamp again.
 

danadak

Joined Mar 10, 2018
3,578
Note if you do a freq cntr its easy in PSOC to do a gate operated counter
or a reciprocal cntr if measuring really low frequencies. In fact you could
easily make a dual purpose counter with intelligent switching between
modes.

More than you want to know about counters, attached.


Regards, Dana.
 

Attachments

MrChips

Joined Oct 2, 2009
19,280
I do have my personal biases hence at the risk of sticking my neck out on the chopping block here are my recommendations.

If one is looking into becoming an embedded design engineer then learn ASM first.
If one wants to get a project up and running fast, then learn C.

Here are my preferences for learning ASM in no order of preference:

Microchip/Atmel AVR
NXP/Freescale MC9S08
Texas Instruments MSP430

(There are other MCU manufacturers with which I have no experience.)
 

pmd34

Joined Feb 22, 2014
368
I would go for Atmel AVR for sure, something like the ATmega 48.. family.
- You can buy all the programmers, demo boards, ICs etc.. very cheaply from china.
- The AVR studio is a very nice tool to play with, and takes care of the compiling AND programming, as well as allowing you to do in system debugging, (plus its FREE!) so for example you can pause your code and see if your counter is reading what it you think it should be and also check the states of your output pins.
- A big plus is that the data sheets were very well written and also often include some example code to get you going.
- Most of the Arduino boards use the Atmega chips, so there is a huge amount of information available online for people using the ICs and if you come across a problem, or want to know how to do something then its extremely likely there is something on the net to tell you how to do it!

For example.. searching for "ATMega frequency counter" there is no shortage of hits.
 

MrChips

Joined Oct 2, 2009
19,280
Best of all, AVR architecture and machine instruction set make a lot of sense.
However, there are a few things to watch for, which I can provide later in more detail.

The first that comes to mind is the reverse syntax:

operation destination, source
 

Thread Starter

Wendy

Joined Mar 24, 2008
21,848
I do have my personal biases hence at the risk of sticking my neck out on the chopping block here are my recommendations.

If one is looking into becoming an embedded design engineer then learn ASM first.
If one wants to get a project up and running fast, then learn C.

Here are my preferences for learning ASM in no order of preference:

Microchip/Atmel AVR
NXP/Freescale MC9S08
Texas Instruments MSP430

(There are other MCU manufacturers with which I have no experience.)
Is ASM CPU Op Codes?
Where can I find website literature? No matter which route I go I have some serious studying to do. MCU stands for?(Micro Controller Unit?)
 

DickCappels

Joined Aug 21, 2008
5,897

MrChips

Joined Oct 2, 2009
19,280
I was a big fan of Motorola => Freescale now owned by NXP.
I worked with all the families

6800 > 6802 > 6805 > 6809 > 68000 > 68HC11 > 68HC12 > 9S08

Hence it was easy to migrate from one family to the next, and even on to Atmel AVR.

The native language of the MCU (Micro Controller Unit) is machine code = CPU op code. This is one, two, or three bytes of binary data. You do not need nor want to work at this level.

The next step up is to write programs in assembler code (ASM).

For anyone now starting out, this is my #1 recommendation:

Understanding Small Microcontrollers

Read this and it will provide you with a solid foundation into the world of microcontrollers.
 

MrChips

Joined Oct 2, 2009
19,280
If you are starting afresh you do not need to know this. However, if you have some insight to ASM coding you will be able to follow the differences. (You may come back to this at a later stage.)

(The text was copied from a webpage with tables. The column format has been lost on the AAC fora. I have entered = to show the column break.)

Converting HC11 code to XAVR code

To a very large extent it is very easy to convert HC11 code to AVR. Most instructions have a direct equivalent. To make life easier, many of the HC11 mnemonics have been retained in the XAVR assembler. For example, BSR, JSR, RCALL and CALL generate the same code on the XAVR. [Edit: I wrote an assembler called XASM for the Motorola MCU families. This was ported to XAVR for Atmel AVR.]

Here are some examples of direct translations from HC11 to AVR.

HC11 Syntax = AVR Syntax
Immediate Addressing
LDA #$3F = LDI A $3F
CMPA #98 = CPI A 98

Direct RAM addressing
LDA num = LDS A num
STB num = STS num B

Indexed Addressing
LDA 0,Y = LD A Y
LDA 1,Y = LD A Y 1
STA 0,Y = ST Y A
STB 1,Y = ST Y 1 B

Register-register operations
TAB = MOV B A
TBA = MOV A B

Register Operations
CLRA = CLR A
PSHA = PUSH A
PULA = PULL A

Input/Output
LDA #$FF = LDI A $FF
STA PORTD = OUT PORTD A

LDA PORTB = IN A PINB

Note that in general the AVR syntax is: operator destination source
 

Lo_volt

Joined Apr 3, 2014
80
If you're stiaying with programming in assembly, the PIC's won't be far different than the z80. You'll have no problem picking up the PIC assembly language.
 

MrChips

Joined Oct 2, 2009
19,280
(This post is for the record. You can come back to this later.)

Idiosyncrasies of the AVR instruction set


1. Set/Clear Interrupts - This is actually an idiosyncrasy of the HC11 MCU. The HC11 uses an interrupt MASK. Therefore CLI clears the interrupt mask (enables interrupts) and SEI sets the interrupt mask (disables interrupts). With the AVR, SEI enables interrupts and CLI disables interrupts.

2. Unlike the HC11, the LD and ST instructions do not affect the flags in the status register. In order to branch on a zero/non-zero or positive/negative value of a variable loaded from RAM you must use the TST instruction first, for example:

HC11 Syntax = AVR Syntax

LDA num = LDS A num
BEQ iszero = TST A
= BEQ iszero


3. An input port uses a different address (e.g. PINB) from the output port (e.g. PORTB). Reading the input port reads the actual logic input at the input pins.

4. Arithmetic and Logic instructions are not available on all 32 registers. Registers 16 to 31 are privileged as most instructions apply to these. Reserve these as your general purpose registers. Registers 26-27, 28-29, 30-31 are used for indexed and indirect address and should be reserved for these purposes.

The following instructions are not available on registers 0-15:

LDI CPI ANDI ORI SUBI SBCI SBR CBR SER


5. The instructions CLR (Clear Register) and SER (Set Register) are of questionable value.( Both of these are not extra instructions in any case since CLR is actually EOR reg,reg and SER is LDI reg,$FF).

6. Skip on register bit set or clear (SBRS, SBRC) can be useful instructions. Unfortunately, the instructions to set and clear register bits (SBR, CBR) do not use the bit-number but use a bit-mask instead. This means that programs have to create constants for both the bit-number as well as the bit-mask. (Note that SBR is the same as ORI in any case). It would have been nicer to have SBR and CBR use a bit-number just as the SBI and CBI instructions.

7. Set and Clear bit in I/O register (SBI and CBI) and Skip if Bit in I/O register is Set or Clear (SBIS and SBIC) operate on I/O addresses 0 to 31 ($00 to $1F) only. You cannot use these instructions on registers involving the timers, input capture, output compare, interrupt flag and mask, MCU control register, watchdog timer and the status register.

8. An ADDI (Add Immediate) instruction is noticeably missing and would be desirable.

9. A LDI (Load Immediate) and CPI (Compare with Immediate) on all registers would have been nice. This would have allowed all of the registers to be usable as general purpose registers.

10. ADIW (Add Immediate to Word) and SBIW (Subtract Immediate from Word) have four idiosyncracies:

  1. They operate on a pair of registers (16 bits).
  2. Only registers 24-25, 26-27, 28-29, 30-31 are allowed.
  3. The immediate value is restricted to 6 bits (0-63).
  4. Register pair 24-25 is of questionable value.
11. Register-0 is the implied destination of the LPM (Load Program Memory) instruction.

12. The SBC (Subtract with Carry) instruction does not change the Z-flag if the result of the subtraction is zero. If the result is non-zero the Z-flag is cleared.
 

Thread Starter

Wendy

Joined Mar 24, 2008
21,848
OK, my experience with interrupts is minimal. Most of my assy coding was short subroutines to speed up BASIC code.So where do I find the opcode set so I can begin my first baby steps in assy. Starting off what is the CPU I should plan on using? A website would be great. Thank you.

As I understand it 6502 and 6800 CPUs are cousins, correct?

BTW I still think in BASIC.
 
Top