联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2022-04-24 10:56

University of California Santa Cruz Baskin School of Engineering CSE121 & CSE121L Spring 2022 Lab 1 Copyright ? 2022 David C. Harrison. All rights reserved.


CSE121 & CSE121L Spring 2022


Lab 1


In this lab you will gain basic familiarity with the PSoC 6 BLE Prototyping Kit (which we’ll just call ‘PSoC 6’ from

now on) and the PSoC Creator IDE you will be using for subsequent labs.


Specifically, you will write programs to blink the PSoC 6’s internal LEDs in four different ways. All programs are

examples of setting the values (voltages) of digital pins on the PSoC 6.


This assignment is worth 5% of your final grade.



Setup


1. Connect your PSoC 6 to a USB port on a lab workstation using the USB 2.0 A male to female cable from your

components kit and the short USB A female to micro male cable from the PSoC 6 package.


2. Update the firmware on your PSoC 6 by starting PSoC Programmer, selecting the Utilities tab and clicking

Upgrade Firmware. Then disconnect then re-connect your PSoC 6.


3. Start PSoC Creator and create a workspace.

File New Project…

Select Workspace then Next

Set Workspace name to CSE121 and click Finish


4. Set the PDL V3 path to C:\Program Files (x86)\Cypress\PDL\3.1.5 ( or 3.1.3 )

Tools Options Project management


5. Create an empty project that can be used to re-set you PSoC 6 to a known state.

File New Project…

Set Target device to PSoc 6 and Launch Device Selector

In Device Selector, scroll down and select CYBLE-416045-02 then click OK

Click Next

Select Empty schematic and click Next

Click Next again

Set Project name to Lab1.0 and click Finish

Build Generate Application

Debug Select target and program

Select PSoC 6 CYBLE-416045-02 (CM4) and OK / Connect

Watch for output in the window at the bottom of PSoC Creator

When you see Device ‘PSoC 6 CYBLE-416045-02 (CM4)’ was successfully programmed you have

successfully created the empty project and programmed your PSoC 6.


Background information


Pulse Width Modulation


A Pulse-Width Modulator (PWM) is a component used by digital systems to generate control signals for hardware.

Its periodic rectangular (modified square) signal can be used for many applications including driving a speaker,

rotating a servo motor, or making an LED blink at a regular interval.


By adjusting the duty cycle (portion of the period that the power is on), a PWM can be used to control the average

power supplied, which can be used for a variety of functions including dimming an LED as we’ll see in Lab 2.


For more details see: https://en.wikipedia.org/wiki/Pulse-width_modulation

University of California Santa Cruz Baskin School of Engineering CSE121 & CSE121L Spring 2022 Lab 1 Copyright ? 2022 David C. Harrison. All rights reserved.


Requirements


Lab 1.1 Hardware Only


Whilst the PSoC 6 has two CPUs, it is possible to have on-board hardware set the values of digital pins without

the involvement of either CPU. Here you will drive the on-board PWM with an on-board clock to switch the voltage

of the digital pins the two internal LEDs are connected to from high to low (zero volts) every half second.


Lab 1.2: Single CPU


Have the PSoC 6’s CM0+ CPU switch the voltage of the digital pins the two internal LEDs are connected to by

making use of the PSoC 6 Peripheral Driver Library, details of which can be found on-line on the manufacture’s

web site: https://infineon.github.io/psoc6pdl/pdl_api_reference_manual/html/index.html


Lab 1.3: Multiple CPUs


By using the PSoC 6 Peripheral Driver Library, have the PSoC 6’s CM0+ CPU switch the voltage of the digital pin

one the two internal LEDs is connected to and have the PSoC 6’s CM4 CPU switch the voltage of the digital pin

the other internal LED is connected to.


Lab 1.4: FreeRTOS


The code from Lab1.2 and Lab1.3, whilst easy to understand, is inefficient and difficult to scale as we must maintain

the main program loop ourselves. For more realistic embedded systems it is convenient to use a “Real Time

