This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Newbie needs help with understanding programming.

Other Parts Discussed in Thread: MSP430G2553, ENERGIA, CC430F5137

I recently purchased a launchpad 430 and have been attempting to learn c programming for the launchpad. I have made very little progress in 3 weeks working with it at least 8 hrs per day or more. I have been involved with electronics and electronic control systems for at least 30 years and have never seen anything so confusing. So I am giving up and asking for help. I have read 100’s of pages of reference material, some good and some worthless but not one example or document that really gets down to the nuts and bolts and explains why you do this or do that or what each piece of code means. Like what does "while 1" mean?

I have managed to work out some code that does parts of what I want to do but cannot figure out how to combine the code to get a complete working program. What I want to do is….

Turn on the red led at p1.0 and a buzzer at p1.6 if a analog input (the onboard temp sensor ) goes above a setpoint by a pre-defined differential (deadband). As long as the temp is above setpoint have the red led stay on but if a switch at p1.3 (the onboard switch) is pressed lock p1.4 in an off state and stay off until power is cycled to the launchpad.

I can do a little of each part but not the whole thing together. I have a programm that works the temp part and a program to do the switch but cannot figure out how to put them together  I would greatly appreciate a steer in the right direction from some of you genius’s out there. In fact I am very willing to pay for some help and guidance in developing this project I have in mind. If you are interested let me know. And thanks in advance for any and all advice and help.

  • Well "while(1)" means that something is happenign indefinitely. For example:

    while(1) {
          do_something();
    }

    will execute function "do_something()" once and then again and again and again until you power down the MCU.

    but simply:

    while(1);

    will just stop the program flow at that point and will do nothing except if an interrupt comes in, then it will serve the interrupt but that's a more advanced concept.

    For you it looks like it would be more beneficial to start with a simpler language than C. Maybe BASIC and then move on to Pascal and then maybe start thinking about C. That's if you want to educate yourself.

    If you just want to get the job done and are willing to pay for it however then we need to know the requirements of the project.

    Is this:

    Jerry jackson1 said:
    Turn on the red led at p1.0 and a buzzer at p1.6 if a analog input (the onboard temp sensor ) goes above a setpoint by a pre-defined differential (deadband). As long as the temp is above setpoint have the red led stay on but if a switch at p1.3 (the onboard switch) is pressed lock p1.4 in an off state and stay off until power is cycled to the launchpad.

    all you want to do? I guess some parts of the scenario are missing (e.g. what happens if switch at p1.3 is pressed and then temperature goes below the setpoint without power cycle). Also the temperature sensor can tell you by how much the temperature has risen but not really what it is because the temperature sensor on MSP430G2553 is uncalibrated-- it may have various startup values. Is that going to be ok? Otherwise you may need an external device for temperature measurement.

  • Seems that you're trying to learn too much new stuff all at once.

    Things like while(1) are purely to do with the  'C' programming language, and have nothing specifically to do with microcontrollers

    Sounds like what you need to do is to step back and spend some time to just learn the 'C' programming language first - then, when you have a fair grip of the language itself, you can move on to apply that to the specifics of the MSP430.

    Suggestions for starting with the 'C' programming language: http://blog.antronics.co.uk/2011/08/08

    Jerry jackson1 said:
    I have been involved with electronics and electronic control systems for at least 30 years

    Can you explain the nature of your "involvement"? What kinds of "electronics and electronic control systems"? Do you have any experience with programming in general? Or Microcontrollers? Digital systems?

    It's a lot easier to help if we know where you're starting from...

  • Jerry jackson1 said:
    I recently purchased a launchpad 430 and have been attempting to learn c programming for the launchpad. ,,

    I think that is quite reasonable if:

    (a) You already know c and want to apply that to a micros.

    ---- Or ----

    (b) You already know micros and want to program them in c.

    But if you do not have prior experiences in both either, I do not think you can get anywhere -- and this seems to be the case you are in.

    I had some experience with both c and micros, but I end up using assembly for MSP430. If you want to try the same, I can help you on that.

    But there are planty of other people who are using c for micros and happy about that combination. Join them if that is your choice.

  • old_cow_yellow said:
    if you do not have prior experiences in both either, I do not think you can get anywhere...

    While I wouldn't go so far as to say that you can't get anywhere, it does obviously make the whole thing far, far more difficult!

    old_cow_yellow said:
     -- and this seems to be the case you are in.

    Indeed!

    See my previous post!

  • So, then, the question is: where to start?

    Consider:

    • Programming (including 'C' programming) can be learned in isolation - without involving any microcontrollers;
    • Microcontrollers are pretty useless without some form of programming.

    Thus it would seem that 'C' is the place to start, moving on to the microcontroller when ready...

  • To answer some of your questions, my experience with controllers was building automation. My programming experience was logic based and basic. I had no problems understanding and using either. In fact i was very good at both but c seems to escape me. However i did find a site yesterday that has explained a lot. I am now going thru the tutorials and it is straightening out a lot of things. To bad i didn't find it 3 weeks ago. As for the particular projet i am trying to develope the sequence is as follows: .... monitor 3 analog inputs and one digital input from momentary N.O. pushbutton switch .... output to 2 leds, red and blue and 1 buzzer Display a blue led to indicate power to contoller. When power is applied cycle red and blue leds to prove lights good and processor working. Chirp buzzer to prove buzzer is good. Delay for 30 seconds then start watching analog inputs. Inputs are pressure, temp and volts. All 3 will probably be volts actually varied by press and temp transducers plus a battery voltage. If press goes low or temp goes high or voltage goes low depending on setpoints red led will turn on, and buzzer will sound. Red led stays on as long as any alarm condition is in alarm state and goes of if no longer in alarm. If switch is pushed alarm buzzer will lock off (and red led stay on if still in alarm) until reset by turning off power supply to controller. To answer more of your questions.... i do understand the electronics of circuits and controllers it's the c that is so confusing. But i am going to persist now that i have found some better tutorials and the help of great people like you guys. I actually would like to learn the programming whether it be c or spmething else because i have maany project ideas that i think i can develop and mayybe even sell a few plus it keeps me off the streets and out of trouble. I also have a web development business so if anyone would like to swap some one on one guidance for maybe a website design and hosting i would like to discuss it with you. Or i may just have to pay one of you to help me learn c or whatever. Again thanks for everything.

  • My recommendation to you is to buy an excellent book which I have already recommended in the past:

    MSP 430 Microcontoller Basics by John Davies.

  • Hmm, unless he knows assembly this will confuse even more.

    Look out for Energia, this is Arduino for MSP430s. Then work through some Arduino beginner examples.

  • Stephan Goldenberg said:
    Look out for Energia

    Could you be more specific - like a link, perhaps?

    Google finds many "Energias" - including "international network on gender and sustainable energy" (??!!) -  but I didn't see anything MSP430-related...

  • Andy Neil said:
    Could you be more specific - like a link, perhaps?

    https://github.com/energia/Energia supports some msp430g2xxx devices in the Launchpad.

    https://github.com/zacinaction/Energia/tree/Branch_CC430_RF_support is a fork which is adding support for a CC430F5137 (for use in the Sprite spacecraft)

  • That's great - thanks!

    SO it follows the Arduino with non-standard terminology like "sketch" instead of  "program" - I hope the OP isn't going to find that confusing...?!

     

  • learning c is a cup of cake for a person with good analytical and logical skills.. please try to learn c basics which should not take much time for your caliber.. once you are familiar with abc of C, try understanding the sample codes available for the msp430 MCU (samples include lighting up the LED and sensing the button press too).

    All the best with your new venture.. :)

  • Jerry jackson1 said:
    My programming experience was logic based and basic. I had no problems understanding and using either. In fact i was very good at both but c seems to escape me.

    There are many similarities between C and Basic. However, in Basic (in its original form) the program structure was line-oriented whiel in C, it is function oriented.
    Wher ein Basic you used 'gosub x' to execute code on a certain line, C makes this code a separate function and you call it by name.
    However, VisualBasic form Microsoft has move far towards this structure too and has not much common with the original Basic language.

    Many years ago I had to do a similar step, moving from C64 Basic to Pascal, Modula2 and finally C/C++. (you don't need/cannot use most of the '++' part of C++ on a microcontroller). It looked a huge step at first but once I got used to the concept of procedureal programming rahter than the linear code concept of Basic, I found that the step was smaller than I thought. Languages like Prolog, Logo and Forth (which I all learned once and forgot later)  were way more challenging.

    A good online resource is The C Book from Mike Banahan, Declan Brady and Mark Doran (Published by Addisob Wesley, 1991), whch is freely available. Chapter one is what you need for a start.
    When you're far enough to start with actual microcontroller programming, take a deeper look into chapter 8, especially 8.4. It's very important for things like hardware registers and interrupts. Any many people common with C have failed there when tring to use their (application) programming skills on a microcontroller.

  • Jens-Michael Gross said:
    My programming experience was logic based and basic...

    There are many similarities between C and Basic. [/quote]

    It's not clear whether the OP meant "basic" as in "elementary", or was referring to the BASIC programming language.

    Note that BASIC (as in the programming language) is an acronym - not a proper name - so should be written as BASIC.

    Beginner's All-Purpose Symbolic Instruction Code

    http://en.wikipedia.org/wiki/BASIC

    Some people say the 'I' stands for "Instructional" - as BASIC was created as a college teaching language.

    Jens-Michael Gross said:
    Basic (in its original form) the program structure was line-oriented whiel in C, it is function oriented

    BASIC is un-structured; 'C' is block-structured - as are Pascal, Modula, et, al.

    'C' is also, as you say, function-oriented - as opposed to Object-Oriented.

    BASIC was originally an interpreted language - some implementations still are.

  • Andy Neil said:
    BASIC is un-structured; 'C' is block-structured - as are Pascal, Modula, et, al.

    un-structured isn't quite right. However, the structure was mainly left to the coders preference.
    And, as I said, later versions of Basic are way more like pascal or C. VisualBasic has almost nothing to do with the original BASIC dialects. It's rather a clone of Pascal without being compatible.

    Andy Neil said:
    'C' is also, as you say, function-oriented - as opposed to Object-Oriented.

    Not opposed. There are several other ways of 'doing things' that function or object orientation. Prolog, while also built on functions, is database-oriented and BASIC originally was line-oriented.

    Andy Neil said:
    BASIC was originally an interpreted language - some implementations still are.

    There have been pPascal interpreters as well a BASIC compilers all the time.
    However, BASIC was interpreted because nobody could waste the space of storing source code and compiled data and compiler executable all together. Or spend the time of compiling a program with the speed of 1 source line per second for every change.
    Compilers became more popular with affordable hard disks. Or at least more than one disk drive. (Modula2 with one 360k disk drive was impossible to work with)

    However, I once wrote my own compiler for a language we (a friend and I) called TECSL (Technical Environment Compiler Speed Language). A Mixture of BASIC and C. It contained a runtime module for timers, I2C I/O and simple GUI, based on GEOS for the C64. Good old C64 times!

**Attention** This is a public forum