Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Empowering you to understand your world

How To Make An Anti-Reset Device For Surge Protection: Part 2

Replace the contents of the main.c file generated by CCS with the following code:

Source Code (Main.c)

1. #include <msp430.h>
2. /*
3. * main.c
4. */
5. int main(void) {
6. WDTCTL = WDTPW | WDTHOLD; //This stops the watchdog timer.
7. /*
8. * BIT0 is connected to the red LED, so we turn on BIT0 to turn on the red LED.
9. * BIT6 is connected to the green LED, so we turn on BIT6 to turn on the green LED.
10.* BIT4 is the pin that you'll connect the transistor which controls the relay to.
11.*/
12. 
13. P2DIR = 0;
14. P2OUT = 0; //This sets the output value of all the pins on port 2 to 0.
15.
16. P1DIR = BIT0; //This sets BIT0 to the output direction. This enables us to turn the red LED on as shown below.
17. P1OUT = BIT0; //This sets the output value of BIT0 to 1/switches it on. The red LED will now switch on.
18.
19. __delay_cycles(120000000); //This delays execution of the next two lines of code by two minutes.
20.
21. P1DIR = BIT6|BIT4; //This sets BIT6 and BIT4 to the output direction.
22. P1OUT = BIT6|BIT4; //This sets the output value of BIT6 and BIT4 to 1/switches them on. The green LED and the transistor.
23.
24. return 0;
25. }

Let’s take a look at the code above.

Line 1 includes the msp430 header, which corresponds to the MCU we are using. Line 6 stops the watchdog timer, as the comment suggests. The watchdog timer periodically performs a system reset, which can be useful if your program hangs. If it isn’t disabled, it can be periodically ‘serviced’ to let it know the device is operating properly, so it won’t reset. In this case, we’ll just disable it for now.

Line 13 effectively sets all pins on port 2 to the input direction, followed by line 14 which sets their output values to 0, switching them off. This reduces energy wastage. Only do this if you’re not using any of the pins on port two. In this project, we aren’t. Remember the adage: turn things off when you’re not using them.

Line 16 sets Pin 1.0 (also the red LED) to the output direction, enabling us to switch it on. Line 17 is where we finally switch on Pin 1.0 (and hence, the LED, since it is connected to that pin).

Line 19 creates a 2-minute delay before we finally switch on the green LED and the relay, as explained below.

Line 21 sets pins 1.6 and 1.4 to the output direction, enabling us to switch them on later. Pin 1.6 is connected to the green LED, so switching on pin 1.6 also switches on the green LED. Pin 1.4 will be used to switch on the relay which controls the appliances plugged into our anti-reset device.

Line 22 sets the output values of pin 1.6 and 1.4 to 1. This is how we switch pins on. The green LED and the relay will now switch on, restoring power to your appliances. The red LED will switch off automatically, because we assigned new values to the P1DIR and P1OUT registers (BIT6 and BIT4) which overwrote the BIT0 value we wrote to them earlier.

Parts List

  1. Bipolar Junction Transistor (or any other applicable transistor). I used a 2n6284 because that’s what I had at the time, but it is more than necessary – $2. (update: this could cost far more, depending on the brand and store). Datasheet/Pinout.
  2. A 125-250 volt, 15 amp relay$5. Datasheet.
  3. 1/2 watt, 5 kOhm resistor to connect the transistor’s base to the development kit’s GPIO pin (pin 4) (5.6 kOhms will do as well) – $0.13.
  4. Texas Instruments Launchpad MSP430 G2 development kit$10.

The total cost of the parts for me was $18, but can be significantly less if you use a cheaper transistor.

Sparkfun explains the basics of transistors clearly, so i’d recommend reading their tutorial if you don’t already know how to use transistors.

[button link=”https://www.kompulsa.com/how-to-make-an-anti-reset-device-for-surge-protection/”]Back To Page 1[/button]

Subscribe to our newsletter
Get notified when new content is published