Jump to content
43oh

cde

Members
  • Content Count

    940
  • Joined

  • Last visited

  • Days Won

    21

Reputation Activity

  1. Like
    cde reacted to enl in Basic Control Register Control for LED Blink Issue   
    The first thing is that the numeric values, such as in the line `P1OUT = 01000000;' are treated as octal values due to the leading zero. Without a leading zero or base specified, numerics are treated as decimal. As you intend this to be binary, you can try `0b01000000'. Some compilers will accept this as binary, though it is not standard. The best way is use hexidecimal: `0x40', which all C compilers will accept.
  2. Like
    cde reacted to cubeberg in Basic Control Register Control for LED Blink Issue   
    For ease-of-use - I like using the BIT0, BIT1, etc. defines.  Also - the reason why you're running into problems with initialization is you're always using the plain assignment operator.  You need to look at some of the other operators like  |=, &= and ^= - they will make it easier to control single bits without affecting the others.  For instance - P1DIR |= BIT6 will only add bit6 to whatever is defined in P1DIR.
     
    Typical on/off code:
    void loop() { P1OUT |= BIT6; delay(1000); // wait for a second P1OUT &= ~BIT6; delay(1000); // wait for a second } or another option - toggle
    void loop() { P1OUT ^= BIT6; delay(1000); // wait for a second }
  3. Like
    cde reacted to zeke in Saving flash space, by making use of infomem   
    While reading this thread, I noticed that the answers did not comment on a solution for CCS. 
     
    So here are my observations and code samples to make that work in CCS.
     
    First, I trimmed down the font sample code from @@greeeg just to see if it will work.
    #pragma DATA_SECTION(font_data, ".infoB") const unsigned int font_data[] = { 0x0000,0xC101,0x0110,0x3B89,0x9BD9,0x5BDA,0x0F6D,0x4000, 0x4400,0x0022,0x55AA,0x1188,0x0002,0x1008,0x0001,0x4002, 0xEA57,0x6800,0xB24D,0xDA41,0x3818,0x8659,0x9A5D,0xA840, 0xBA5D,0xBA59,0x0041,0x0042,0x4203,0x1209,0x0621,0xB0C0, }; Good! This is just the right size to fill up 64 bytes - the size of INFOB. Any bigger and the compiler fails out with an error message about memory size is over filled or something.
     
    Next, figure out what special names you can use in the DATA_SECTION declaration.
     
    Open up the linker file for your project. In my case, it's called lnk_msp430g2553.cmd. 
     
    You will see this inside of it:
    .infoA : {} > INFOA /* MSP430 INFO FLASH MEMORY SEGMENTS */ .infoB : {} > INFOB .infoC : {} > INFOC .infoD : {} > INFOD so, use the lowercase name in your declaration.
     
     
    And here is my test program that I used to test drive the flash on an MSP43G2553:
    #include <msp430.h> /* "Compressed" font data, in form 0b ABCD EFGH IJKL MNOP {A-P} represent segment bits in each character __J_ _A__ |\ | /| | K H B | L \ | / C | \|/ | >-M--*--D-< | /|\ | N / | \ E | O I F | |/ | \| ~~P~ ~G~~ */ #pragma DATA_SECTION(font_data, ".infoB") const unsigned int font_data[] = { 0x0000,0xC101,0x0110,0x3B89,0x9BD9,0x5BDA,0x0F6D,0x4000, 0x4400,0x0022,0x55AA,0x1188,0x0002,0x1008,0x0001,0x4002, 0xEA57,0x6800,0xB24D,0xDA41,0x3818,0x8659,0x9A5D,0xA840, 0xBA5D,0xBA59,0x0041,0x0042,0x4203,0x1209,0x0621,0xB0C0, }; //const unsigned int font_data[] //__attribute__((section(".infob"))) = //{ //0x0000,0xC101,0x0110,0x3B89,0x9BD9,0x5BDA,0x0F6D,0x4000, //0x4400,0x0022,0x55AA,0x1188,0x0002,0x1008,0x0001,0x4002, //0xEA57,0x6800,0xB24D,0xDA41,0x3818,0x8659,0x9A5D,0xA840, //0xBA5D,0xBA59,0x0041,0x0042,0x4203,0x1209,0x0621,0xB0C0, //0xAACD,0xB85C,0xBBC1,0x8255,0xABC1,0x825D,0x805C,0x9A55, //0x381C,0x83C1,0x81C5,0x441C,0x0215,0x6834,0x2C34,0xAA55, //0xB05C,0xAE55,0xB45C,0x9A59,0x81C0,0x2A15,0x4016,0x2C16, //0x4422,0x40A0,0xC243,0x0055,0x0420,0xAA00,0x0402,0x0201, //0x0020,0x028D,0x009D,0x000D,0x018D,0x000F,0x9188,0x1E01, //0x009C,0x0080,0x0081,0x1580,0x03C0,0x188C,0x008C,0x008D, //0x015C,0x03D8,0x000C,0x1081,0x1388,0x0085,0x0006,0x0A85, //0x4182,0x0E01,0x000B,0x8388,0x0180,0x11C1,0x3150,0x0000, //}; char value; // 8-bit value to write to segment A // Function prototypes void write_SegC (char value); void copy_C2D (void); int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer if (CALBC1_1MHZ==0xFF) // If calibration constant erased { while(1); // do not load, trap CPU!! } DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator value = 0; // initialize value while(1) // Repeat forever { write_SegC(value++); // Write segment C, increment value copy_C2D(); // Copy segment C to D __no_operation(); // SET BREAKPOINT HERE } } void write_SegC (char value) { char *Flash_ptr; // Flash pointer unsigned int i; Flash_ptr = (char *) 0x1040; // Initialize Flash pointer FCTL1 = FWKEY + ERASE; // Set Erase bit FCTL3 = FWKEY; // Clear Lock bit *Flash_ptr = 0; // Dummy write to erase Flash segment FCTL1 = FWKEY + WRT; // Set WRT bit for write operation for (i=0; i<64; i++) { *Flash_ptr++ = value; // Write value to flash } FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit } void copy_C2D (void) { char *Flash_ptrC; // Segment C pointer char *Flash_ptrD; // Segment D pointer unsigned int i; Flash_ptrC = (char *) 0x1040; // Initialize Flash segment C pointer Flash_ptrD = (char *) 0x1000; // Initialize Flash segment D pointer FCTL1 = FWKEY + ERASE; // Set Erase bit FCTL3 = FWKEY; // Clear Lock bit *Flash_ptrD = 0; // Dummy write to erase Flash segment D FCTL1 = FWKEY + WRT; // Set WRT bit for write operation for (i=0; i<64; i++) { *Flash_ptrD++ = *Flash_ptrC++; // copy value segment C to segment D } FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit } Here is a screen shot of CCS as I inspected the information memory section.  
     
    The way I have the screen stretched out causes each memory section to be all on one line ie:
    INFOD (0x1000), INFOC (0x1040), INFOB (0x1080) and INFOA (0x10C0).  

     
     
    Footnote: For reference, here's TI's take on this topic: 
  4. Like
    cde got a reaction from Diego Herrera in Hi from Colombia   
    Bienvenido
  5. Like
    cde got a reaction from vinicius.jlantunes in Simple PWM using timer   
    No, it can't be used directly. P1.0 is Timer0_A, clock signal TACLK input only. It cannot be set as a hardware Timer0_A output.
     
    You can use it with a software assisted PWM. You need an Interrupt for your timer, and just have it manually toggle the P1.0 in gpio output mode.
  6. Like
    cde reacted to bluehash in 43oh Server Slow Responsiveness.   
    Thank you guys. This site is l..i..m..p..i..ng. I'm configuring a Linnode for now. I moved over c2kcentral as a test and it went well. 
    I leave for vacation tomorrow(my wedding) and hoping to finish it sometime tomorrow, at least.
    Always at the wrong time.
     
    Thanks for sticking around.
  7. Like
    cde reacted to cjn in Home security system: SMS alerts, https event log, bluetooth passcode (dis)arming   
    Has anyone seen this or hacked this for home security: http://www.amazon.com/gp/product/B00DH2VOXK
    At $12 (+$9 for more sensors) it is a throwaway price. Initially was priced at $200 and sold thru Radioshack.
    The product build hardware quality is quite nice. The reason for low price tag seems to be that manufacturer went belly up and they are getting rid of stock.
     
    While the hardware is good and works just like any other home security system, its configuration is done almost entirely over SMS messages - which is a pain (which may be the reason why it was a failure.)
     
    If I had to source the components/sensors myself I bet it would cost me more than $20 shipped.
     
    I plan to use it as a secondary or fail-over burglar alarm because I already have another system installed and I prefer to have central monitoring. This is so cheap I can have door-open sensors on every cabinet door
  8. Like
    cde reacted to rebeltaz in trouble with battery backup   
    I'm only running this at 1MHz. I thought that the battery would be low enough, too, but without the resistor, it's only like 0.05-0.1v below the supply voltage and I didn't think that that was low enough. I even tried adding a 470uf capacitor across the supply pins on the MSP (pins 1 and 20) as well as a 470uF capacitor across the reset pin and ground to help in case the transition wasn't quick enough. Still no good.
  9. Like
    cde got a reaction from AGlass0fMilk in MSP430-Based DIY DJ Controller   
    Wow, that's REALLY indepth.
     
    As a side note, have you thought of making a native USB Midi adaptor on a Tiva or F5529 launchpad? You probably have the skill to do it. At that point, no drivers or processing would be needed, as you would do a usb class compliant device.
  10. Like
    cde reacted to AGlass0fMilk in MSP430-Based DIY DJ Controller   
    I said I'd post it when I was done, so here it is! It's a Laser-cut USB DJ Controller made with two MSP430G2553s and an MCP3008 ADC. Check out the Instructable I made for more information about the build. If you like it, please vote for it in the contests I entered! Thanks guys!
     
    Instructables Link
     
    Representing the 43Oh!

  11. Like
    cde got a reaction from StupidPig in APA102 - simple to drive RGB leds   
    You might have better luck running the msp430 at 3.6V. That tends to near the typical VIH of a 5V ttl device (VCC * 0.7).
  12. Like
    cde reacted to RobG in halloween 2014   
    My 2014 Halloween project, Enderman. 
     
    It's still not finished, at least not the way I wanted. My wife told me this morning that we are going to Halloween parade, so I had to scramble and finish it by 6pm today. Meaning lots of duct tape. When finished properly, the entire head will be covered.
     
    Each eye has 12 WS2812 LEDs, MSP430G2553 control, powered from 4 x AA.
    At full brightness, eyes were perfect in the evening, but once it got dark, they were little too bright (on the bright side, they could see what candy is in the basket )
    I think I will have to add light sensor or at least brightness switch/pot.
    Light boxes should also be taller. I added extra 0.25" on top and bottom so that LEDs are not visible, but they still are, especially when head is tilted.
     
     

  13. Like
    cde reacted to pabigot in Convert char to integer issue   
    Being pedantic (which I am...):
     
    Ignoring the past-end-of-array error: In C, the macro NULL as defined in various headers denotes a null pointer constant, nominally compatible with type void * but not necessarily of pointer type. In C++ NULL is an integral constant expression that evaluates to zero; it cannot be a pointer type. In C++11 the literal nullptr replaces NULL.
     
    The end-of-string terminating character in C and C++ is the ASCII code NUL, which is character value '\0' or equivalently an integral value zero.
     
    One is a pointer, the other is a character. You shouldn't mix those concepts: you'll just confuse yourself and whoever has to maintain your code. (If you use a compiler where NULL is equivalent to ((void*)0) and you enable all warnings (which you should do) you'd get complaints about assigning a pointer to a non-pointer object.)
     
    In situations like the above, assign either '\0' or simply 0 to a char that marks the end of the string.
     
    (When documenting an array like a that holds a NUL-terminated array of characters, you might specify to its content as "ASCIIZ" denoting a zero-terminated ASCII encoded string, as opposed to a length-plus-characters encoding used in some other languages. There are cases where the object would intentionally exclude the terminating zero, but that's a topic for another day.)
  14. Like
    cde reacted to USWaterRockets in Hello from the New York Spaceport   
    Hello everyone!
     
    We're a small group of science enthusiasts with varied interests who got together a little over a decade ago after seeing a video about the (then) world altitude record for Water Rockets. Everyone here surely remembers fondly the small plastic rockets that you filled with water and pumped with compressed air and can shoot up 50 feet or so? Well, there exists a small niche of rocketry enthusiasts who design and build their own high performance versions of these rockets that can fly hundreds or thousands of feet in the air. With their short but powerful boost phase, water rockets are ideal for lofting experiments and payloads that commonly available pyrotechnic rockets simply cannot budge.
     
    The primary benefit to these rockets is that they don't use combustion to fly and don't use pyrotechnics in their recovery systems, so they are not heavily regulated and are vastly less expensive to build and fly.  Water Rocketry attracts a wide range of people with different backgrounds from all over the world. Given that water rockets are assembled from common everyday materials, the cost to get started is minimal, and this is very appealing to those of us who are on a budget.
     
    How this relates to the MSP430 is where things get interesting...
     
    A few years ago, Mythbusters did a segment about water rockets, which created a surge of interest in the sport. The surge in popularity generated a lot of wonderful research into improvements in key areas. Enthusiasts began lofting cameras and science experiments and often crashing them, since the state of the art at that time were notoriously unreliable passive and clockwork parachute deploy systems. To improve the reliability of deploy systems, a number of people turned to electronic systems, usually activating a servo motor or a magnetic release. Many designs were built and tested, and at the time there were numerous designs based on the Microchip PIC processors, which we felt were abhorrent even back then. We did some designs based on Motorola micros and some AVR designs, and then we discovered the low cost R/F development kits for the MSP430 and discovered how amazing this family of micros is. We designed a number of deploy controllers and camera controllers and other payloads for our rockets based on the EZ430-RF2500 kits.
     
    Around this time, a couple of garage shops took the best designs that were being discussed online, and they rehashed them and started producing and selling various microcontroller servo deploy timers for water rockets. Being early into a new market, quite a bit of price gouging began taking place. This type of thing flies in the face of what water rockets is all about, so we thought it would be great to publish plans on how to build a version of our servo deploy timer. As luck would have it, the MSP430 LaunchPad had just arrived on the market and so a little software work to fit our code into the small memory of the MSP430G2231 was all it would take to make our design work for everyone (Documenting the build process for the average layperson was by far the hardest part of the project).
     
    When the project was complete, we published the executable and build instructions, and thanks for the $4.30 price, people could have a servo parachute recovery system for about 10% of the price of the PIC based semi commercial offerings.
     
    We absolutely fell in love with the LaunchPad and the fact that it could be programmed easily in C or assembler, and has such a wide range of offerings.
     
    Since then, TI upgraded the LaunchPad to the MSPP430G2553, with more memory, and we decided to produce a much more advanced design. With the addition of a Sparkfun barometric sensor breakout board and a piezo buzzer, we created a LaunchPad based model rocket Altimeter with automatic parachute deploy at apogee. This past summer we published the executable and the instructions for this new version and it has been well received.
     
    That's our history in a nutshell.  We hope to continue to refine and improve our DIY designs using some of the new LaunchPads which have come out recently. They come out so fast now we have a backlog of ideas to apply! This is a good problem to have!  We hope you enjoyed our story, and look forward to interacting with everyone here on the forum!
     
    USWaterRockets
    www.uswaterrockets.com
     
     
     
  15. Like
    cde got a reaction from bluehash in EZ430 Soft Switch (DIY Skylanders Portal)   
    Form:
    Made a base similar to the Skylanders Portal, with some spray foam, coroplast, and Color Changing LEDs. This was added to a Totem Pole. Kid brother's school project.
     
     
    Function:
    Used an EZ430-F2013 as a simple Soft Switch, leds on 5 minute timer, to save the batteries from being drained.
     
    Code (main.c):
    #include "common.h" /*-------------- EZ430 Soft Switch, 5 Minute Sleep Timer using Watchdog LED is P1.0 D1 on EZ430 TRANS is P1.1 2n2222 Transistor Base PB is P1.2 Pushbutton P1.3-P1.7, P2.6, P2.7 free --------------*/ bool switch_state = 0; void cpu_init(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WatchDog Timer BCSCTL1 = CALBC1_1MHZ; // Set range to 1mhz Calibrated Range DCOCTL = CALDCO_1MHZ; // Set DCO to 1mhz Calibrated DCO // SMCLK = DCO = 1MHz P2SEL &= ~BIT6 & ~BIT7; // Disable External Oscillator Pins P2DIR |= BIT6 | BIT7; // Set as Output P2OUT &= ~BIT6 & ~BIT7; // Set as Output Low } void out_init(void) { P1SEL &= ~LED & ~TRANS; // Set Pins as GPIO P1DIR |= LED | TRANS; // Set Pins as Output P1OUT &= ~LED & ~TRANS; // Set LED and TRANS Pins to Off // Used for Testing, not needed as will not be visible // P1OUT |= LED; // Turn on EZ430 LED } void pushbutton_init(void) { P1SEL &= ~PB; // Set Button as GPIO P1DIR &= ~PB; // Set Button as Input P1REN |= PB; // Set Buttons Pull-Up/Pull-Down Mode P1OUT |= PB; // Set Buttons Pull-Up P1IES |= PB; // P1.2 Interrupt set for High to Low Transition (Active Low) P1IFG &= ~PB; // P1.2 Interrupt Flag Cleared P1IE |= PB; // P1.2 Interrupt Enabled } // Port 1 interrupt service routine #pragma vector = PORT1_VECTOR __interrupt void Port_1_ISR(void) { // Clear LPM & Disable Interrupts to Allow main() to handle commands before returning to sleep _BIC_SR_IRQ(LPM4_bits + GIE); // Check which button pressed if ( (P1IFG & PB) == 0x04) { if (switch_state == 0) switch_state = 1; else switch_state = 0; } // Debounce scripted_wait(); scripted_wait(); scripted_wait(); scripted_wait(); scripted_wait(); // P1.2 IFG cleared P1IFG &= ~PB; } volatile int second_count = 0; volatile int minute_count = 0; void timeDog_on(void) { WDTCTL = WDT_MDLY_32; // WatchDog Interval (Clock Source / Interval) (SMCLK / 32) // 1MHz / 32 = 31.25kHz // 1 / ( Clock Source / Interval ) = Freq in Milliseconds // Happens 32 times per second! Duh! Every 32766 Clock Ticks. DUH! IE1 |= WDTIE; // Enable WatchDog Interrupt, Still need to enable Global Interrupts } void timeDog_off(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WatchDog Timer IE1 &= ~WDTIE; // Disable WatchDog Interrupt minute_count = 0; // Reset Timer Count to 0 second_count = 0; // Reset Timer Count to 0 } // WatchDog interrupt service routine #pragma vector = WDT_VECTOR __interrupt void WatchDog_ISR(void) { second_count++; // 32 Interrupts per Second * 60 seconds = 1920 per minute if (second_count >= 1920) { second_count = 0; minute_count++; } if (minute_count >= 5) { switch_state = 0; // __low_power_mode_off_on_exit(); // Exit LPM at Interrupt End _BIC_SR_IRQ(LPM4_bits + GIE); } } void scripted_wait(void) { // SW Delay (how many seconds??) volatile unsigned int hick; hick = 10000; do hick--; while (hick != 0); } int main(void) { cpu_init(); out_init(); pushbutton_init(); __enable_interrupt(); // Turn on Switch when first plugged in for 30 seconds minute_count = 4; second_count = 960; switch_state = 1; // Setup Complete, now check state, run function, then go to sleep with interrupts while (1) { if (switch_state == 0) { P1OUT &= ~TRANS; // Switch Off timeDog_off(); // Disable Watchdog Interrupt // __low_power_mode_4(); // Sleep until Button Press __bis_SR_register(LPM4_bits + GIE); __no_operation(); } else if (switch_state == 1) { P1OUT |= TRANS; // Switch On timeDog_on(); // Enable Watchdog Interrupt // __low_power_mode_0(); // Sleep with Timer __bis_SR_register(LPM0_bits + GIE); __no_operation(); } } } Code (common.h):
    #ifndef COMMON_H #define COMMON_H 1 #include <msp430f2013.h> #include <stdbool.h> #ifndef TRUE #define TRUE true #endif #ifndef FALSE #define FALSE false #endif #ifndef BOOL typedef bool BOOL; #endif #define LED BIT0 // P1.0 #define TRANS BIT1 // P1.1 #define PB BIT2 // P1.2 void scripted_wait(void); #endif Schematic:
    (not 100% complete, missing on board Reset pull-up, Decoupling Cap, and most of the EZ430 programming board stuff)

     
     
    The lights were made using some Slow Color Changing LEDs from a USB . These have a microcontroller inside providing current control and pwm. No resistor needed, and have a wide input range. But 3V is not enough for full brightness and colors, so the entire EZ430-F2013 stick was used. This is for a few reasons:
    Power. The LEDs need 4V + for brightness, while the msp430 needs 3.5V. The EZ430's USB input and regulator ensures I have both voltages. Plug and Play. I can reprogram the stick without having to worry about the 0.05" pins or wiring, or a programmer. Adaptability. Currently uses a 3x AA battery pack with a usb female connector, can easily be switched to a USB wall charger without any changes. I have multiple EZ430s lying around. After figuring out the electronics (A simple NPN transistor is used, while the base resistor is probably undersized as I did not actually measure the total LED current consumption, bad cde, bad.), the code took some testing. Using the Watchdog timer and LPM0 and LPM4, as well as a switch, the lights turn on for 30 seconds when first plugged into power. After turning off, it works as follows. LPM4 until the switch is pressed, then the lights turn on. Dropping into LPM0 as the Watchdog Timer uses the SMCLK, it counts to 5 minutes then turn off, or it can be turned off by pressing the switch again. No hardware debounce, just some for loop delays, it works fine as long as the switch isn't held in for long, otherwise it might turn off/on again.

     
     
    The Totem was made using a PVC pipe, with plaster shaped on top. The Base was made using three things. The first is the coroplast (corrugated plastic, like cardboard. Same stuff street signs are made of). The one used was fairly opaque, a more transparent one would have been better. Once it was cut to size and holes drilled for the leds, the second part is some cardboard rolled around it. Once taped, the dirty part of the job was getting Expanding Spray Foam onto the sides. This was harder than it should have been since the can I used had a broken nozzle. Simply hold it from the inside, spray the foam on, rotate, spray some more, let it dry, rotate, spray some more, etc (a coat hanger worked great to hold it up between rotations). I pressed some of the air out once it started drying, be careful as spray foam is incredibly sticky, and at some points pulls, while at others it gets stringy. Finally done and hardened to touch, some of the less rocky parts were cut off with an exacto knife. It was then painted using some grey primer. No highlighting needed due to the texture and grooves creating shadows.
    (Warning, some spray foams will melt/be eaten away by some spray paints. I used Great Stuff brand spray foam from Home Depot, and I forget the spray paint brand). Hint, there is multiple types. The beige one I used expands more (1" holes) while the pink one (fire/heat resistant) is stiffer and has less air pockets. If I had to do this again, I would use the pink for it all. This is a basic cosplay/halloween prop/decoration technique

    Once done, everything was assembled. He has to get an A.

  16. Like
    cde got a reaction from cubeberg in EZ430 Soft Switch (DIY Skylanders Portal)   
    Form:
    Made a base similar to the Skylanders Portal, with some spray foam, coroplast, and Color Changing LEDs. This was added to a Totem Pole. Kid brother's school project.
     
     
    Function:
    Used an EZ430-F2013 as a simple Soft Switch, leds on 5 minute timer, to save the batteries from being drained.
     
    Code (main.c):
    #include "common.h" /*-------------- EZ430 Soft Switch, 5 Minute Sleep Timer using Watchdog LED is P1.0 D1 on EZ430 TRANS is P1.1 2n2222 Transistor Base PB is P1.2 Pushbutton P1.3-P1.7, P2.6, P2.7 free --------------*/ bool switch_state = 0; void cpu_init(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WatchDog Timer BCSCTL1 = CALBC1_1MHZ; // Set range to 1mhz Calibrated Range DCOCTL = CALDCO_1MHZ; // Set DCO to 1mhz Calibrated DCO // SMCLK = DCO = 1MHz P2SEL &= ~BIT6 & ~BIT7; // Disable External Oscillator Pins P2DIR |= BIT6 | BIT7; // Set as Output P2OUT &= ~BIT6 & ~BIT7; // Set as Output Low } void out_init(void) { P1SEL &= ~LED & ~TRANS; // Set Pins as GPIO P1DIR |= LED | TRANS; // Set Pins as Output P1OUT &= ~LED & ~TRANS; // Set LED and TRANS Pins to Off // Used for Testing, not needed as will not be visible // P1OUT |= LED; // Turn on EZ430 LED } void pushbutton_init(void) { P1SEL &= ~PB; // Set Button as GPIO P1DIR &= ~PB; // Set Button as Input P1REN |= PB; // Set Buttons Pull-Up/Pull-Down Mode P1OUT |= PB; // Set Buttons Pull-Up P1IES |= PB; // P1.2 Interrupt set for High to Low Transition (Active Low) P1IFG &= ~PB; // P1.2 Interrupt Flag Cleared P1IE |= PB; // P1.2 Interrupt Enabled } // Port 1 interrupt service routine #pragma vector = PORT1_VECTOR __interrupt void Port_1_ISR(void) { // Clear LPM & Disable Interrupts to Allow main() to handle commands before returning to sleep _BIC_SR_IRQ(LPM4_bits + GIE); // Check which button pressed if ( (P1IFG & PB) == 0x04) { if (switch_state == 0) switch_state = 1; else switch_state = 0; } // Debounce scripted_wait(); scripted_wait(); scripted_wait(); scripted_wait(); scripted_wait(); // P1.2 IFG cleared P1IFG &= ~PB; } volatile int second_count = 0; volatile int minute_count = 0; void timeDog_on(void) { WDTCTL = WDT_MDLY_32; // WatchDog Interval (Clock Source / Interval) (SMCLK / 32) // 1MHz / 32 = 31.25kHz // 1 / ( Clock Source / Interval ) = Freq in Milliseconds // Happens 32 times per second! Duh! Every 32766 Clock Ticks. DUH! IE1 |= WDTIE; // Enable WatchDog Interrupt, Still need to enable Global Interrupts } void timeDog_off(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WatchDog Timer IE1 &= ~WDTIE; // Disable WatchDog Interrupt minute_count = 0; // Reset Timer Count to 0 second_count = 0; // Reset Timer Count to 0 } // WatchDog interrupt service routine #pragma vector = WDT_VECTOR __interrupt void WatchDog_ISR(void) { second_count++; // 32 Interrupts per Second * 60 seconds = 1920 per minute if (second_count >= 1920) { second_count = 0; minute_count++; } if (minute_count >= 5) { switch_state = 0; // __low_power_mode_off_on_exit(); // Exit LPM at Interrupt End _BIC_SR_IRQ(LPM4_bits + GIE); } } void scripted_wait(void) { // SW Delay (how many seconds??) volatile unsigned int hick; hick = 10000; do hick--; while (hick != 0); } int main(void) { cpu_init(); out_init(); pushbutton_init(); __enable_interrupt(); // Turn on Switch when first plugged in for 30 seconds minute_count = 4; second_count = 960; switch_state = 1; // Setup Complete, now check state, run function, then go to sleep with interrupts while (1) { if (switch_state == 0) { P1OUT &= ~TRANS; // Switch Off timeDog_off(); // Disable Watchdog Interrupt // __low_power_mode_4(); // Sleep until Button Press __bis_SR_register(LPM4_bits + GIE); __no_operation(); } else if (switch_state == 1) { P1OUT |= TRANS; // Switch On timeDog_on(); // Enable Watchdog Interrupt // __low_power_mode_0(); // Sleep with Timer __bis_SR_register(LPM0_bits + GIE); __no_operation(); } } } Code (common.h):
    #ifndef COMMON_H #define COMMON_H 1 #include <msp430f2013.h> #include <stdbool.h> #ifndef TRUE #define TRUE true #endif #ifndef FALSE #define FALSE false #endif #ifndef BOOL typedef bool BOOL; #endif #define LED BIT0 // P1.0 #define TRANS BIT1 // P1.1 #define PB BIT2 // P1.2 void scripted_wait(void); #endif Schematic:
    (not 100% complete, missing on board Reset pull-up, Decoupling Cap, and most of the EZ430 programming board stuff)

     
     
    The lights were made using some Slow Color Changing LEDs from a USB . These have a microcontroller inside providing current control and pwm. No resistor needed, and have a wide input range. But 3V is not enough for full brightness and colors, so the entire EZ430-F2013 stick was used. This is for a few reasons:
    Power. The LEDs need 4V + for brightness, while the msp430 needs 3.5V. The EZ430's USB input and regulator ensures I have both voltages. Plug and Play. I can reprogram the stick without having to worry about the 0.05" pins or wiring, or a programmer. Adaptability. Currently uses a 3x AA battery pack with a usb female connector, can easily be switched to a USB wall charger without any changes. I have multiple EZ430s lying around. After figuring out the electronics (A simple NPN transistor is used, while the base resistor is probably undersized as I did not actually measure the total LED current consumption, bad cde, bad.), the code took some testing. Using the Watchdog timer and LPM0 and LPM4, as well as a switch, the lights turn on for 30 seconds when first plugged into power. After turning off, it works as follows. LPM4 until the switch is pressed, then the lights turn on. Dropping into LPM0 as the Watchdog Timer uses the SMCLK, it counts to 5 minutes then turn off, or it can be turned off by pressing the switch again. No hardware debounce, just some for loop delays, it works fine as long as the switch isn't held in for long, otherwise it might turn off/on again.

     
     
    The Totem was made using a PVC pipe, with plaster shaped on top. The Base was made using three things. The first is the coroplast (corrugated plastic, like cardboard. Same stuff street signs are made of). The one used was fairly opaque, a more transparent one would have been better. Once it was cut to size and holes drilled for the leds, the second part is some cardboard rolled around it. Once taped, the dirty part of the job was getting Expanding Spray Foam onto the sides. This was harder than it should have been since the can I used had a broken nozzle. Simply hold it from the inside, spray the foam on, rotate, spray some more, let it dry, rotate, spray some more, etc (a coat hanger worked great to hold it up between rotations). I pressed some of the air out once it started drying, be careful as spray foam is incredibly sticky, and at some points pulls, while at others it gets stringy. Finally done and hardened to touch, some of the less rocky parts were cut off with an exacto knife. It was then painted using some grey primer. No highlighting needed due to the texture and grooves creating shadows.
    (Warning, some spray foams will melt/be eaten away by some spray paints. I used Great Stuff brand spray foam from Home Depot, and I forget the spray paint brand). Hint, there is multiple types. The beige one I used expands more (1" holes) while the pink one (fire/heat resistant) is stiffer and has less air pockets. If I had to do this again, I would use the pink for it all. This is a basic cosplay/halloween prop/decoration technique

    Once done, everything was assembled. He has to get an A.

  17. Like
    cde got a reaction from pine in EZ430 Soft Switch (DIY Skylanders Portal)   
    Form:
    Made a base similar to the Skylanders Portal, with some spray foam, coroplast, and Color Changing LEDs. This was added to a Totem Pole. Kid brother's school project.
     
     
    Function:
    Used an EZ430-F2013 as a simple Soft Switch, leds on 5 minute timer, to save the batteries from being drained.
     
    Code (main.c):
    #include "common.h" /*-------------- EZ430 Soft Switch, 5 Minute Sleep Timer using Watchdog LED is P1.0 D1 on EZ430 TRANS is P1.1 2n2222 Transistor Base PB is P1.2 Pushbutton P1.3-P1.7, P2.6, P2.7 free --------------*/ bool switch_state = 0; void cpu_init(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WatchDog Timer BCSCTL1 = CALBC1_1MHZ; // Set range to 1mhz Calibrated Range DCOCTL = CALDCO_1MHZ; // Set DCO to 1mhz Calibrated DCO // SMCLK = DCO = 1MHz P2SEL &= ~BIT6 & ~BIT7; // Disable External Oscillator Pins P2DIR |= BIT6 | BIT7; // Set as Output P2OUT &= ~BIT6 & ~BIT7; // Set as Output Low } void out_init(void) { P1SEL &= ~LED & ~TRANS; // Set Pins as GPIO P1DIR |= LED | TRANS; // Set Pins as Output P1OUT &= ~LED & ~TRANS; // Set LED and TRANS Pins to Off // Used for Testing, not needed as will not be visible // P1OUT |= LED; // Turn on EZ430 LED } void pushbutton_init(void) { P1SEL &= ~PB; // Set Button as GPIO P1DIR &= ~PB; // Set Button as Input P1REN |= PB; // Set Buttons Pull-Up/Pull-Down Mode P1OUT |= PB; // Set Buttons Pull-Up P1IES |= PB; // P1.2 Interrupt set for High to Low Transition (Active Low) P1IFG &= ~PB; // P1.2 Interrupt Flag Cleared P1IE |= PB; // P1.2 Interrupt Enabled } // Port 1 interrupt service routine #pragma vector = PORT1_VECTOR __interrupt void Port_1_ISR(void) { // Clear LPM & Disable Interrupts to Allow main() to handle commands before returning to sleep _BIC_SR_IRQ(LPM4_bits + GIE); // Check which button pressed if ( (P1IFG & PB) == 0x04) { if (switch_state == 0) switch_state = 1; else switch_state = 0; } // Debounce scripted_wait(); scripted_wait(); scripted_wait(); scripted_wait(); scripted_wait(); // P1.2 IFG cleared P1IFG &= ~PB; } volatile int second_count = 0; volatile int minute_count = 0; void timeDog_on(void) { WDTCTL = WDT_MDLY_32; // WatchDog Interval (Clock Source / Interval) (SMCLK / 32) // 1MHz / 32 = 31.25kHz // 1 / ( Clock Source / Interval ) = Freq in Milliseconds // Happens 32 times per second! Duh! Every 32766 Clock Ticks. DUH! IE1 |= WDTIE; // Enable WatchDog Interrupt, Still need to enable Global Interrupts } void timeDog_off(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WatchDog Timer IE1 &= ~WDTIE; // Disable WatchDog Interrupt minute_count = 0; // Reset Timer Count to 0 second_count = 0; // Reset Timer Count to 0 } // WatchDog interrupt service routine #pragma vector = WDT_VECTOR __interrupt void WatchDog_ISR(void) { second_count++; // 32 Interrupts per Second * 60 seconds = 1920 per minute if (second_count >= 1920) { second_count = 0; minute_count++; } if (minute_count >= 5) { switch_state = 0; // __low_power_mode_off_on_exit(); // Exit LPM at Interrupt End _BIC_SR_IRQ(LPM4_bits + GIE); } } void scripted_wait(void) { // SW Delay (how many seconds??) volatile unsigned int hick; hick = 10000; do hick--; while (hick != 0); } int main(void) { cpu_init(); out_init(); pushbutton_init(); __enable_interrupt(); // Turn on Switch when first plugged in for 30 seconds minute_count = 4; second_count = 960; switch_state = 1; // Setup Complete, now check state, run function, then go to sleep with interrupts while (1) { if (switch_state == 0) { P1OUT &= ~TRANS; // Switch Off timeDog_off(); // Disable Watchdog Interrupt // __low_power_mode_4(); // Sleep until Button Press __bis_SR_register(LPM4_bits + GIE); __no_operation(); } else if (switch_state == 1) { P1OUT |= TRANS; // Switch On timeDog_on(); // Enable Watchdog Interrupt // __low_power_mode_0(); // Sleep with Timer __bis_SR_register(LPM0_bits + GIE); __no_operation(); } } } Code (common.h):
    #ifndef COMMON_H #define COMMON_H 1 #include <msp430f2013.h> #include <stdbool.h> #ifndef TRUE #define TRUE true #endif #ifndef FALSE #define FALSE false #endif #ifndef BOOL typedef bool BOOL; #endif #define LED BIT0 // P1.0 #define TRANS BIT1 // P1.1 #define PB BIT2 // P1.2 void scripted_wait(void); #endif Schematic:
    (not 100% complete, missing on board Reset pull-up, Decoupling Cap, and most of the EZ430 programming board stuff)

     
     
    The lights were made using some Slow Color Changing LEDs from a USB . These have a microcontroller inside providing current control and pwm. No resistor needed, and have a wide input range. But 3V is not enough for full brightness and colors, so the entire EZ430-F2013 stick was used. This is for a few reasons:
    Power. The LEDs need 4V + for brightness, while the msp430 needs 3.5V. The EZ430's USB input and regulator ensures I have both voltages. Plug and Play. I can reprogram the stick without having to worry about the 0.05" pins or wiring, or a programmer. Adaptability. Currently uses a 3x AA battery pack with a usb female connector, can easily be switched to a USB wall charger without any changes. I have multiple EZ430s lying around. After figuring out the electronics (A simple NPN transistor is used, while the base resistor is probably undersized as I did not actually measure the total LED current consumption, bad cde, bad.), the code took some testing. Using the Watchdog timer and LPM0 and LPM4, as well as a switch, the lights turn on for 30 seconds when first plugged into power. After turning off, it works as follows. LPM4 until the switch is pressed, then the lights turn on. Dropping into LPM0 as the Watchdog Timer uses the SMCLK, it counts to 5 minutes then turn off, or it can be turned off by pressing the switch again. No hardware debounce, just some for loop delays, it works fine as long as the switch isn't held in for long, otherwise it might turn off/on again.

     
     
    The Totem was made using a PVC pipe, with plaster shaped on top. The Base was made using three things. The first is the coroplast (corrugated plastic, like cardboard. Same stuff street signs are made of). The one used was fairly opaque, a more transparent one would have been better. Once it was cut to size and holes drilled for the leds, the second part is some cardboard rolled around it. Once taped, the dirty part of the job was getting Expanding Spray Foam onto the sides. This was harder than it should have been since the can I used had a broken nozzle. Simply hold it from the inside, spray the foam on, rotate, spray some more, let it dry, rotate, spray some more, etc (a coat hanger worked great to hold it up between rotations). I pressed some of the air out once it started drying, be careful as spray foam is incredibly sticky, and at some points pulls, while at others it gets stringy. Finally done and hardened to touch, some of the less rocky parts were cut off with an exacto knife. It was then painted using some grey primer. No highlighting needed due to the texture and grooves creating shadows.
    (Warning, some spray foams will melt/be eaten away by some spray paints. I used Great Stuff brand spray foam from Home Depot, and I forget the spray paint brand). Hint, there is multiple types. The beige one I used expands more (1" holes) while the pink one (fire/heat resistant) is stiffer and has less air pockets. If I had to do this again, I would use the pink for it all. This is a basic cosplay/halloween prop/decoration technique

    Once done, everything was assembled. He has to get an A.

  18. Like
    cde got a reaction from Fred in Use MSP430G2553 internal reference voltage at an output pin   
    Always on, VCC/2 reference voltage? Have you tried a voltage divider with some high value resistors?
  19. Like
    cde reacted to Fred in What are you working on today/this week?   
    @@cde Those sound like excellent reasons. I should have realised from your post count and reputation that you'd thought it through and made a sensible decision, rather than some newbie who hadn't noticed they could be disconnected.
  20. Like
    cde got a reaction from shrenik in Use MSP430G2553 internal reference voltage at an output pin   
    Are you using it as a voltage reference, or as a regulator for power draw? Because it's only for reference, drawing more than 1mA is bad. Also, I believe only the 1.5V or 2.5V voltage reference generator can be output. The AVcc/2 is for internal reference only.
     
    See page 38, 46 and 47 of the 2553 datasheet for "VREF+" and section 22 (ADC10) specifically Figure 22-1 and section 22.2.3 of the family guide.
     
  21. Like
    cde got a reaction from roadrunner84 in What are you working on today/this week?   
    Simple one, but I am glad I got it working in a single revision Little Brother wanted to add some glow to a school project. Last one died from being left on (and 9v battery), so...
     
    A 5 minute soft-switch for some color changing leds. Using the EZ430 sticks I had, LPM0 and LPM4, Interrupts, the whole shebang. Turns on for 30 seconds when power is applied, then sleeps. Press the button, lights turn on for 5 minutes, using the watchdog timer, before going back to sleep. Press the button while the lights are on, they turn off and back to sleep.
     
    Simple pushbutton + transistor, and tapping the 5V pin for usb power (actually 3x AA but the EZ430's regulator is a 0.15V dropout LDO!). Codes and pics later.
  22. Like
    cde reacted to Automate in Products using MSP430   
    Well, not an MSP but the Wink home automation hub does have two TI CC1101 for 433Mhz communications with Lutron and Kidde devices.
     
    The board is nicely labeled with the 5 different wireless radios (WiFi/BT, Z-wave, Zigbee, Lutron, Kidde)
     

     
    http://community.smartthings.com/t/wink-hub-teardown/3288
     
     
  23. Like
    cde reacted to Antscran in MSP430 voice control over bluetooth   
    Hi all,
     
    I was playing around with the MSP430G2553 and the UART at the weekend, then remembered I had a cheap HC06 bluetooth module.  The result being a basic Android app that you can control your launchpad using voice control, it's far from polished but a bit of fun all the same 
     
    Project tutorial. C code and Android App http://coder-tronics.com/msp430-voice-control-over-bluetooth/
    Video demonstration  https://www.youtube.com/watch?v=8Z5ixK30Ddc
     
    Cheers,
    Ant
  24. Like
    cde reacted to spirilis in Serial port and I/O Expander, I2C   
    Wow that is neat, for when you need more serial ports and don't know where to find them.  There was an exhibit at the NY MakerFaire ( http://makerfaire.com/makers/the-grid-2/ ) where the folks were using a single Arduino Mega per "tile" because they needed the serial ports, and ended up still using SoftwareSerial to make up the balance.  Hideous waste of money IMO when UART expanders like this are available ;-)
  25. Like
    cde got a reaction from abecedarian in hardware UART at high bit rates?   
    Computer -> Launchpad USB -> MSP430, limited to 9600 (hardcoded in the launchpad).
     
    Midi Device -> MSP430, limited to greater than 115200, according to the family guide.
     
    The hardware uart is fast, the bottle neck is the launchpad to usb connection, which you won't need.
     
    In that case, you remove the two serial jumpers. You won't have the serial connection to the computer, but you will still have the debugging interface.
×
×
  • Create New...