Msp432 blink led

The Ports are usually related to the following registers:. The PxDIR register is used to configure a particular port pin as input or output. Each bit corresponds to a pin on the port. Setting a particular bit makes that particular pin output and resetting it makes it input i. So to make the first pin P1.

How to Blink an LED in C (avr, msp430)

To write the values to the pins we set a bit in the PxOUT register to make the pin high and reset the bit to make it low. The following code is used. There are other macros defined for other registers as well which we will be seeing some other time. To read a particular value we need to mask the PxIN register to check the bit. Since here we need to check the fourth pin or pin P1. This is done as follows.

If the expression is equated to these values in a if condition then the required action can be written in the body of the loop. Now coming to blinking an led. The following code is written. The code is self explanatory. The loop is to give a delay so that toggling is seen. Compile the code.

It might give a warning as statement unreachable which is because of the return statement. Deleting it will give zero warnings.

Then set the target options and hit download and debug. Press F5 to run the program or F11 to start Single step debugging. But keep in mind that this line needs to be included else the cpu will reset every 32ms. A program to toggle LED when a switch is pressed. The delay should be properly selected to compensate for the switch debouncing effect.Guess what it is called — Blink. NOTE: On most Arduino boards there is an LED soldered right by pin 13 — it is actually connected to pin 13 — so if you do not have an LED laying around or a resistor for that matteryou can use the board mounted LED — it will blink with the same sketch.

This image was made using Fritzing. Notice the comments at the top of the program. It is always a good idea to take time and see what the programmer has to say about the sketch they wrote. The comments will likely be concise, describing how the program works or what it should accomplish. A few may even tell you how to connect the circuit. Recall that the setup function is in almost every Arduino sketch you encounter.

Inside the curly braces is code that will only be run once by the Arduino. For this sketch notice the function pinMode is inside the curly braces of the setup function. Let me start by saying that pinMode is a wonderful function.

If you recall, functions can take arguments. The pinMode function takes two arguments — it wants a pin number and a mode for that pin. The pin number is easy, 0 to 13 for digital pins, and A0 to A5 for analog pins. In this example, we want to light an LED, this requires that voltage is applied at pin Keep in mind that setting the mode of the pin to OUTPUT does not apply a voltage, it enables the pin to supply a voltage once it is programmed to do so.

Moving on to the final block of code, we come to our favorite and ubiquitous function void loop …. You may recall that void loop runs over and over again. In this loop, we see two functions: digitalWrite and delay. There is a voltage difference between the pin and ground, thus current is able to flow through the LED. Variables are awesome like that — they can take the place of numbers and are much easier to change and track. Once digitalWrite function has been executed, the LED will get bright — we just applied 5 volts, so hey, that makes sense.

The next thing we do is delay the Arduino sketch to enjoy the bright glow of our LED. To do this, we use the delay function. The delay function takes one argument — the number of milliseconds you want the program to delay. In this case, we want milliseconds, which equals one second. Our LED will glow for exactly one second.LED blinking is the simplest and most commonly used example for the beginners. It acts as a stepping stone for microcontroller development.

It gives the basic idea of working with the controllers in a practical environment. Similarly, when we want to sense an external signal such as push-button, switch, digital signals with pic microcontroller, the GPIO pins will be used as a digital output pin.

For example when we use keypad interfacing with a microcontroller or we use a switch with a microcontroller we use pins as input. Before we see how to interface an LED with pic microcontroller, we need to understand some basics of a light-emitting diode such as its current and voltage requirements.

Subscribe to RSS

How much does it require to turn it on? What is the forward voltage rating of an LED? As its name suggests, it is a light source that emits light when we apply a voltage across its terminal. We usually use it as an indication signal in embedded systems projects. For example, it is used to indicate either power is applied to the circuit or not. Some other applications are:.

This picture shows an electronic symbol and a physical diagram of light-emitting diodes. As you can depict from the diagram that it consists of two-terminal such as anode and cathode. An anode is a positive terminal and we connect positive terminal of power supply to this terminal.

Similarly, we connect the negative terminal with the cathode. Before interfacing LED with Pic microcontroller, we should find its forward current and forward voltage. The intensity of lights that emits from it depends on the forward current.

msp432 blink led

Greater the forward, the higher will be light intensity. But every device has a peak forward current and voltage. It cannot withstand the current and voltage greater than the peak value. Note: millicandela is a light intensity unit that is used to measure light brightness. The forward voltage depends on the color and size of an LED. This table shows the forward voltage drop of different color LEDs according to color and size.

