Jump to content
43oh

MSP430 Annoyatron


Recommended Posts

Hey, just read your code :), VERY tidy!

A normal piezo actually needs a pwm like signal. its a bare crystal without any logic. when i ran brians code on my msp430 with a speaker or a piezo it just created a click when the piezo switched on and another when it turned off.

 

check out my code, it has a very simpel way of generating the signal, although i try to find a way to make it less battery consuming.

 

best regards

Link to post
Share on other sites
  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

hey brian   i just played with your source a little. i really like the annoyatron, wanted to plant one on a friend for quite some time. i made a little change which would make it completly imposs

hi again,   fixed my code ^^   brian: do you use piezo that automaticly generates a sound? because your code just turn port 1.6 on, then off without any PWM   second: as the code uses timerA, ca

I'm not really sure how a piezo works, but i think you just power it and it generates sound, so no PWM is needed.   I also made a twist to the annoyatron on https://github.com/sergiocampama/Launch .

I just use some radioshack piezo... i get a beep from it, although there are better things you can do... lastaid's code generates a more sophisticated tone for example...

 

sergiocampama, your code doesn't compile in IAR, something about the interrupt vector :( Seems like there is compatibility problem between IAR and Uniarch...

 

 

Error[Pe070]: incomplete type is not allowed C:\Users\brian\Documents\MSP\main.cpp 110

Error[Pe020]: identifier "interrupt" is undefined C:\Users\brian\Documents\MSP\main.cpp 110

Error[Pe065]: expected a ";" C:\Users\brian\Documents\MSP\main.cpp 110

Warning[Pe012]: parsing restarts here after previous syntax error C:\Users\brian\Documents\MSP\main.cpp 132

Error[Pe169]: expected a declaration C:\Users\brian\Documents\MSP\main.cpp 133

Warning[Pe012]: parsing restarts here after previous syntax error C:\Users\brian\Documents\MSP\main.cpp 135

Error while running C/C++ compiler

 

Total number of errors: 8

Total number of warnings: 4

Link to post
Share on other sites

Thanks for the info, I'll update my code to get PWM running...

 

Sorry Brian, I have never used IAR before, so I don't know the syntax for interrupts, the only thing I've ever known to msp programming is mspgcc... i despise windows, hahaha.. if you do get it running, send me the differences, to see if it's not too much of a hassle to make my code more portable

Link to post
Share on other sites

Hey :)

 

I savaged my Piezo from a keyfinder that was supposed to beep when you clapped your hands [ never worked, but the voice of a friend of mine set it off ]

 

i am currently trying to get the code running using only the internal clock, so there would be no need for an external clock source. this would make this ideal for "mass" production, a 25cent mcu like the msp430g2001 without any external components but a piezo and battery. build 20 of those and share :), make the world a worse place to live in :-D

Link to post
Share on other sites

Ok, so I fixed my code to use PWM, And only using 1 interrupt! It's kinda hard to understand at first, but is very well documented. I tested it with my headphones and is very annoying. The comments inside help change the frequency and duration of the beep. The selection of these values should be cleaner, but the purpose of the mini projects is to get people working with the hard stuff, not sugar coating it like EasyMSP (not trying to be disrespectful of that project, my philosophy is to teach the innards of the msp)

 

Using the VLO is a great idea actually, tell us if it works!

Link to post
Share on other sites
  • 8 months later...

What do you guys use to compile this?

 

I am trying to compile and load the code by lastaid in Code Composer Studio and I just get a ton of errors.

 

The line

#pragma vector=TIMERA0_VECTOR

 

Generates this error

Severity and Description Path Resource Location Creation Time Id

identifier "TIMERA0_VECTOR" is undefined Annoyatron annoyatron.c line 40 1330907885926 163

 

If I comment it out, it would at least compile but I don't think its running because I un-commented the line for the test mode

 

The code by sergiocampama errors out here:

//CCR0 timer interrupt, which toggles the LEDs

//Theres more than one definition for this interrupt, depending on the model

#ifdef TIMER0_A0_VECTOR

