Jump to content
Sign in to follow this  
villekille

Making a programmable timer switch with the launchpad

Recommended Posts

I am planning to make a timer switch using MSP430F5529 launchpad and a relay board for microcontrollers  like this: http://www.ebay.co.uk/itm/2-4-CHANNEL-5V-RELAY-MODULE-BOARD-for-ARDUINO-ARM-AVR-DSP-RASP-PI-MSP430-19102-/251501033197?pt=UK_BOI_Electrical_Components_Supplies_ET&var=&hash=item3a8ea136ed

 

I wish to have an output ON for 3 minutes every 60 minutes. So there is not really a need to have a 24 hour clock or anything like that, just to get it to switch the output ON  for 3 minutes and then turn it off and ON again after another 60 min and continue doing this as long as it is powered. 

 

I just find it hard as a beginner to do this. Could anyone more experience give me some info on how this could be done in the code? Hardware wise I think it is simple but I just don't understand how to program this.

Share this post


Link to post
Share on other sites

ok I figured out. Here is a code to make it happen. "Seconds" is the time we want the timer to wait before switching output on, for one hour this should be 3600. And "secon" is a value in secons, for how long you wish to keep the output on, for 3 minutes this should be 180.

#include <msp430.h>
unsigned int seconds, secon;
int main(void)
{
  seconds = 0;
secon  = 0;  
  WDTCTL = WDT_ADLY_1000;                    // WDT 1000ms, ACLK, interval timer
  SFRIE1 |= WDTIE;                          // Enable WDT interrupt
  P1DIR |= 0x01;                            // Set P1.0 to output direction
  P1OUT &=~0x01;
 
  
  
 
  __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, enable interrupts
  __no_operation();                         // For debugger
}
 
// Watchdog Timer interrupt service routine
#pragma vector = WDT_VECTOR
__interrupt void WDT_ISR(void)
{
 
if (seconds++ >120)
{
  P1OUT |= 0x01;  
  secon++;
 
      if (secon >30)
{
  P1OUT &=~0x01;  
  secon=0;
  seconds=0;
}
}
 
}

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

Sign in to follow this  

×
×
  • Create New...