HANcoder/Training Material/AutomaticLightControlSystem/6

From OpenMBD
Jump to: navigation, search

<<<Go back to part 5

>>>Go to part 7

LED Control System Part 6

Part 6: Connecting the input to the output

The next step is to connect the input of the potentiometer to the PWM block to enable you to change the output of the PWM block with the potentiometer. Delete the Constant block and delete the Terminator block and connect the Analog Input to the PWM Output. Build the model and flash the program onto your Olimexino and check if you can change the LED’s intensity by turning the potentiometer.

Once you've flashed the program onto the Olimxino and you turn the potentiometer to change the intensity of the LED, you’ll discover that the potentiometer will make the LED go from 0% to 100% intensity on only a small part of its range. The microcontroller converts the analog signal of the potentiometer to a value of 0 to 4095. The PWM block needs an input of 0 to 1023. Therefor you'll need to divide the PWM signal by 4 to use the full range of the potentiometer to drive the LED.

To overcome this problem, you’ll need to add a Gain block in between the Analog Input and the PWM Output. The Gain block can add an amplification factor (gain) to a signal. Because you need to divide the input by 4 to make the range of the potentiometer match the range of the PWM signal, you'll need to add a gain of ¼ = 0.25. Make sure to set the Output data type of the Gain block to the correct data type.


<<<Go back to part 5

>>>Go to part 7