• Tag Archives electronics
  • msp430- coding interrupts for mspgcc

    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()****

    Edit 6-23-2011

    MSPGCC Uniarch branch of mspgcc has been released, It supports newer chips like the msp430G2453 (the newer 20pin DIPs) This is an initiative to unify the current branches of mspgcc. Interrupts for this version is slightly different. Once I test it or get confirmation from another user I will post the correct format for uniarch branch……but what would be better would be unify the branches so we don’t have so much confusion with these version discrepancies and nuances of the trees.

    As of right now uniarch is still being worked on and there and is not fully recommended unless you need support for the newer 20pin Dips (G2x53 G2x52).  Please don’t let my opinion dissuade your choice of compiler, mspgcc works great for me but uniarch may work better for you.

     

    Thank you Tissit for your Comment

    “In current gcc, you can (should) include msp430.c instead of the specific header and use the -m switches (in a Makefile) to tell the compiler which chip you’re using. It will find the right headers automatically. “

    If I forget something let me know and I will update


  • Invintory time!!!

    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


  • BPM Counter Display update

    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 .


  • Arduino BPM- researching and building the display

    breadboard with the start of the display
    Breadboard with display and audio conector

    I have started construction of the Display of my bpm counter, I decided to use the 7 segment displays instead of sending it to the serial connection, from what others have told me is that the serial connection lags a little and may screw up my timing of the audio signal.

    I plan on hooking up 3 out of 4 digits using the same kind of method as building a POV display, by flashing the digits one at a time, fast enough, it will look like all 3 are on, but in truth only one digit will display for a very short time…. I have a drawn schematic right now, as soon as I finish the display I will post the schematic with a picture, and explain a little more on how i accomplished it.

    The audio half has given me some trouble, I have not found a good example of how to measure the music and get a BPM. all the examples I have seen use human interaction, A few examples I have seen, use either a button or a piezo electric element, and all that it does is measure the time between taps, then averages out the last few to get the BPM, this does work but you still need human interaction, this is not ideal when listening to multiple tracks at the same time

    My plan is to use a 741 OP-Amp to level the signal from the audio source and change it into a square wave that is measurable by my Arduino or other MC, Personally I would like to be able to select what audio range it is measuring but lets start simple and get a working measurement of some simple audio track and go from there.

    The 741 op-amp is a versatile chip and can be used in so many applications from comparators to audio amplifiers. A great resource that I used to get a good idea how op-amps work (since I little experience in using them) is http:\talkingelectronics.com

    the exact page I used is http://www.talkingelectronics.com/projects/OP-AMP/OP-AMP-1.html

    the site has some great info, but the one on op-amps really goes into detail and has helped me design the (hopefully) ideal circuit for this application. A schmitt trigger looks like the ideal setup. I chose this as a starting point, the schmitt trigger only sends High signals, when a upper and lower threshhold are met other wise it is low on the outputs.

    I will get more into my op-amp experiments once I start experimenting with them.

    Look for my display update in the next few days!!!

    P.S.  If any of you have any experience in op-amp circuits, your help will be appreciated greatly.


  • Projects on Hold till next month

    Currently I have to put my projects on hold, due to personal reasons, next month i will finish and polish and write up a few more.
    more PHP classes will be added as well.
    Look for a few more new Ideas, like my Dawn clock- a silent alarm clock that uses bright lite to simulate dawn…..for those 3 rd shift people ……the other idea was a large fish tank filled with small swimming robots , instead of water , mineral oil will be used, since it is a non conducting liquid. No need to waterproof any of the robots for the tank….just a few ideas that i want flesh out and create…….

    Hope to see you Next month when i start up again

    Justin


  • Idea: Arduino Based BPM counter

    I was thinking about my turntables that I have and about spinning trance and thought to myself that I don’t have any way to tell what the BPM is of the song, there are mixers that have this built in and I have seen rack mount stand alone units but nothing small and portable. My device would be handheld with stereo jack and rca jacks for input. Knowing that all analog music is just a wave form, why not measure the wave of a specific frequency (e.g. bass) using a band pass, then calculate when the peaks hit and get the BPM.

    This seems like a very simple thing to do but wont know till I start putting something together.

    parts that I will need:

    • Arduino or other ATmega chip
    • RCA connections
    • Darlington transistor pair (chip or separate transistors)
    • a few LEDs
    • Resistors asst
    • 2x 7 or 8 segment display or serial LCD module
    • maybe more parts, odds and ends

    This could be made into a kit or a sellable project. Hopefull in Jan I will be able to start putting this together for my proof of concept and show it off….

    Update:12/26/09

    Just thinking on how would i calculate BPM, so I started with Google….didnt get very many specific code, alot of applications that do it for you but no real source code to extract the equation from so i kept looking, and found this  http://www.conradaskland.com/blog/2008/02/how-to-calculate-delay-time-to-tempo-beat/

    He explains on how to calculate the delay time between beats

    * Delay time for crotchet in ms = 60000/BPM (Beat Per Minute)
    * Delay time for Quaver in ms = 60000/BPM/2 (Beat Per Minute)
    * Delay time for Semi-Quaver in ms = 60000/BPM/4 (Beat Per Minute)

    so I used my Horrible math skills and came up with

    BPM= 60K/Delay , then so on and so fourth.

    so now the hard part pattern recognition, The tactile Metronome project seems to be the closest on what I want to create there project is here http://wayneandlayne.com/metronome/ , This should give me a good start on my project/


  • One Step Closer to Finishing My Eye

    ready to test
    ready to test


    My IR eye is finally built and is ready to test, and see if my eye really works or not, my first readings were pretty good, by using a TV remote i tested each photo transistor to make sure it was working correctly before i attached it to the servo.
    The whole assembly is partially made out of recycled materials, the x axis base is made from an old cd that i was going to toss, and the y axis mount was made from a shelf bracket (found it in one of my boxes), the main base is made out of an old cardboard box that was bound for the recycling.
    Finished connections
    Finished connections

    I will have a build page up as soon as i finish some of the code.
    With Video!
    .


  • IR eye

    This project is the first step in my motion tracking. This Eye was built and adapted from an LRM post here .

    DSCN0219DSCN0221please dont laugh at my soldering job, its what i can manage with that kind of board, I like the ones that mimic a breadboard setup. With very little trouble i finished soldering in about 2 hours but had to go back a desolder one transistor and replace it and resolder one wire. After that i tested each IR sensor by themselves to make sure they all worked, each one gave a little different reading off the same IR source but that can be fixed with a little calibration in the software. But for now my goal is to hook it up to 2 servos and control the x and y for the motion tracking, eventually i would like to put this into an enclosure that looks like an eye.
    This is to make sure all 4 eyes are working
    const int sensepin0 = 0;
    const int sensepin1 = 1;
    const int sensepin2 = 2;
    const int sensepin3 = 3;
    int sensorValue0 = 0;
    int sensorValue1 = 0;
    int sensorValue2 = 0;
    int sensorValue3 = 0;
    void setup() {
    Serial.begin(9600);
    }
    void loop() {
    sensorValue0 = analogRead(sensepin0);
    sensorValue1 = analogRead(sensepin1);
    sensorValue2 = analogRead(sensepin2);
    sensorValue3 = analogRead(sensepin3);
    Serial.print("sensor = ");
    Serial.print(sensorValue0);
    Serial.print(" ");
    Serial.print(sensorValue1);
    Serial.print(" ");
    Serial.print(sensorValue2);
    Serial.print(" ");
    Serial.println(sensorValue3);
    delay(10);
    }

    this will test all 4 sensors and print to the serial port.

    also this code is written for the arduino but can be adapted to other microprossecors.

    Here is a screenshot of the schematic as well

    ScreenshotNext i will mount it to the servo and start writing the logic for 1 of the axis, but my question is how to mount this to a servo with stuff wround the garage. I will answer this question soo.

    and this is why you should never place you MC on your keyboard…………..Screenshot-1that large stack to the left is about 30 print screen applications running. I placed my arduino on my print screen button for about 10 secs before I realized what was going on.

    Parts:

    • 4x 2n 2222 NPN transistors (generic NPN)
    • 4x 220 Ohm 1/4w resistors
    • 4x NPN photo transistors
    • a bunch of wire
    • Arduino