In this exercise, you will wire and program an LED to “breathe” on and off (example).
Item | Quantity | Detail |
---|---|---|
5V Power Supply | 1 | |
CY8CKIT-042 (Pioneer or BLE) PSoC® 4 Evaluation Board | 1 | |
USB micro B cable | 1 | Included in PSoC® kit |
AOTF2618L MOSFET driver circuit | 1 | (Digikey) (datasheet) |
FAN8100N H-Bridge driver circuit | 1 | (Digikey) (datasheet) |
Benchtop Power Supply | 1 | Available at lab workbenches |
Benchtop Multimeter | 1 | Available at lab workbenches |
Gear Motor (model 1) OR | 1 | Available at lab workbenches (Jameco) (datasheet) |
Gear Motor (model 2) | 1 | Available at lab workbenches (AllElectronics) (datasheet) supplied in class, 1 per station (do not take with you) |
Concept | Importance |
---|---|
a. Which ports on the PSoC® you can connect external LEDs and buttons to. | Needed in order to control an external LED and read the button in software. Can be connected to most unused GPIO pins listed in the Appendix of the appropriate Prototyping Kit Guide. (also discussed in Section 4.3.5 of the Pioneer Kit and Section 5.1.4 of the BLE Kit). Make sure you are not connecting to the PSoC® 5LP GPIO Header. The PSoC® 5LP is only used as a programmer. |
b. What the logic high (1) voltage coming out of the PSoC® I/O (GPIO) pins is. | Needed in order to calculate a proper current-limiting resistor value for an LED. Study section A.2 (including all subsections) in the appropriate Prototyping Kit Guide to determine where power and ground pins are located on the PSoC® board. With the PSoC® board plugged into the computer via USB, measure the supply voltage of the PSoC® board using a multimeter. This will be equal to the logic high voltage on a GPIO pin. |
c. How to calculate the value of a series current-limiting resistor for an LED circuit. | Needed to prevent an LED connected to a GPIO pin from drawing too much current and burning out. Example and equation (based on Ohm’s Law) can be found in Section 3.5 of Scherz & Monk. |
d. What a pullup resistor is and why it is necessary to properly interface a switch to a microcontroller. | Needed to understand how to properly wire the switch so that it is always providing a voltage to the PSoC®. Can be found in Section 12.6.9 of Scherz & Monk. |
e. What a PWM signal is. | Needed to understand the output of the PWM component. Can be found in Section 13.5.3 and 14.4 of Scherz & Monk. |
f. How to increment and decrement a counter using a for() loop in C. |
Needed to change the duty cycle (Compare value) of the PWM. See Loops in C for more information. |
Figure 1: Example of connecting an external LED to a microcontroller using a transistor to switch |
Create a MOSFET motor circuit above to accommodate a LED and current limiting resistor, as seen above. Note the power source.
Note that the LED uses the 5V regulated voltage from the ICC1 voltage regulator or the benchtop power supply, rather than unregulated power.
Figure 2: LED symbol, wording, and leads, from https://commons.wikimedia.org/wiki/File:%2B-_of_Led.svg |
Connect the CY8CKIT-042 (or CY8CKIT-042-BLE) to your computer via USB.
In PSoC® Creator™, create a new project for the CY8CKIT-042 (or CY8CKIT-042-BLE) in a new workspace for HW3.
In the Top Design, create a PWM(v3.30)
component (not the TCPWM mode version). Select One Output
. Set the period to “Max” (remember this value) and the compare value to ```0``. Leave all other settings at their defaults.
Create a Clock component and wire it to the clock input on the PWM. Leave the clock at its default frequency.
Create one (1) Digital Output pin.
Strong drive
.Build the project once in order to expose the newly specified hardware to the coding API
Open main.c
and add two lines of code in the line before the for(;;)
loop: one to initialize and one to start the PWM subsystem.
Hint: In the Top Design, right-click on the PWM component, choose “Open Datasheet…”, scroll to the Application Programming Interface (API) section, and find the line of code to start the PWM component. Remember to use the name of your specific instance of the PWM component in the Top Design (e.g.,
PWM_1_FunctionName()
).
Declare a new variable, ii
, as an integer and initialize it to zero.
Inside the main for(;;)
loop add the following code:
Add an inner for()
loop that increments ii
from 0
to the PWM’s “max” value (logged above). Execute a CyDelay(5)
in each iteration of the loop.
for()
loop, change the duty cycle (via changing the Compare value), passing in the value of ii
.Hint: In the API section of the PWM component datasheet, find documentation about the function of the “Compare” value.
After the first inner for()
loop, copy a duplicate of the first for()
loop.
255-ii
).Compile, download, and run your solution working with the modified AOTF2618L MOSFET driver circuit from ICC3. The LED should “breathe” using the PWM component.
Continue on to PWM Tutorial 2 – Using PWM and an H-Bridge to Control Motor Speed