Windows on Device Project Practice 1-PWM dimming

Source: Internet
Author: User

In the previous article, "Wintel IoT platform-windows IoT starter Guide", we explained the setup of the Windows on device hardware preparation and software development environment, as well as a presentation of the Hello Blinky project. At the beginning of this article, we enter the project practice section.

Because Windows on device is designed with Galileo as the hardware platform, its peripheral interface is also compatible with the Arduino standard. In addition, the programming model also references the wiring Language used in the Arduino.

1. PWM principle

The pulse width modulation is commonly referred to as PWM, which is translated into pulsed-wide modulation, referred to as pulse width modulation. Pulse width modulation (PWM) is a digital encoding of the analog signal level, because the computer can not output analog voltage, can only output 0 or 5V of digital voltage value, we use a high-resolution counter, using the square wave duty ratio is modulated by the method to encode a specific analog signal level. The PWM signal is still digital, because at any given moment the DC power to the full amplitude is either 5V (on) or 0V (OFF). A voltage or current source is a repeating pulse sequence with a pass (on) or off (off) that is added to the analog load. When the DC power supply is added to the load, when the power supply is broken. Any analog value can be encoded using PWM as long as the bandwidth is sufficient. The output voltage value is calculated by the time of the pass and break. Output voltage = (on time/pulse time) * Maximum voltage value.

PWM is used in many places, dimming lights, motor speed, sound production and so on. The three basic parameters of PWM are as follows:

    • 1, Pulse width change amplitude (min/MAX)
    • 2. Pulse period (the reciprocal of the number of pulses in 1 seconds)
    • 3, Voltage height (for example: 0v-5v)

The Arduino controller has 6 PWM interfaces, namely the Digital Interface 3, 5, 6, 9, 10, 11, and also, on the Galileo, these interfaces support PWM output.

2. Components and hardware connections

The components to be used in this practice project are:

    • Potentiometer Module * *
    • Straight Plug Led*1
    • 220ω Straight Plug Resistor
    • Bread Plate * *
    • Bread Plate jumper several

As the analog value input of the Galileo, we receive the analog port, the LED light we receive the PWM interface, so that by producing different PWM signal can make the small lamp has different brightness changes.

The schematic and hardware diagram of the connection is as follows:

3. Source code Parsing

In the process of writing the program, we will use the analog write Analogwrite (PWM interface, analog value) function, for the analog write Analogwrite () function, this function is very simple to use, we read the analog value of the potentiometer signal in this experiment and assign it to the PWM The interface allows the light to produce corresponding brightness changes, and then on the screen to show the analog value of reading, you can understand that the program is in the analog value of the experiment program to add the analog value to the PWM interface this part, the following is a reference to the source program, using the analog input interface 0 and the digital interface 11.

Main.cpp:Defines the entry point for the console application.
//

#include "stdafx.h"
#include "arduino.h"

int _tmain (int argc, _tchar* argv[])
{
return Runarduinosketch ();
}

int Potpin = 0;//Define the analog interface 0
int Ledpin = 11;//defines the digital interface one by one (PWM output)
int val = 0;//A variable value from the sensor

void Setup ()
{
Todo:add Your code here
Pinmode (ledpin, output);//define the Digital interface 11 for the output
Note: The analog interface is automatically set to input
}

The loop routine runs over and over again forever:
void Loop ()
{
Todo:add Your code here

val = Analogread (Potpin);//Read the analog value of the potentiometer and assign a value to Val
Log (L "Val:%d\r\n", Val); Output values in the Debug window
Analogwrite (Ledpin, VAL/4);//Turn on LED and set brightness (maximum PWM output is 255)
Delay (10);//delay 0.01 seconds

}

4. Debug results

Start Galileo, connect using Telnet, and then click Debug. The program will be downloaded to the Galileo via the network port. We turn the knob of the potentiometer, not only can see the changes in the value on the screen, but also can clearly see our bread board LED light brightness is also changing.

Debug the video link below, you can see the effect of dimming: http://v.youku.com/v_show/id_XODU0NjY1OTQw.html

Windows on Device Project Practice 1-PWM dimming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.