Monday 4 January 2021

Ultrasonic Sensor HCSR04 with MSP430

The explanation for this project can be found here: Project Link

Subscribe to the channel for more such content.

Below is the code:

#include "msp430.h"

#define TRIG_PIN BIT1 // Corresponds to P2.1

#define ECHO_PIN BIT1 // Corresponds to P1.1

//#define TXD BIT2 // TXD on P1.2

volatile unsigned long start_time;

volatile unsigned long end_time;

volatile unsigned long delta_time;

volatile unsigned long distance;

void wait_ms(unsigned int ms)


unsigned int i;

for (i = 0; i <= ms; i++)





#if defined(__TI_COMPILER_VERSION__)

#pragma vector = TIMER0_A0_VECTOR

__interrupt void ta1_isr(void)


void __attribute__((interrupt(TIMER0_A0_VECTOR))) ta1_isr(void)



switch (TAIV)


//Timer overflow

case 10:


//Otherwise Capture Interrupt


// Read the CCI bit (ECHO signal) in CCTL0

// If ECHO is HIGH then start counting (rising edge)

if (CCTL0 & CCI)


start_time = CCR0;

} // If ECHO is LOW then stop counting (falling edge)



end_time = CCR0;

delta_time = end_time - start_time;

distance = (unsigned long)(delta_time / 0.00583090379);

//set a range

if (distance / 10000 >= 2.0 && distance / 10000 <= 10)


//turn on LED P1.0;

P1OUT |= BIT0;



P1OUT &= ~BIT0;




TACTL &= ~CCIFG; // reset the interrupt flag


void reset_timer(void)


//Clear timer



void main(void)


// Stop Watch Dog Timer


// Set ECHO (P1.1) pin as INPUT


// Set P1.1 as CCI0A (Capture Input signal).


// Set TRIGGER (P2.1) pin as OUTPUT


// Set TRIGGER (P2.1) pin to LOW


P1DIR |= BIT0;

P1OUT &= ~BIT0;

//P1DIR |= BIT6;

/* Use internal calibrated 1MHz clock: */

BCSCTL1 = CALBC1_1MHZ; // Set range


BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 1MHz

// Stop timer before modifying the configuration


CCTL0 |= CM_3 + SCS + CCIS_0 + CAP + CCIE;

// Select SMCLK with no divisions, continuous mode.

TACTL |= TASSEL_2 + MC_2 + ID_0;

// Global Interrupt Enable


while (1)


// send ultrasonic pulse


// Enable TRIGGER


// Send pulse for 10us


// Disable TRIGGER


// wait 500ms until next measurement




Wednesday 30 December 2020

Chevening Interview Prep Questions (few examples)

Below are the set of questions that you may want to consider during the interview prep session:

1. Why do you want to study in the UK?

2. Why did you choose this course/program?

3. What do you intend to do after the Chevening MSc program?

4. State some examples exhibiting your leadership skills.

5. How will this scholarship help you in the development of your home country?

6. What will you do if you don't get the scholarship?

7. What are your greatest achievements?

8. What are your strengths and weaknesses?

9. Why did you select these three universities?

10. Why is a particular uni your first preference?

11. Which leader (could be from your field) do you admire and why?

12. Why are you interested in Chevening Scholarship particularly (the main advantage is the network, think of other reasons as well)?

13. What are the other activities which you are interested in doing in the UK besides focussing on academics?

14. What changes would you like to bring about in your field in your home country?

15. Are there any challenges that you face during your time in the UK (eg. staying away from the family) and would you able to successfully complete the MSc. program?

16. State any examples showcasing your networking skills or do you have the networking skills and how will you use it to leverage the condition in your home country (in your field)?

17. Do you need an MSc. degree to bring about changes in your field of interest (in your home country)? Justify why an MSc. program a prerequisite for you.

18. Is your work experience in line with the field that you want to pursue your MSc. in?

19. Have you already got admission in any of the universities (it will be best if you have already got the admission)

20. Would you like to change the preferences of uni? (rearranging the order)

21. Do you have any questions?

Also, prepare the most commonly asked questions:

1. Tell us something about yourself (keep this answer brief and to the point)

2. Where do you see yourself in 5 to 10 years time?

3. Your strengths and weaknesses.