Operating System” (RTOS) to schedule period tasks. Here we deploy FreeRTOS (https://www.freertos.org) on the

PSoC 6’s CM4 CPU and write tasks to independently switch the voltage of the digital pins the two internal LEDs

are connected to using the PSoC 6 Peripheral Driver Library.



What steps should you take to tackle this?


Lab 1.1 Hardware Only


1. Create a new project in the CSE121 workspace:

File New Project…

Set Target device to PSoc 6 and Last used: CYBLE-416045-02

Click Next

Select Empty schematic and click Next

Click Next again

Set Project name to Lab1.1 and click Finish


2. Add two digital pins:

Open TopDesign.cysh

Add a digital pin from Ports and Pins and change its Name to RED

Add a second digital pin and change its Name to GREEN


3. Add a PWM:

Add a PWM from Digital ? Functions and change its Name to PWM

Set the PWM Period 0 to 999

Set the PWM Compare 0 to 500


4. Add a clock:

Add a Clock from System and change its Name to Clock

Set the clock Frequency to 1KHz


5. Connect the components:

Use the Wire Tool to connect the clock to the clock port on the PWM

Use the Wire Tool to connect the PWM pwm port to the RED digital pin

Use the Wire Tool to connect the PWM pwm_n port to the GREEN digital pin

University of California Santa Cruz Baskin School of Engineering CSE121 & CSE121L Spring 2022 Lab 1 Copyright ? 2022 David C. Harrison. All rights reserved.


6. Confirm your TopDesign.cysh looks like this:


7. Set the digital pin port numbers in “Design Wide Resources”:

Set GREEN to port P7[1]

Set RED to port P6[3]


8. Generate software / firmware components.

Build Generate Application


9. Disable CM4, enable the PWM and put CM0+ to sleep:

Edit CM0p Source Files main_cm0p.c

Remove the call to Cy_SysEnableCM4()

Remove the infinite loop for (;;) { }

Start the PWM by adding a call to PWM_Start()

Put CM0+ to sleep by adding a call to Cy_SysPm_Sleep(CY_SYSPM_STATUS_CM0_SLEEP)

Save main_cm0p.c


10. Program the PSoC 6:

Debug Select target and program

Select PSoC 6 CYBLE-416045-02 (CM4) and click OK / Connect

Watch for Device ‘PSoC 6 CYBLE-416045-02 (CM4)’ was successfully programmed’


If all goes well, the red and green on-board LEDs will start blinking on a half second cycle, red on, green off,

green on red off, etc.


Lab 1.2: Single CPU


1. Create a new project in the CSE121 workspace:

As above, but name it Lab1.2


2. Add two digital pins:

As above, but uncheck their General ? Digital output ? HW connection properties


3. Set the digital pin port numbers in "Design Wide Resources":

Set GREEN to port P7[1]

Set RED to port P6[3]


4. Generate software / firmware components

Build Generate Project


5. Disable CM4

Edit CM0p Source Files main_cm0p.c

Remove the call to Cy_SysEnableCM4()


University of California Santa Cruz Baskin School of Engineering CSE121 & CSE121L Spring 2022 Lab 1 Copyright ? 2022 David C. Harrison. All rights reserved.


6. Modify the main control loop to set the RED LED on and off on a half second delay:

Cy_GPIO_Write(RED_PORT, RED_NUM, x); // x = 1 for on, 0 for off

CyDelay(500); // sleep for 500ms


7. Modify the main control loop to do the opposite for GREEN LED on:


8. Program the PSoC 6:

Debug Select target and program

Select PSoC 6 CYBLE-416045-02 (CM4) and OK / Connect

Watch for Device ‘PSoC 6 CYBLE-416045-02 (CM4)’ was successfully programmed’


Lab 1.3: Multiple CPUs


1. As Lab1.2, but with the following differences:

Project name is Lab1.3

Do not disable CM4

Only toggle the RED LED in the CM0+ control loop

Toggle the GREEN LED in the CM4 main control loop


Lab 1.4: FreeRTOS


1. As steps 1 to 3 in Lab1.2, but with the following differences:

Project name is Lab1.4


2. Include support for FreeRTOS:

Use the (right mouse) context menu on the Lab1.4 project:

Build Settings Peripheral Driver Library

Select RTOS FreeRTOS Memory Management ( variant heap_1 )


3. Generate software / firmware components

Build Generate Application


4. Include FreeRTOS header files:

Edit CM4 Source Files main_cm4.c

Hash include FreeRTOS.h and task.h


5. Write a FreeRTOS task start function to toggle the RED LED:

Signature must be void red_task(void *arg)

Use Cy_GPIO_Write to set the pin status as before

Use vTaskDelay instead of CyDelay


6. Intialise a FreeRTOS task to call the start function:

xTaskCreate(red_task, "RED_TASK", 400, NULL, 1, 0);

Study the documentation to understand what the arguments to xTaskCreate signify


7. Repeat steps 5 and 6 for the GREEN LED


8. Start the FreeRTOS task scheduler

Remove the generated infinite loop

Replace with a call to vTaskStartScheduler();


9. Program the PSoC 6:

Debug Select target and program

Select PSoC 6 CYBLE-416045-02 (CM4) and OK / Connect

Watch for Device ‘PSoC 6 CYBLE-416045-02 (CM4)’ was successfully programmed’


University of California Santa Cruz Baskin School of Engineering CSE121 & CSE121L Spring 2022 Lab 1 Copyright ? 2022 David C. Harrison. All rights reserved.


How much code will you need to write?


Almost none. Your FreeRTOS implementation can be factored to avoid duplication, but make sure you have a

simple if inefficient version working before moving on to anything more sophisticated.


Grading scheme


The following aspects will be assessed:


1. (100%) Does it work?


Lab 1.1 Hardware Only (25%)

Lab 1.2 Single CPU (25%)

Lab 1.3 Multiple CPUs (25%)

Lab 1.4 FreeRTOS (25%)


How will you get your work graded?


Submit as described below, then in a TA office hours session, or lab section, demonstrate all four programs to a

TA. They will only award you a grade if you have submitted your code.


What to submit


In PSoC Creator, select:


Build Clean All Projects


Then open PowerShell:


$ cd '.\Documents\PSoC Creator\CSE121'

$ Compress-Archive -Path Lab1.* -DestinationPath CSE121-Lab1.zip


This creates an archive named CSE121-Lab1.zip in the current directory.


相关文章

版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp