Jump to content
IGNORED

Microcontroller programming


Vorticon

Recommended Posts

Hi.

My current mad scientist TI interfacing project requires the use of a microcontroller. From what I have gleaned from the net, most current microcontrollers can be programmed in C/C++, so here's my question:

Do I really need C++ or can I just stick with C? I have programmed in C before (TI Lander), so it will only take a quick review to get back up to speed. On the other hand, I have never learned C++, and I would rather not spend time on it if I don't have to.

Any thoughts?

Link to comment
Share on other sites

No, C is good enough for most things in the embedded wold. Unless you're doing UI's or extremely modular stuff, I see no reason to use C++

 

Ah good to know. I'll stick with C then.

Frankly, I intensely dislike C and all its variants for some likely irrational reason. I just never warmed up to it, perhaps because my first structured high level language after Basic was Pascal, and C feels very cryptic compared to Pascal. Surprisingly, Forth was far more fun to work with than C despite its quirky approach. Like I said, I don't have a truly rational reason here, but I have given up trying to fight it :grin:

Link to comment
Share on other sites

Though I have been something of an evangelist for Forth on this forum, my favorite language is, in fact, C. My progression in learning computer languages was often driven by necessity, starting with Fortran 2B in undergrad PChem as a means of fitting data to an equation by the method of least squares. After that, I was hooked on programming computers. Until I learned C, Algol was my favorite language. I guess I would say that Pascal is a superset of Algol, with more rigid typing than Algol—but, I digress.

 

Anyway, as I am sure you are well aware, you would have support from the handful of Forthers here were you to go with @Willsy’s suggestion.

 

...lee

Link to comment
Share on other sites

C++ is a superset of C, so in a C++ environment you should always be able to code in a C-style and use C-only constructs. Depending on the environment you may have to include a little bit of C++ to satisfy the tools and do the boiler-plate stuff.

 

If you are dealing with small microcontrollers then I would suspect the main language would be C followed by assembly. I just looked up the Teensy:

 

"You can program the Teensy in your favorite IDE using C or you can install the Teensyduino add-on for the Arduino IDE and write Arduino sketches for Teensy!"

 

It is an 8-Bit AVR Processor (AT90USB1286), meaning you will use C or assembly.

Link to comment
Share on other sites

There are a number of MSP430 boards (from Texas Instruments) that have a (free) Forth for them. You could program it in Forth ;-)

 

I just had a quick look at the wikipedia page for the MSP430

 

http://en.wikipedia.org/wiki/TI_MSP430#MSP430_CPU

 

Alot of the instructions look very similar to what I'm learning on the TI-99! (SWPB, JEQ etc etc)

 

cheers

Daryn

Link to comment
Share on other sites

Yep. It's a sixteen bitter like the TMS9900, too. Of course, it's a microcontroller so there's a LOT of stuff on there, but I think it'd take no more than a day to get comfy with MSP430 assembly.

 

It doesn't have moveable workspace like the 9900 does. Suprising how much I miss that on other processors. What a great idea it was.

Link to comment
Share on other sites

Though I have been something of an evangelist for Forth on this forum, my favorite language is, in fact, C. My progression in learning computer languages was often driven by necessity, starting with Fortran 2B in undergrad PChem as a means of fitting data to an equation by the method of least squares. After that, I was hooked on programming computers. Until I learned C, Algol was my favorite language. I guess I would say that Pascal is a superset of Algol, with more rigid typing than Algol—but, I digress.

 

Anyway, as I am sure you are well aware, you would have support from the handful of Forthers here were you to go with @Willsy’s suggestion.

 

...lee

 

I failed Fortran in high school :woozy: I believe it was Fortran 77, and I still have the textbook!. It was, and still is, a horrible text. I tried re-reading it a couple of years ago out of curiosity and because I had acquired the TI fortran package, and I could not make it past the first chapter. All the code examples were about payrolls and such, and the assumption was that we would program using punch cards! I had just gotten my TI at the time (1981), and TI BASIC was such a friendly language compared to this beast. Thankfully, that was the only course I ever failed in my entire career, but it left an indelible mark on me :grin:

Link to comment
Share on other sites

