Jump to content
43oh

MSP430 Annoyatron


Recommended Posts

By popular demand

 

//MSP430 Annoyatron
//Brian Gorman 2011

#include 
int i=0;
void main(void)
{
 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
 P1DIR |= 0x32;                            // P1.5 output
 CCTL0 = CCIE;                             // CCR0 interrupt enabled
 CCR0 = 32767;
 TACTL = TASSEL_1 + MC_1;                  // ACLK, upmode
 P1OUT = 0x00;
 int flow=0;
 int delays[]= {59,531,259,472,118,59,177,354,177};
 while(1)
 {
   if (i>(delays[flow]))
   {
     P1OUT ^= 0x32;                            // Toggle P1.5
     long z = 65000;                            // Delay
     do (z--);
     while (z != 0);
     P1OUT ^= 0x32;
     i=0;
     if (flow>9)
     flow=0;
     else
     flow++;
   }
   _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/ interrupt
 }
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
i++;
_BIC_SR_IRQ(LPM3_bits);
}

:evil:

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 .

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 impossible for someone to anticipate a beep.

it uses a prng to generate the delays rrather then an array, this way its way less predictable.

maximum delay is capped to 511 seconds using the bitshift [ from the 16bit unsigned to a more reasonable value ]

 

have fun :)

 

#include "msp430g2231.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.5 output
 CCTL0 = CCIE;                             // CCR0 interrupt enabled
 CCR0 = 32767;
 TACTL = TASSEL_1 + MC_1;                  // ACLK, upmode
 P1OUT = 0x00;
 unsigned int delay = 10;
 while(1)
 {
   if (i>delay)
   {
     P1OUT ^= PIEZO;                            // Toggle P1.5
     long z = 65000;                            // Delay
     do (z--);
     while (z != 0);
     P1OUT ^= PIEZO;
     i=0;

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

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
i++;
_BIC_SR_IRQ(LPM3_bits);
}

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

Link to post
Share on other sites

 

hmmm.Did miss it.. I kind of heard only two beeps, or may be I'm missing the point.

Yeah, it's not a very interesting video. The point is to stash it near a co-worker or something along those lines and over time these beeps will start compounding in their minds and annoying them. Ideally you will want to have a speaker at an annoying frequency.

Link to post
Share on other sites

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, can i use a value line device with only one timer to generate sound AND timing with one Timer ?

 

anyway, here is my code, which is completly based on brians code

 

https://gist.github.com/1049184

 

it uses an http://en.wikipedia.org/wiki/Linear_feedback_shift_register to generate the delays and silly wait loops to generate PWM.

 

have fun

Link to post
Share on other sites

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 ... Annoyatron

it now works only in low power mode, i don't really like whiles to wait. I also set the PIEZO as the green led, because i don't have a piezo with me right now, but changing it to the actual pin is trivial

 

proper credit given to this post

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...