Custom Search

msp430- coding interrupts for mspgcc

0
Filed under Hardware, MSP430, electronics, programing, software
Tagged as , , , , , ,

I am just an idiot, but thats my opinion. For those with MSPGCC compilers, we have a more difficult time finding code examples, and many of the code examples given either don’ explain very well (cryptic Coding, un-commented code) or they are for the CCS or IAR, and they dont use the same syntax as the MSPGCC compiler. So here is how to create an interrupt handler for non-PUC/POR interrupts.

I will not go into interrupt vector masking, that is beyond me at this moment, but im not saying that i wont cover it later on, once i understand why you would want to mask it…..
So lets start at what headers and other setup items you need before, creating the interrupt handler.
First the signal.h has to be included into your code. #include<signal.h>
this will give you access to the special function of
interrupt(VECTOR ) service_routine (void) {/*interrupt code*/ }

this is the same as #pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void){ }

These are the Defined vectors for interrupts right from the header files.(mspgcc headers)

#define PORT1_VECTOR 4 /* 0xFFE4 Port 1 */
#define PORT2_VECTOR 6 /* 0xFFE6 Port 2 */
#define USI_VECTOR 8 /* 0xFFE8 USI */
#define ADC10_VECTOR 10 /* 0xFFEA ADC10 */
#define TIMERA1_VECTOR 16 /* 0xFFF0 Timer A CC1-2, TA */
#define TIMERA0_VECTOR 18 /* 0xFFF2 Timer A CC0 */
#define WDT_VECTOR 20 /* 0xFFF4 Watchdog Timer */
#define NMI_VECTOR 28 /* 0xFFFC Non-maskable */

all the interrupts should be self expainatory, vector = the source of the interrupt.

since now we have all the basics we can now right a small program that uses interrupt, we will just create a small WDT interval timer.
/*WDT interval timer- code based on msp430 examples*/
//compiler=mspgcc
#include<msp430x22x2.h>
#include<signal.h> //interrupt service routine
#include <io.h> //usually included on msp430 header, but for sfr register access.
void main(void) {
WDTCTL = WDT_MDLY_32; //~30mS intervals
P1DIR |=BIT1;
IE1 |= WDTIE; //enable interrupt
_BIS_SR(LPM0_bits + GIE); //not low power mode and enable interrupts
}//end of main
//interrupt service routine
interrupt(WDT_VECTOR) watchdog_timer(void)
{
P1OUT ^= BIT1;
}//end of interrupt

this should give you a good start on your Interrupts but there is still one thing that you may need. Changing the power modes when a interrupt is being serviced, the power mode will revert back to the power mode that it was in when the interrupt was called.
There are 2 functions that we can use to clear or set power modes while in an interrupt.
First one is to set the mode on exit of the routine, this is done by changing the copy of the status register that is saved to the stack. _BIS_SR_IRQ( ... )
you would use this the same way you would use the _BIS_SR(…)

The second one will clear the bits you select _BIC_SR_IRQ(...) same usage as the other, except it will just clear the bits not modify them.
***the use of _BIx_SR_IRQ() should only be used in an interrupt service request, the compiler will give you a warning but will produce the correct code if you use it anywhere else.***
****remember to enable Interrupts by using BIS_SR(GIE) or eint()****
if i forget something let me know and i will update

MSP430 basic coding/programing part 2 WDT+

1
Filed under Hardware, MSP430, electronics, programing

WDT is a very useful tool, as I explained before most of us will turn it off or use it as an interval timer. Timer_A has a similar timer function but more robust and more options.
So today we will be going over WDT and timer_A registers, how to setup them up, how you use them is up the you.

WDT is the watch dog timer, used for checking errors/faults, or software states, interval timer, interval interrupt, or what ever other uses you can think of.

So lets start with the basic register WDTCTL
This is the main register that will configure the WDT, bits 15-8 are the password register and 7-0 are for control. you need to set the password register before you can modify bits 7-0.
to do this WDTCTL = WDTPW; // WDTPW = 0x5A00 or 01011010 00000000
This will allow access to the 7-0 bits to configure the WDT. The rest of the registers are used to turn off, setup, change to interval mode, set interupts, change clock sources, and more.
This next set of registers is taken from the slau144e.pdf from the TI website, this book explains how it all works and what the settings mean.