In my mathematics diploma thesis which I finished in 1995, I discussed mapping properties of triangle maps (complex analysis), see https://en.wikipedia.org/wiki/Hypergeometric_function

 

(which is pretty intimidating for me to read now ... did I really once understand that?)

 

Not only that I wrote the theses in LaTeX (while others still submitted typewriter paper), but I even created the maps using F9640 (the FORTRAN compiler for the Geneve). This was one of the most productive uses for my Geneve.

 

(In fact, this was real cut-copy-paste, which involved scissors, glue, and a photocopier. :-) )

Link to comment
Share on other sites

In my mathematics diploma thesis which I finished in 1995, I discussed mapping properties of triangle maps (complex analysis), see https://en.wikipedia.org/wiki/Hypergeometric_function

 

(which is pretty intimidating for me to read now ... did I really once understand that?)

 

Not only that I wrote the theses in LaTeX (while others still submitted typewriter paper), but I even created the maps using F9640 (the FORTRAN compiler for the Geneve). This was one of the most productive uses for my Geneve.

 

(In fact, this was real cut-copy-paste, which involved scissors, glue, and a photocopier. :-) )

 

That Fortran is the one I have, and it runs on the TI as well. I have never encountered any applications written in Fortran for the TI though. My nephew is an aerospace engineering graduate student at the University of Minnesota and Fortran under Linux is all they use to develop code for testing on the UofM supercomputer cluster for fluid dynamics simulations. This really surprised me, but it seems that it's still the best language for scientific purposes.

Link to comment
Share on other sites

Vorticon, don't forget, if you're using the Teensy for it's USB support, there is also V-USB which adds USB support to most, if not practically all of the AVR series microcontrollers. I've used it with the tiny85 to construct virtual com ports, the mega8 to construct usb controllers for arcade systems, etc. Pretty handy tool to have. Especially since a Mega8 will cost you a buck or so along with a few resistors, diodes and caps, while the Teensy will cost you about $20.

Link to comment
Share on other sites

It doesn't have moveable workspace like the 9900 does. Suprising how much I miss that on other processors. What a great idea it was.

 

Yup, moveable workspace registers is the biggest thing I found attractive about the 9900 versus the 6510 (6502.) In the Commodore 128, the MMU is capable of moving the CPU's "zero page" memory around, though VERY few programs take advantage of this function.

 

Zero-page is the first 256 bytes ($02-$FF for 6510 and 8502, as $00 and $01 are used for the on-chip I/O register) of RAM which is used in a special addressing mode by a lot of instructions to reduce instruction size (from three to two bytes) and gain some execution speed. For example, instead of LDA $0080 to load the contents of $0080 into the accumulator, one should use LDA $80. Come to think of it, I am pretty sure that almost all instructions except for JSR and JMP have zero-page variants.

Link to comment
Share on other sites

Vorticon, don't forget, if you're using the Teensy for it's USB support, there is also V-USB which adds USB support to most, if not practically all of the AVR series microcontrollers. I've used it with the tiny85 to construct virtual com ports, the mega8 to construct usb controllers for arcade systems, etc. Pretty handy tool to have. Especially since a Mega8 will cost you a buck or so along with a few resistors, diodes and caps, while the Teensy will cost you about $20.

 

Thanks for the tips :) The only reason I picked the Teensy is because there was already code for it in the area I was interested in which would require only minor modification to suit my purposes. I have not used microcontrollers before, and frankly I am bewildered by the options available! I did pick up the other day an Arduino Esplora for a few dollars from a closing Radio Shack store, and I have been playing with it a bit as I refresh my memory of the C language. I am pretty comfortable with the Raspberry Pi though as far as interfacing is concerned using Python, and the concepts are the same when it comes to the Arduino family of microcontrollers, just different syntax.

I will have a look at the Mega 8 for sure though.

Link to comment
Share on other sites

So it came preloaded with the code? If that's the case you better be able to read and write machine code.

 

The avr series is a fun microcontroller to mess with. And you get a lot of band for your buck. There are variants in packages from DIP-8 to DIP-40, as well as SMD variants. Soon I want to play around with a neat little hack that a guy did a while back. See below....

 