interrupt(TIMER0_A0_VECTOR) TIMERA0_ISR() {

#else

interrupt(TIMERA0_VECTOR) TIMERA0_ISR() {

#endif

 

Causing these errors

expected a "{" Annoyatron annoyatron.c line 129 1330908510489 172

expected a type specifier Annoyatron annoyatron.c line 129 1330908510489 170

extra text after expected end of number Annoyatron annoyatron.c line 110 1330908510489 169

identifier "uint64_t" is undefined Annoyatron annoyatron.c line 106 1330908510489 168

unnamed prototyped parameters not allowed when body is present Annoyatron annoyatron.c line 129 1330908510489 171

 

Am I using the wrong stuff to compile?

I have edited the code to reflect MSP430G2452 when necessary because the launchpad I have came with the new chip instead.

Link to post
Share on other sites

Sergio's code won't compile on CCS, it's written for mspgcc.

 

For lastaid's code to work, you have to change TIMERA0_VECTOR to TIMER0_A0_VECTOR, as it has a different name in the include file.

 

Whenever something like this happens (interrupt vector names aren't recognized), check the include file. Especially the timers are well known for causing headaches ;)

 

Cheers

TomKraut

Link to post
Share on other sites
Thanks for the info, I'll update my code to get PWM running...

 

Sorry Brian, I have never used IAR before, so I don't know the syntax for interrupts, the only thing I've ever known to msp programming is mspgcc... i despise windows, hahaha.. if you do get it running, send me the differences, to see if it's not too much of a hassle to make my code more portable

 

A few posts back ;)

Link to post
Share on other sites

Totally building this. My co-workers will never figure it out!

 

On a side note, the RadioShack buzzers don't require PWM input.

 

I'll just add here instead of a new post...

 

lastaid, I like what you did to make it random. I've taken your code and modified it a bit to use a sleep cycle on CCR1 instead of a do-while(wasn't working quite right for me that way) and I use the VLO for my timer clock source. It saves the use of a crystal and since this is all random who cares how off the VLO might be. Include was also changed for a 2001.

 

    #include "msp430g2001.h"

   #define PIEZO BIT6

   unsigned short lfsr = 0xACE1u;
   unsigned period = 0;         
   unsigned int getRnd (void);

   int i=0;
   void main(void)
   {
     WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
     P1DIR |= PIEZO;                            // P1.6 output
     BCSCTL3 |= LFXT1S_2;						// Set VLO
     CCTL0 = CCIE;                             // CCR0 interrupt enabled
     CCR0 = 12000;
     TACTL = TASSEL_1 + MC_1;                  // ACLK, upmode
     P1OUT = 0x00;
     unsigned int delay = 10;
     while(1)
     {
       if (i>delay)
       {
         P1OUT ^= PIEZO;                            // Toggle P1.6
         CCR1 = 800;			// Set 800 cycles to reset counter 12000 = 1sec length
         CCTL1 = CCIE;			// Enable CCR1 interrupt
         _BIS_SR(LPM3_bits + GIE);		//Go to sleep
         P1OUT ^= PIEZO;
         i=0;

         delay = getRnd() >> 7;
       }
       _BIS_SR(LPM3_bits + GIE);
                        // Enter LPM3 w/ interrupt
     }
   }

   // Timer A0 interrupt service routine for time between beeps
   #pragma vector=TIMERA0_VECTOR
   __interrupt void Timer_A (void)
   {
   i++;
   _BIC_SR_IRQ(LPM3_bits);
   }
   // Timer A1 ISR for beep length
   #pragma vector=TIMERA1_VECTOR
   __interrupt void Timer_B (void)
   {
   CCTL1 &= CCIE;
   _BIC_SR_IRQ(LPM3_bits);
   }

   unsigned int getRnd () {
     lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xB400u);   
     ++period;
     return lfsr;
   }   

 

This is in CCS btw.

Link to post
Share on other sites

this is beautiful :) and merciless :D

 

nice thing is without the crystal you can build tons of those with just an mcu [ 25c @1k ], 2 coin cells and one piezo. i wonder how much power it draws. on off switch could be a piece of paper between the coin cells paired with a prng starting var that maximizes the first interval.

 

i might try to build one deadbug style this weekend as small as possible :)

 

thanks for sharing,

 

lastaid

Link to post
Share on other sites

Careful with two cells, at 3v each you'll be way past the max for the MSP430.

 

Someone blew the fuses in my fluke at work so I can't measure current, but assuming maximum draw of 12mA for the buzzer beeping 15 times an hour for 85 milliseconds each and some careful guessing on mcu draw you're looking at about 10-20uA of average power consumption an hour.

 

I'm having trouble finding batteries that are small and between 3.2-3.6V. Might have to just stick 3x AAAA batteries together and have it run in the office for a year.

Link to post
Share on other sites

LR2032 is a rechargeable version of the common CR2032 coin cell. In addition to being rechargeable, it has a nominal voltage of 3.6. (aprox 4 volts fully charged, and unloaded)

 

The additional 0.6 volts allows running G series chips at full speed, and using blue and white LEDs with good brightness over the life of the battery.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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


×
×
  • Create New...