WDTHOLD Bit 7 Watchdog timer+ hold. This bit stops the watchdog timer+. Setting
WDTHOLD = 1 when the WDT+ is not in use conserves power.

  • 0 Watchdog timer+ is not stopped
  • 1 Watchdog timer+ is stopped
  • WDTNMIES Bit 6 Watchdog timer+ NMI edge select. This bit selects the interrupt edge for the
    NMI interrupt when WDTNMI = 1. Modifying this bit can trigger an NMI. Modify
    this bit when WDTIE = 0 to avoid triggering an accidental NMI.

  • 0 NMI on rising edge
  • 1 NMI on falling edge
  • WDTNMI Bit 5 Watchdog timer+ NMI select. This bit selects the function for the RST/NMI pin.

  • 0 Reset function
  • 1 NMI function
  • WDTTMSEL Bit 4 Watchdog timer+ mode select

  • 0 Watchdog mode
  • 1 Interval timer mode
  • WDTCNTCL Bit 3 Watchdog timer+ counter clear. Setting WDTCNTCL = 1 clears the count
    value to 0000h. WDTCNTCL is automatically reset.

  • 0 No action
  • 1 WDTCNT = 0000h
  • WDTSSEL Bit 2 Watchdog timer+ clock source select

  • 0 SMCLK
  • 1 ACLK
  • WDTISx Bits 1-0
    Watchdog timer+ interval select. These bits select the watchdog timer+
    interval to set the WDTIFG flag and/or generate a PUC.

  • 00 Watchdog clock source /32768
  • 01 Watchdog clock source /8192
  • 10 Watchdog clock source /512
  • 11 Watchdog clock source /64
  • Read More »

    Invintory time!!!

    3
    Filed under Uncategorized
    Tagged as

    While i work and try to finish a few small projects that i have started but haven’t posted about, I will be doing a small inventory of all my parts…….I have boxes and bags, and parts almost everywhere and i dont really know what i have any more. When i am finished, I may be giving away parts as long as shipping is reasonable. This wont cut to much into my programming and writing posts, i do that during work (ssshhhh!).

    I also want to thank everyone who visits my site. It means alot :)

    Justin

    TI samples came in today

    1
    Filed under Uncategorized

    ADS7841-
    12-Bit, 4-Channel Analog-to-Digital Converter
    ADS7813-
    16-Bit Sampling Analog-To-Digital Converter
    …TLC5940-
    16-Channel LED Driver w/EEprom
    TLC556-
    Dual LinCMOS(TM) Timer
    TRS232E-
    Dual RS-232 Driver/Receiver With IEC61000-4-2 Protection
    MSP430F2013-
    16-bit Ultra-Low-Power Microcontroller, 2kB Flash

    MSP430 basic coding/programing part 1

    3
    Filed under Hardware, MSP430, electronics, programing, software

    basic functionality can be achieved with minimal coding. In my attempt to learning how to get the different peripherals working on my msp~2231. All MSP430 value line come with a simple universal package of hardware, Basic Clock, Timer_A, GPIO, USI (SPI,I2C,UART), WDT. then there are chips with chip specific hardware like ADC10, Comparator, Timer_B, Sigma-Delta ADC. to get most of these to work, it takes very little code, but to make them useful that will take a little more skill.

    We will start with everything after the header file #include msp430xxx.h , remember that this header file is chip specific.

    Lets start Here- this is where most of your code will go, including setting up the clocks, pins, interrupts, and anything else that will be run.
    void main(void) {
    //program goes here
    }

    Read More »

    BPM counter update: audio processing(not good)

    2
    Filed under General, Hardware, electronics

    Finally had enough time to sit and experiment with a bunch of different designs to boost and smooth the signal from an audio source. The few that I have tried didn’t work very well, the op-amp(741) with a LP filter didn’t boost the audio as much as i liked, it was giving poor results or no results at times, and  it used more components then i would have liked, since i don’t need audio quality sound, I didn’t feel the need to buy a dedicated audio amp or ICs. the other circuit i had tried was a LP  filter with a few extra caps, it looks like it would have worked but the audio signal was way too small to get a good reading.

    So i scratched everything and started again trying to go for simple, So i decided to use a Transistor amp, or class B amplifier since i am only using half of the wave…

    after the first few attempts it worked, not as i wanted but it did amplify the music, but it was not giving me the correct reading, when it was read it was giving very high odd values, between 400 and 900, and when plotted it did have a sine wave to the graph. the bad thing was it was a very small change in values and was unusable to create an algorithm to determine the beat, so i went to the drawing board, and looked at my design ,

    I had figured i forgot the pull down resistor on the ADC of the arduino(oops), after that i hooked it back up and tried again…….now the weird part, it didn’t work……so i double checked everything, connectivity the transistor, arduino, and i couldn’t find anything wrong…it should have been working……so i have put it down for now till i figure out why its not working ………

    I finally figured it out…..I killed my MP3 player that i was using as my source audio,  and now i have to find a replacement audio source that’s a little bit more robust then the one i just fried. an idea for replacement is use a 555 timer and set it at 120BPM and use that as my test source, but its just an idea……ill let you know how it turns out this weekend….

    BTW if anyone has any ideas for a simple schematic program, it would help greatly,

    everything i find has extra functions or some weird way to connect the wiring …..all i need is something that i can just place a symbol down rotate if needed and connect the wires….like using paintbrushes in gimp, then drawing a line between them……i tried that method too but no luck on the paintbrushes :(

    if i ever get something simple or i find a parallel cable for my scanner, i will post all my test diagrams and schematics.

    MSP430 tools for linux

    0
    Filed under General, Hardware, Linux, OS, electronics, software

    For your MSP430 launchpad to work on Linux you may have to do a little work, lol hopefully you expected this…..So lets get to it…..by the way i have Ubuntu 9.04 for my system, but that shouldn’t matter, except for dependencies may be different then mine.

    First you will need a few things to get it all working, so gather your tools and programs and lets start…..

    1. launchpad with 430 value line chip
    2. http://mspgcc4.sourceforge.net/ you will need at leas the binaries, or you can build it yourself
    3. http://mspdebug.sourceforge.net/ this is the program that will let you program your msp430 launchpad and debug it if needed
    4. libusb dev files (usb headers for compilation)
    5. Readline dev files
    6. and texinfo dev files

    after you have gathered all that you need you can start installing, you will most likely need the CLI to do most of the work, since we will be moving files into a root owned folder.

    1. First Build or install MSP430-gcc and other binaries for the tool chain http://mspgcc4.sourceforge.net/
    2. next install or copy the binaries /usr/ or usr/local ( i choose /usr/) I unpacked my archive inside my home folder and then CPd(copied) everything into /usr/ folder
    3. then check to see that they work, run msp430-gcc or msp430-gdb, it should just give the usage or start the program if all went well
    4. Now you want to install mspdebug, this program allows you to connect to the launchpad and reprogram the chip or debug it . It should be the simple make && make install on the source and it should go fairly quickly. if you have dependencies issues please consult the maintainer, I only listed the ones that i needed to download.
    5. after its done installing run it and test. to run it type “mspdebug rf2500″ and it should start up
    6. jsolarski@server-001:~$ sudo mspdebug rf2500
      [sudo] password for jsolarski:
      MSPDebug version 0.9 - debugging tool for MSP430 MCUs
      Copyright (C) 2009, 2010 Daniel Beer
      This is free software; see the source for copying conditions. There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


      Trying to open interface 1 on 005
      Initializing FET...
      FET protocol version is 30066536
      Configured for Spy-Bi-Wire
      Set Vcc: 3000 mV
      Device ID: 0xf201
      Device: MSP430F2013
      Code memory starts at 0xf800
      Available commands:
      = erase hexout mw read run sym
      cgraph gdb isearch opt regs set
      dis help md prog reset step
      Available options:
      color gdb_loop
      Type "help " for more information.
      Press Ctrl+D to quit.
      (mspdebug)

    7. now that it is connected its time to try and reprogram the flash, or play around with the registers.

    Now that its hooked up and ready to go you can go ahead and play around with mspdebug, or connect it up with gdb to debug and reprogram as well, but im just going to go into mspdebug because i have not learned gdb as well as i should.

    The main commands for mspdebugare

    =        erase    hexout   mw       read     run      sym
    cgraph   gdb      isearch  opt      regs     set
    dis      help     md       prog     reset    step

    the ones that i have used so far in my learning this program

    • dis <address>< length> — disassembles that block of memory dis 0xf800 2048
    • prog <file> program the target board “prog main.elf”
    • md <address><length in bit> read an address
    • regs    displays your registers for the board
    • erase   erases the flash memory of the board

    There are plenty of other things you can do in mspdebug but that is beyond my knowledge at this point.

    To reprogram the board just follow the simple instructions of  erase, prog. simple as that.

    Personally the easiest way to reprogram it is use this archive, which has all the files needed to do a test reprogram …and its been edited so it can be compiled with mspgcc.

    Demo program that works with GCC and mspdebug and msp tools

    this is the same source code and make file found on This site. I have not modified it all i did was take the .tgz and package it up into a zip file so its an archive with in a zip file. this is the same program that’s on the 2231 chip that comes with the launchpad except a few changes to make it work with gcc.

    At this point you should have a good starting point to work with this chip…just a little more research and i should be able to creating programs that do what i want them to do….

    Hope this helps!!

    MSP430 launchpad dev kit how too

    1
    Filed under Hardware, Linux, electronics, software

    A few weeks ago I had purchased a few MSP430 Launchpad, originally from Mouser, but there wait times for shipment of the product wasn’t until mid AUG to SEP

    and decided that was unacceptable for my terms of getting product and or waiting for parts…..very few times have i waited for more then a month for anything that I wanted, Sugru was different so I waited for it…..but back to the MSP430.

    after searching around I found a company that sold it and was in stock, so i Decided to cancel my other orders and go with them, the company was Newark, and i was very happy with there customer service….very friendly and polite. but i have finally gotten it and was able to do a little testing but not much in the way of programming, I haven’t set up the software for it or the library’s. But i did get to solder on the 32KHz crystal that was sent with the board………to my surprise it was a SMD 1.4mm+-.1mm crystal, with the leads .5mm apart from each other. I saw this and wondered why TI hates us hobbyist. I was expecting a regular through hole crystal, like they showed in one of the videos but that’s not the case, so i will do my best to solder one on to the boards and connect all the headers. I chose the regular female headers, sorta like the arduino, and i left the other board blank so i could solder wires and add other interesting gizmos to it and also to have a board that relies on the internal oscillator. so back to the how too……. Installing the crystal is probably the hardest part of the whole kit, just because the crystal is so small and hard to handle, but if you do it smart you can solder this piece in no time flat. So lets begin with things you may need

    • Supplies
    • Launch pad
    • 32KHz crystal
    • soldering iron
    • solder
    • headers
    • Bright lamp
    • electrical tape or tape like substitute
    • odds and ends (lol)(tweezers or other tool for manipulation)

    after getting your supplies ready its time to start plugging stuff in and getting things setup

    Read More »

    not forgotten just busy

    5
    Filed under General

    just been really busy with work and life, work still continues on my projects. The BPM counter, i am having issues with the input circuit, and with out an oscilloscope i have very limited data from my input circuit, and the readings are all over the graph, another project is i have created a 45 joule cap bank, which is going to be used for my coil gun, more on that later once i figure out how to optimize the inductor for maximum electro-magnet field.
    After this week, I do not have any more OT for a bit so i will have some more time to work on everything……

    I want to thank all my Visitors to my site, I may not be the best writer but i try to do my best…..Come back soon for some more updates, 1 more week!!!

    BPM Counter Display update

    0
    Filed under Hardware, arduino, electronics, software
    Tagged as , , ,

    I finished the display for the bpm counter!! Its amazing what you can do with a few transistors.  I’m currently using 10 of the 14 digital pins on my board, but running three 7 segment LED displays.  Parts include 10 NPN 2n2222 transistors and NPN 2n3904. 7 x 3.7K resistors and 2 dual 7 segment displays (only 3 being used).

    Thanks to Codekiller, im going in a slightly different direction, he suggested to create a VU meter first and get a good reading, then start to create the algorithm to find out the bpm is. Timing will be essential to get an accurate calculation, and also to visually look at the graphed data the arduino puts out will help in creation of the bpm algorithm, from my experience in audio editing and mastering, I am pretty certain I can pick out the Beat and measure the time it takes for the next peak, doing this visually should not be to hard but putting it into a programming language and having it work may be a little challenging.

    I am currently coding a quick gui to read and graph the values using The processing programing language(very easy to build visualization software and gui interfaces using a C like programming language). This may turn into a start of a simple oscilloscope later this year since i do need one for my bench.

    Pics comming this morning when  I get home from work(lol)and maybe a video if i can get it to work correctly. I am so happy that I have a radio shack within 5 mins from my place, and only have to wait till 9 am till they open.

    Thanks Codekiller for the great help and ideas—> his site http://smfinc.web.elte.hu/ruckus/index.html

    and the site Im using as a starting point —>http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/

    at the time of this post the last link had a Database connection error in German, I will check in a day or so and if its still down, I will post the PDF and code that I’m using from there project.

    Look for more updates Soon!!

    Justin

    update-

    my camera is not function at this moment, im working on getting it fixed and recovering some of my pics, but work is continuing on my days off. (not to much time on work days) the audio circuit is done, just need to test .