Therefore, we can conclude from the above table that the average forward voltage drop is about 2V. The typical forward current is about 10mA.

msp432 blink led

But you should select the device according to your brightness requirement. Last but not the least, this section lists all details on how to interface an LED with a pic microcontroller. But you can always find a peak forward current value from the datasheet. We can easily calculate the current limiting resistor value R1 by using this equation:. You must be thinking why do we need to use a resistor while interfacing an LED with Pic microcontroller?

According to the PIC18F microcontroller datasheet, the maximum current a single pin can provide up to 25mA.

Another reseason is because of the peak forward current of the light-emitting device. Each pin can be used both as a digital input or a digital output. As its name suggests, this 7-bit register is used to set the direction of data. In other words, it defines the nature of pin either as a digital input or a digital output.

Note: RC4 and RC5 pins can be used only as digital input pins only.We will do that by controlling the brightness of a LED by varying the potentiometer. So the potentiometer will be attached to an analog pin of the MSP to read its analog voltage, hence it is recommended to know go through the ADC tutorial before proceeding. This signal is set high 3. There are two important parameters for a PWM as discussed below:. There is plethora of applications for PWM signals in real time, but to give you an idea the PWM signal can be used to control servo Motors and can also be converted to Analog voltage which can control the brightness of the brightness of an LED.

Check all the PWM related projects here. This is a simple and most commonly used circuit for this purpose. The circuit just includes a Resistor and a capacitor in series as shown in the below circuit. So what basically happens here is that when the when the PWM signal is high the capacitor charges up though the resistor and when the PWM signal goes low the capacitor discharges through the stored charge. This way we will always have a constant voltage at the output which will be proportional to the PWM duty cycle.

In the graph shown above, the Yellow coloured one is the PWM signal and the blue colour one is the output analog voltage. As you can see the output wave will not be a pure DC wave but it should very well work for our application.

If you need pure DC wave for other type of application you should design a switching circuit. The circuit diagram is pretty simple; it just has a potentiometer and a Resistor and capacitor to form a RC circuit and the Led itself.

The potentiometer is used to provide an analog voltage based on which the PWM signal duty cycle can be controlled. The output of the pot is connected to Pin P1. Then we have to produce a PWM signal, which can be done by using the pin P1. It is very important to understand that not all pin on the MSP board can read analog voltage or can generate PWM pins. The specific pins which can do the specific tasks are shown in the figure below.

Always use this as a guidance to select your pins for programming. Assemble the complete circuit as shown above, you can use a breadboard and few jumper wires and easily make the connections.

Once the connections are done my board looked like as shown below. Once the hardware is ready we can start with our programming. The first thing in a program is to declare the pins that we are going to use.

msp432 blink led

Here we are going to use the pin number 4 P1. Complete program is given at the end. Next we come into the setup function. Whatever code is written here will be executed only once, here we declare that we are using this 4 th pin as an output pin since PWM is output functionality.

Note that we have used the variable PWMpin here instead of the number 4 so that the code looks more meaningful. Finally we get into the loop function.

Whatever we write here gets executed again and again.Previously, we played with the CCS cloud tools. The latest version is 8. There two cases you must use the CCS local version. After you installed the CCS local version, you will see the main page. The IDE is based on Eclipse. Select the MSP board. Question1: If you change the P1.

Multiple Blinking LEDs at Different Rates

What you will get? Can you still get the interrupt? You can setup one breakpoint inside the interrupt handler.

When you will get the interrupt? If you want to try the interrupt via register access, you can use the following code to realize the same function. When you compile the project, it will show driverlib. Due to the limitation of the CCS Cloud, you cannot change the include path manually. Another option is to use the CCS local version. You can add the path manually. But, TI recommends to import the sample code directly to save the time for path configuration. In the previous code, we first configure P1.

You can run the previous code and the LED in the board will blink based on the frequency setup. Comparing with the LED blinking in Lab1, this code utilizes the timer interrupt to toggle the LED without blocking the main function, i. Clock system CS is the key to any digital system. The MSP contains multiple clock sources. It also controls the mapping between the sources and the different clocks in the device. The MSP clock module can be configured to operate without any external components, with up to two external crystals, or with resonators, or with an external resistor under full software control.

