Code Examples Forum Discussions
Description:
- This example demonstrates TCPWM use case with CC0 and Period Auto Reload with switch event.
- One TCPWM will generate interrupt every second. In the interrupt handler, it will change the period buffer and cc0 buffer and enable the switch event.
- One LED will blink at the period 1 second, another LED will change the blink frequency and duty cycle.
Test environment:
- CYTVII-B-E-1M-SK(Traveo II starter kit board)
- SDL version 7.9.0
- IAR version 9.30
Based on the device acceleration (acceleration sensor value) how to wake up the device? In example code where we can set the Acceleration sensor threshold value for wakeup.
Show LessWe will post sample code for XMC2Go, the smallest evaluation kit in the XMC microcontroller series.
Features of XMC2Go
- Equipped with XMC1000 microcontroller
- On-board debugging capability, no need for ICE or other debuggers
- 3.3V operation with USB power supply
- Equipped with 2 LED lights
- 8-pin x 2 rows of header pins
Sample code to flash LEDs on XMC2Go
Sample code for using P2.7, P2.9, P2.10, and P2.11 as general-purpose ports (GPIOs)
The XMC2Go can be equipped with two rows of 8-pin x 8-pin header pins. If the user is P2.7, Sample code for using P2.9, P2.10, and P2.11 is attached. The file name is "XMC_2Go_Inital_Start_v1.3_P2_7,9,10,11.zip".
Use DAVE's Import function to import "XMC_2Go_Inital_Start_v1.3_P2_7,9,10,11.zip".
In order to use P2.7, P2.9, P2.10, and P2.11, we have added two places in the figure below.
where P2.7, P2.9 cannot be used as an output due to the STD_IN/AN function, as stated in the data sheet.
P2_7_set_mode(OUTPUT_PP_GP);
P2_9_set_mode(OUTPUT_PP_GP);
There is no particular error in the line, but it will not be OUTPUT as specified.
P2.10 and P2.11 are written as STD_INOUT and can be used for input and output.
Also, since AN (Analog input) is the default setting, if you want to use it as a GPIO P2_PDISC you need to set the registers.
(Example)
P2_10_enable_digital();
P2_11_enable_digital();
more than
smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/%E3%82%B3%E3%83%BC%E3%83%89%E4%BE%8B/XMC2Go-for-XMC-starters/td-p/642676
Show LessHi, Community,
The project was created to provide a rudimentary understanding of proximity sensor functionality.
This was worked on in PSoC Creator.
This project is based on CE225691_PSoC4_CapSense_Proximity.
The five elements of the slider electrode on the kit are assigned to the CSD button and they are ganged together to act as a proximity sensor.
The first step is to operate the sensor as a proximity, and when a finger touches the electrode (only SLD1 in this project), it toggles the GPIO to which the LED is connected.
Regarding the ganged button, I was able to assign a function to it as a stand-alone it as well.
In addition, the CAPSENSE Tuner could be launched through the UART connection to check the operation of the CAPSENSE.
Designing the electrodes would be a very tough job, so I decided to try it first with the electrodes in the kit.
Finally, the work for the BUTTON alone could be done by sending a message serially instead of lighting an LED, and I think it could give a lot of ideas to be implemented.
TopDesign & Pin allocation:
NOTE:
LED are externally mounted.
If you want the LED connected to the PWM to light up in reverse of the proximity operation, change the following: change the Output line signal to "Invert output".
Best Regards,
Chihiro Tatebayashi / NEXTY
This is an example of the 8-bit arbitrary signal generator playing DTMF tones on PSoC4200M CY8CKIT-044 Pioneer Board.
Like the previous example, this project also uses Double-Buffered DMA to update the IDAC8. However, this time the data are being calculated in the real time by DDS, and the IDAC is operated in bidirectional mode, which requires setting IDAC's direction (sign) and magnitude.
This has several benefits, compared to the previous example:
- The signal output is centered around Vref (here Vdd/2 was used)
- The output amplitude has double span (-255 to 255)
- Using single DMA channel allows for higher update rates
The drawback is that now two bytes have to be populated in the temporary buffer array {CTRL, data}, which consumes more processor clocks. This load, however, is quite low, reaching in current example only ~3% of all processor time.
The Double-Buffered DMA uses intermediate RAM Buffer of size 2N=64 bytes made of two equal halves, to store the data coming from the data source. The DMA1 consists of two chained Transfer Descriptors TD0 and TD1, copying 2 bytes from the Buffer to the IDAC on each clock. Once TD0 finishes copying the data from the first half of the Buffer, it chains to the TD1, which copies data from the second half of the Buffer and loops back to TD0.
Once TD0 (or TD1) is completed, an interrupt is fired, signaling that this Buffer half needs replenishment (while the other one is busy). At this point processor need to fill the half-Buffer with generated waveform, and wait for the next data request, while the Buffer content is being continuously played without interruption.
DTMF tones (F1 + F2) are generated in real-time using two software DDS blocks, which return 8-bit sine waveforms based on the lookup table.
The IDAC is used in bipolar mode, both Source and Sink, controlled by the sign of the input data. The IDAC current is converted into voltage using 3.3k resistor and buffered by the Opamp in the transimpedance mode. The Opamp output is centered around the reference voltage (Vdd/2): Vout = 0.5Vdd +/- 1.0V.
By default the project is configured to start playing waveform on startup and plays each DTMF tone for 2 seconds.
Project attached contains all necessary files. It was tested using both Creator 4.0.
Figure 1. Project schematic. The DTMF data are generated by DDS_1 and DDS_2 on request, and then transferred from the Buffer to the IDAC using DMA. The IDAC output current direction is controlled by the sign of the data. The IDAC operates in transimpedance mode using using 3.3k feedback resistor, producing 0.5Vdd +/- 1.0V signal.
Figure 2. Project annotation using the PSoC Annotation Library v1.0 and KIT-044. The Red LED pin was used for the performance testing; it raises on ISR routine entry, and lowers on exit. The duty cycle on this pin shows the processor load (~3%). The reference voltage is "stolen" from the hidden Pin_5[0], which is connected to the Vdd/2 onboard source. For sound generation, the output can be directly connected to the headphones with combined impedance of 64oHm (32+32). Capacitors shown are optional and don't affect output significantly.
Figure 3. Output waveform for DTMF tone 697Hz + 1209Hz. Yellow - DTMF generator output, centered around Vdd/2. Cyan - test digital pin, raising on DDS routine entry, and lowering on exit. The half-Buffer length to be populated is 32, and DMA sampling clock is 32 kHz, which results in 1 kHz ISR rate. DDS routine calculations take about 28usec, resulting in processor load of less than ~3%.
Figure 4. FFT example of the DTMF tone 697Hz + 1209Hz.
Show Less
Hi, Community,
Here is an example code to measure power consumption of PSoC4000S without entering low power modes like Deep Sleep. Please note that in order to perform the experiment, you will need to remove resistors R22 and R23 on the CY8CKIT-145 evaluation board.
And I removed the jumper on J3 and measured it using the current mode of a tester.
The system frequency of the PSoC4000S is set to 24MHz.
The result shows that the power consumption of the PSoC4000S, with VDD = 3.3V, is approximately 4.8mA.
Was my expectation that it would be about the same as IDD8 correct... ?
I attached the main.c file. Please add it to an empty project.
The TopDesign is as shown in the image.
Best Regards,
Chihiro Tatebayashi / NEXTY
This is an example of the 8-bit PCM audio playback on PSoC4200M CY8CKIT-044 Pioneer Board using Double-Buffered DMA.
Unlike the previous example, which used single-buffered DMA to update the IDAC8, this project is using a Double-Buffered DMA to transfer the data. This has several benefits, compared to previous example:
- No limitation on the audio data size.
- Possibility to mix data from several data sources or manipulate the data
- Seamless data output (no interruptions).
The drawback of the approach is certain processor load, which has to repeatedly populate the Buffer with fresh data. This load, however is much lower compared to using direct interrupt write without DMA.
The Double-Buffered DMA uses intermediate RAM Buffer of size 2N=64 bytes made of two equal halves, to store the data coming from the data source. The DMA1 consists of two chained Transfer Descriptors TD0 and TD1, which copy data byte-by-byte from the Buffer to the temporary RAM location (TMP). Once TD0 finishes copying the data from the first half of the Buffer, it chains to the TD1, which copies data from the second half of the Buffer and loops back to TD0. In this demo, the Buffer size is 64 bytes. Actual size should be set depending on the latencies of the processor, but 128+128 is typically a good size. Project dataflow:
Once TD0 (or TD1) is completed, an interrupt is fired, signaling that this Buffer half needs replenishment (while the other one is busy). At this point processor need to copy fresh portion of the data from the data source (here it is a FLASH), and wait for the next data request, while the Buffer content is being continuously played without interruption.
The data source can be RAM, FLASH, SD card, or processor generated data (sine, etc.).
To get the data to the IDAC8, the 8-bit data is first copied by DMA1 from the Buffer into intermediate (16-bit) location in RAM, where the MSB keeps IDAC control settings, and LSB has the data. The DMA2 then transfers 2 bytes {MSB, LSB} to the IDAC8 control register. Such intricate scheme is required because the DMA transfer to the IDAC is always 16-bit, thus the attempt to send only the data byte wipes off the IDAC control settings.
The project is configured to play on startup the Sawtooth test waveform in the continuous loop. Optionally, it can be configured to play a single time by enabling the SINGLE_SHOT directive.
The audio data are stored in the PSoC FLASH in 8-bit unsigned PCM format. Attached project includes several test PCM audio files in 8-bit unsigned format:
sawtooth_8-bit_S.h - test sawtooth, 8-bit, Unsigned (size= 256 bytes)
smb_world_clear_5k5_N_U.h - Super Mario theme, 5.512kHz, Normalized, Unsigned (size=33600 bytes)
smb_world_clear_11kHz_N_U.h - Super Mario theme, 11.025kHz, Normalized, Unsigned (size=65536 bytes)
smb_world_clear_22kHz_U.h - Super Mario theme, 22.05kHz, Unsigned (size=65535 bytes, clipped)
The WAV files have been converted to the C code using WAVtoCode v1.1.1 by Colin Seymour. The original WAV data have been Normalized to fill the entire 8-bit scale, which has increased the dynamic range.
Project attached contains all necessary files. It was tested using both Creator 4.0 and 4.4.
Credits:
WAVtoCode v1.1.1 by Colin Seymour: https://colinjs.com/software.htm#t_WAVToCode
Figure 1. Project schematic. The PCM data are copied from the FLASH to the Buffer by code, and then from Buffer to the IDAC using chained DMA. The IDAC is configured as a Source. The IDAC current is converted into voltage using 3.3k load resistor buffered by the Opamp in the follower mode, producing 0-1V signal at full scale.. For sound generation, the output is directly connected to the headphones with combined impedance of 64oHm (32+32).
Figure 2. Project annotation using the PSoC Annotation Library v1.0 and KIT-044. The Opamp output is directly loaded on the headphones with combined impedance of about 64oHm (32+32).
Figure 3. Output waveform on startup. The test data is Sawtooth, 256 points per period, played in the loop continuously.
Figure 4. Sawtooth waveform output when configured for a SINGLE_SHOT. The number of data points is 256, played once. After the end of data, the output can be set to some pre-defined value (here is 127).
Show Less
The evaluation board, CYBT-343026-EVAL, is not recognized even when inserted into a computer. There seems to be no driver software.
The board contains a USB Serial dual channel bridge controller (CY7C65215-32LTXI).
If you know how to install and enable the driver, please let me know.
Show LessThis code example can be used for interfacing of XENSIVTM Photoacoustic Spectroscopy (PAS) CO2 sensor with PSoC6 via I2C using available PSoC6 library. The document then explains the extension of the implementation to a CO2 traffic light.
Introduction
The document describes the procedure to interface XENSIV™ PAS CO2 sensor with PSoC6 evaluation board. The basic implementation covers the interfacing the sensor with PSoC6 and the CO2 levels measured is printed in the serial terminal. In this article based on the measured CO2 levels, three LED’s of different colors (green, orange/yellow and red) are individually turned on.
Hardware
The hardware required for the implementation are
- PSoC™ 6 Wi-Fi Bluetooth® pioneer kit
- XENSIV™ PAS CO2 mini-evaluation board or XENSIVTM PAS CO2 Shield2Go board
Figure 1. (a) XENSIV™ PAS CO2 Mini Evaluation Board (b) XENSIV™ PAS CO2 Shield2Go board
The setup using PAS CO2 mini evaluation board can be understood from the figure shown below.
Figure 2. Wiring connection for interfacing XENSIVTM PAS CO2 mini-evaluation board with PSoC™ 6 Wi-Fi Bluetooth® pioneer kit via I2C
The 12 V required for the sensor operation needs to be supplied externally. Please also keep the ground common in all the connections to ensure proper functionality.
PAS CO2 Shield2Go board can be used instead of the mini-evaluation board. The Shield2Go board can be interfaced with the PSoC™ 6 Wi-Fi Bluetooth® pioneer kit as shown in the figure below. Here the advantage is that there is no need for providing 12 V externally.
Figure 3. Wiring connection for interfacing XENSIVTM PAS CO2 Shield2Go board with PSoC™ 6 Wi-Fi Bluetooth® pioneer kit, via I2C
Once the hardware setup is ready, using any of the above options, please proceed to the software setup mentioned in the next section.
Software Setup
Steps required for the software implementation are listed below
Step 1: Please follow the steps from https://github.com/Infineon/sensor-xensiv-pasco2 to have the initial software setup in Modus Toolbox
Step 2: Include the following code for defining the GPIO pins for controlling red, yellow/orange and green LEDs. The calculated CO2 ppm values needs to be compared and used to determine the states of LED’s. For that purpose, a comparator loop can be added as shown below.
#include "cyhal.h"
#include "cybsp.h"
#include "cy_retarget_io.h"
#include "xensiv_pasco2_mtb.h"
/*******************************************************************************
* Macros
*******************************************************************************/
#define PIN_XENSIV_PASCO2_I2C_SDA CYBSP_I2C_SDA
#define PIN_XENSIV_PASCO2_I2C_SCL CYBSP_I2C_SCL
#if defined(USE_CYSBSYSDEV_KIT_01_WINGBOARD)
/* Output pin for sensor PSEL line */
#define PIN_XENSIV_PASCO2_PSEL P5_3
/* Output pin for PAS CO2 Wing Board power switch */
#define PIN_XENSIV_PASCO2_POWER_SWITCH P10_5
#endif
#define I2C_MASTER_FREQUENCY (100000U)
/* Wait time for sensor ready (milliseconds) */
#define WAIT_SENSOR_RDY_MS (2000)
/* The CO2 concentration value acquired by the sensor depends on the external atmospheric pressure.
To compensate for this effect, pressure values can be acquired from a pressure sensor such as an
Infineon XENSIV™ DPS3xx. (https://github.com/Infineon/sensor-xensiv-dps3xx) */
#define DEFAULT_PRESSURE_REF_HPA (0x3F7) /* Default atmospheric pressure to compensate for (hPa) */
/*Defining GPIO pins for LEDs*/
#define PIN_R P9_1
#define PIN_Y P9_4
#define PIN_G P9_7
/***********************************/
/*******************************************************************************
* Global Variables
*******************************************************************************/
static cyhal_i2c_t cyhal_i2c;
static xensiv_pasco2_t xensiv_pasco2;
int main(void)
{
/*Initializing GPIO pins for LEDs*/
cyhal_gpio_init(PIN_R, CYHAL_GPIO_DIR_OUTPUT,CYHAL_GPIO_DRIVE_STRONG, false);
cyhal_gpio_init(PIN_Y, CYHAL_GPIO_DIR_OUTPUT,CYHAL_GPIO_DRIVE_STRONG, false);
cyhal_gpio_init(PIN_G, CYHAL_GPIO_DIR_OUTPUT,CYHAL_GPIO_DRIVE_STRONG, false);
cy_rslt_t result = CY_RSLT_SUCCESS;
/* Initialize the device and board peripherals */
result = cybsp_init();
CY_ASSERT(result == CY_RSLT_SUCCESS);
__enable_irq();
/* Initialize retarget-io to use the debug UART port. */
result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);
CY_ASSERT(result == CY_RSLT_SUCCESS);
printf("XENSIV PAS CO2 Example\r\n");
/* Initialize I2C */
cyhal_i2c_cfg_t i2c_master_config = {CYHAL_I2C_MODE_MASTER,
0,
I2C_MASTER_FREQUENCY};
result = cyhal_i2c_init(&cyhal_i2c, PIN_XENSIV_PASCO2_I2C_SDA, PIN_XENSIV_PASCO2_I2C_SCL, NULL);
CY_ASSERT(result == CY_RSLT_SUCCESS);
result = cyhal_i2c_configure(&cyhal_i2c, &i2c_master_config);
CY_ASSERT(result == CY_RSLT_SUCCESS);
#if defined(USE_CYSBSYSDEV_KIT_01_WINGBOARD)
/* Initialize and enable PAS CO2 Wing Board I2C channel communication*/
result = cyhal_gpio_init(PIN_XENSIV_PASCO2_PSEL, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, false);
CY_ASSERT(result == CY_RSLT_SUCCESS);
/* Initialize and enable PAS CO2 Wing Board power switch */
result = cyhal_gpio_init(PIN_XENSIV_PASCO2_POWER_SWITCH, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, true);
CY_ASSERT(result == CY_RSLT_SUCCESS);
#endif
cyhal_system_delay_ms(WAIT_SENSOR_RDY_MS);
/* Initialize PAS CO2 sensor with default parameter values */
result = xensiv_pasco2_mtb_init_i2c(&xensiv_pasco2, &cyhal_i2c);
if (result != CY_RSLT_SUCCESS)
{
printf("PAS CO2 device initialization error");
CY_ASSERT(0);
}
#if defined(USE_CYSBSYSDEV_KIT_01_WINGBOARD)
/* Configure PAS CO2 Wing board interrupt to enable 12V boost converter in wingboard */
xensiv_pasco2_interrupt_config_t int_config =
{
.b.int_func = XENSIV_PASCO2_INTERRUPT_FUNCTION_NONE,
.b.int_typ = (uint32_t)XENSIV_PASCO2_INTERRUPT_TYPE_LOW_ACTIVE
};
result = xensiv_pasco2_set_interrupt_config(&xensiv_pasco2, int_config);
if (result != CY_RSLT_SUCCESS)
{
printf("PAS CO2 interrupt configuration error");
CY_ASSERT(0);
}
#endif
uint16_t ppm;
/*Defining CO2 ppm levels for safe and warning*/
uint16_t co2ppmsafe = 800;
uint16_t co2ppmwarn = 1100;
for (;;)
{
result = xensiv_pasco2_mtb_read(&xensiv_pasco2, DEFAULT_PRESSURE_REF_HPA, &ppm);
if (result == CY_RSLT_SUCCESS)
{
printf("CO2 %d ppm.\r\n", ppm);
if(ppm<=co2ppmsafe)
{
cyhal_gpio_write(PIN_G,true);
cyhal_gpio_write(PIN_Y,0);
cyhal_gpio_write(PIN_R,0);
}
else if(ppm>co2ppmsafe && ppm<=co2ppmwarn)
{
cyhal_gpio_write(PIN_G,0);
cyhal_gpio_write(PIN_Y,true);
cyhal_gpio_write(PIN_R,0);
}
else if (ppm>co2ppmwarn)
{
cyhal_gpio_write(PIN_G,0);
cyhal_gpio_write(PIN_Y,0);
cyhal_gpio_write(PIN_R,true);
}
}
cyhal_system_delay_ms(10);
}
}
Step 3: The output can be seen in the terminal as shown in Figure 4.
Figure 4. CO2 ppm levels being printed in the serial terminal
The LED’s will be turned on/off based on the CO2 ppm values measured as seen in Figure 5.
Figure 5. LEDs showing the status of CO2 ppm levels, (a) safe state, (b) warning state and (c) danger state
Green LED can show that the environment is safe. Orange/Yellow LED can show a warning state and can be used to initiate some preventive measures. The preventive measures can be as simple as controlling the air conditioning unit or opening the windows. The Red LED can indicate a worst working environment and should be followed by strict actions like vacating the room. A better understanding of effects of CO2 levels on human comfort levels can be understood from Figure 6.
Figure 6. Human comfort levels based on CO2 ppm levels
Working condition is very comfortable for CO2 levels below 800 ppm. Beyond this level the conditions start deteriorating and working condition becomes difficult as CO2 levels reaches 1200 ppm. It is not recommended to continue working with CO2 levels more than 1200 ppm and is considered danger. Continuing working in these conditions can cause headache and sleepiness initially. Further higher levels of CO2 is harmful for human life and is extremely dangerous.
References
Show LessDescription Overview
I wrote code to make a sound using the slider of the CY8CKIT-042 PSoC 4 Pioneer Kit.
1. Get a position on the slider.
2. Set the PWM value according to the location and output as sound.
3. If the position changes, change the value of PWM.
4. If the finger is separated, the PWM output stops.
Prerequisites
• Evaluation Board: CY8CKIT-042 PSoC 4 Pioneer Kit
• Piezoelectric buzzer
• IDE name: PSoC Creator 4.4
procedure
1.P3.5 and GND Connected the buzzer to the PIN.
2. Run the project attached to this topic and touch the slider on the evaluation board with your finger to make a sound.
If you want to change the connection of the buzzer, please change it from the Pin settings.
Show Less