http://m.instructables.com/id/Single-Chip-AVR-BASIC-Computer/

 

That should give you an idea of how powerful these MCUs are.

Link to comment
Share on other sites

One more thing I thought about. If you do decide to start playing with AVR series MCUs, you really need to buy a USBasp. They're only a few bucks, and you shouldn't have any problem figuring out where to buy them from. You can write your code in any IDE that allows you to compile the machine code for that particular MCU, or use a separate compiler. The Arduino environment is one example, although not really C, but a C++ derivative. It's what I normally use. And I think in the latest release of the IDE the Teensy is supported, along with quite a few others. Of course there are Core Libraries available for MCUs not supported officially. The ATtiny series (Attiny85/45/25, Attiny84/44/24, Attiny2313, etc) is an example of that. But having the USBasp (or any other ICSP programmer) is crucial when you get away from the development boards. Although there is a library for using the Arduino has the programmer, I havent had great luck with it.

 

And one more thing to consider hardware wise (I know I'm getting a little off subject here) is oscillators. Depending on what it is you're trying to do, you might want to look into crystals/ceramic resonators. Some projects need them, so do not. The AVR series isn't the most accurate frequency wise when it comes to the speed of the MCU. ATmega8/328 can be run at 8mhz just fine, but if your application is going to be communicating over I2C, UART, SPI, etc then you'll definately want to go with an oscillator of some kind. And this is dependent on application, i.e. 12mhz 16mhz, etc.

 

Now considering I've gotten way off track, I'll try to refrain from future deviations of this thread. But would be happy to talk through PM if you have any questions. MCUs are where I cut my teeth...

Link to comment
Share on other sites

So it came preloaded with the code? If that's the case you better be able to read and write machine code.

 

The avr series is a fun microcontroller to mess with. And you get a lot of band for your buck. There are variants in packages from DIP-8 to DIP-40, as well as SMD variants. Soon I want to play around with a neat little hack that a guy did a while back. See below....

 

http://m.instructables.com/id/Single-Chip-AVR-BASIC-Computer/

 

That should give you an idea of how powerful these MCUs are.

 

No, it did not come pre-loaded, but there is a source code on GitHub designed for it that I want to experiment with. Why reinvent the wheel if you can just tweak it instead? :)

  • Like 1
Link to comment
Share on other sites

One more thing I thought about. If you do decide to start playing with AVR series MCUs, you really need to buy a USBasp. They're only a few bucks, and you shouldn't have any problem figuring out where to buy them from. You can write your code in any IDE that allows you to compile the machine code for that particular MCU, or use a separate compiler. The Arduino environment is one example, although not really C, but a C++ derivative. It's what I normally use. And I think in the latest release of the IDE the Teensy is supported, along with quite a few others. Of course there are Core Libraries available for MCUs not supported officially. The ATtiny series (Attiny85/45/25, Attiny84/44/24, Attiny2313, etc) is an example of that. But having the USBasp (or any other ICSP programmer) is crucial when you get away from the development boards. Although there is a library for using the Arduino has the programmer, I havent had great luck with it.

 

And one more thing to consider hardware wise (I know I'm getting a little off subject here) is oscillators. Depending on what it is you're trying to do, you might want to look into crystals/ceramic resonators. Some projects need them, so do not. The AVR series isn't the most accurate frequency wise when it comes to the speed of the MCU. ATmega8/328 can be run at 8mhz just fine, but if your application is going to be communicating over I2C, UART, SPI, etc then you'll definately want to go with an oscillator of some kind. And this is dependent on application, i.e. 12mhz 16mhz, etc.

 

Now considering I've gotten way off track, I'll try to refrain from future deviations of this thread. But would be happy to talk through PM if you have any questions. MCUs are where I cut my teeth...

 

Thanks for the advice. I don't have an immediate need for resonators at the moment, but who knows where my experiments will lead me to...

And yes, the Arduino IDE does indeed support the Teensy, and I have started writing test code to it, beginning with the classic Hello World of microcontrollers, the blinky program :D It's frankly pretty simple to program if one has some programming experience, and so far it's been a breeze to learn the Arduino C flavor.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...