Therefore, the presence of the crystal allows the full range of low power modes to be used. Most peripherals on the device can select which of the internal clocks to use to operate at the desired speed. There are five system clocks inside the MSP to drive different module. The default configuration is shown.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It only takes a minute to sign up.

Im currently working on setting up led blinking on the board but the human's eyes cannot see it but when i record using camera i can see the blinking after extracting the frames. Since you appear to be concerned with flicker- If there is relative motion between the light source and your eye, the image may appear to "break up".

The sensors in your retina act as if they integrate over a period of time in the milliseconds, but you can see a much more brief flash- it just appears dimmer for shorter durations below the flicker fusion frequency. For example, if you whack yourself over the head with a book you may be able to see a 1kHz flash break up, but the camera frame rate will at best do some aliasing thing with the shutter speed unless it is a high speed camera.

This is not a coincidence, the camera frame rate is made just fast enough to appear steady, which is much slower than what can be picked up with persistence of vision. Flicker is also more perceptible in peripheral vision, Hz is annoying for many people- probably an evolutionary adaptation to help our ancestors pick up rapid motion of predators or prey out of the corners of our eyes.

If there's no motion the light may appear steady above some frequency in the tens of Hz, but it will vary a bit with duty cycle, I think, probably getting somewhat worse as the duty cycle gets shorter due to the logarithmic response. Sign up to join this community. The best answers are voted up and rise to the top. Home Questions Tags Users Unanswered. Asked 2 years, 4 months ago. Active 2 years, 4 months ago. Viewed times. GirlSpag GirlSpag 3 5 5 bronze badges. You can easily see a light flash of microseconds duration, if sufficiently bright.

If the camera can see it, your eye probably can, unless you go outside the visible spectrum eg, infrared. Steady-appearing light is visible. Active Oldest Votes. Spehro Pefhany Spehro Pefhany k 9 9 gold badges silver badges bronze badges. The nice thing about this is that you don't need any fancy equipment to experiment beyond the camera and at least one functioning human eye. A micro, a bench frequency generator or even a nasty old will work.

I plan to extract every 30 frames per second. If it is to secretly pass information, the bar is much higher.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.

MSP430 LED’s & Switches

Post as a guest Name.After doing this, you will get a window mentioned below. Enter your project name, select family as MSPand now variant is mspg Remember, this is a critical step. To check your option, refer your chip on the Launchpad.

It has a mentioned of the variant. For all the tutorial, I will be using mspg as the chip, so kindly change accordingly. In the bottom box, select Empty project with main.

Have a look at the basic structure of the code already written. The first line is your header file that depends upon the variant; you choose while creating your project. Next step is the main function. Inside the main function you can see, initialization of watchdog timer. The MSP and many of the new generation microcontroller includes a special timer called the Watchdog Timer.

How to use Input output pins of MSP430G2 LaunchPad

However, many developers used this timer in a scenario when they want to reset the controller when certain conditions are met. For now remember to turn off the watchdog timer, as we will discuss it when we talk about timers in the tutorial. Now, here comes the task we want to do i. Since the leds are on port1 and on pin 0 and 6 respectively, we will first have to make this pin or declare these two pins as whether they are acting as output or input.

Here comes the use of P1DIR register. P1DIR register is responsible for making your pins as output or input.

msp432 blink led

Since we want to configure pin 6 and pin 0, we assign P1DIR as. Next is to specify the particular pin of the particular port as high or low. For that, you can use P1OUT as the register. Since we are initializing things, I set the led on P1. Next is the infinite while loop, in it there are two steps. First is toggling and other is providing a delay after each toggle to see the toggling effect successfully. This will reverse the state of pin6 and pin0.

So initially pin6 was low it will become high, and pin0 will become low. This process would go on continuously. The important point is there is no inbuilt delay function is MSP, so you have to use for a loop to provide the delay. The next is step is nothing. CCS has automatically closed the while loop, and hence we have to burn the program obviously after building it.

Before burning you can cross-check the code once again from below. After clicking on debugging, you will get a popup related to power saving, simply click proceed. The moment you debugged the code, your program got burnt in the controller.

Clicking on a resume starts the program. The debug screen will look like the one, as given below. Notice, it also has the function of breakpoints, and single-step or continuous run while are essential while debugging and YES, on the Launchpad you would be able to see the Red and Green Led toggling.

After doing this, you will get a window mentioned below Enter your project name, select family as MSPand now variant is mspg