Code Examples Forum Discussions
text.format{('custom.tabs.no.results')}
Recently there was an inquiry about pulse chirp (frequency sweep) generation for ultrasound range detection. It required a burst of the frequency sweep between 38kHz to 42kHz in 5ms for transducer excitation, followed by the 5ms of quiet period for detection of the reflected signal.
The demo project below provides all-hardware solution to this using 24-bit DDS generator (DDS24). The DDS24 is controlled using digital bus, which code is linearly swept in time in 64 steps, provided by the Count7. Project uses unique ability of the DDS to switch output frequency instantly upon tune word change (unlike a PWM, which has to wait until completion of the current period). Project is compiled using CY8CKIT-059 (PSoC5LP). It can be adapted to run on PSoC4/4M series chips.
Project archive is attached below.
/odissey1
Project uses following custom components:
DDS24 v0.1: Re: DDS24: 24-bit DDS arbitrary frequency generator component
The Dummy: The Dummy: empty component for digital bus routing
PSoC Annotation library v1.0: PSoC Annotation Library v1.0
BusConnect_v1_0 (included into the project)
Figure 1. Project schematic.
Figure 2. Connection diagram using PSoC Annotation Library
Figure 3. Scope screenshot: chirp burst (5ms) followed by quiet period (5ms).
Figure 4. Chirp measured starting frequency 38.2kHz
Figure 5. Chirp measured ending frequency 43.1kHz
Show Less
In the Cypress example projects for the CX3 device, the USB string descriptors are defined like this:
/* Standard manufacturer string descriptor */
const uint8_t CyCx3USBManufactureDscr[] =
{
0x10, /* Descriptor size */
CY_U3P_USB_STRING_DESCR, /* Device descriptor type */
'C',0x00, /* Manufacturer String */
'y',0x00,
'p',0x00,
'r',0x00,
'e',0x00,
's',0x00,
's',0x00
};
I would like to suggest a tidier method, which is easier to read, and less prone to bugs. First we define a macro:
#define USB_STRING_DESC(S) ((char const*)&(struct{ char const p[2]; wchar_t const s[sizeof(S)]; }) { {(sizeof(S)), CY_U3P_USB_STRING_DESCR}, S})
Now we can define our descriptors using a single line each:
Show Lessconst uint8_t *CyCx3USBManufactureDscr = USB_STR_DESC(L"Cypress");
const uint8_t *CyCx3USBProductDscr = USB_STR_DESC(L"CX3 Camera");
const uint8_t *CyCx3USBConfigSSDscr = USB_STR_DESC(L"USB-3.0");
const uint8_t *CyCx3USBConfigHSDscr = USB_STR_DESC(L"USB-2.1");
const uint8_t *CyCx3USBConfigFSDscr = USB_STR_DESC(L"USB-1.1");
This example was not working for me. I was not able to set the time.
I'm not sure this was due to some setting of my Teraterm.
Anyway, to make it work I had to do this change:
rslt = cyhal_uart_getc(&cy_retarget_io_uart_obj, &ch, UART_TIMEOUT_MS);
if(rslt != CY_RSLT_ERR_CSP_UART_GETC_TIMEOUT)
{
if(ch == '\r') /// changed, it was if(ch == '\n')
{
break;
}
//////////////////////////////
I also don't see printed on screen what I type while setting the time: for this, I had to add:
printf("%c",ch); fflush(stdout);
Show LessHi,
This is a demo project showing generation of the quadrature signal from the externally provided clock (of arbitrary frequency). The second demo project shows generation of phase-shifted output signal for arbitrary phase. Such necessities often arise in lock-in signal demodulation, when the reference clock comes from the external source (signal generator) and phase-shifted ( or quadrature) signal has to be synthesized internally from that clock.
The project targets high-frequency range (~100kHz), where achieving good-quality phase rotation without phase jitter becomes problematic. This jitter comes from 1 BUS_CLK uncertainty when sampling external signal.
The project uses digital Counter to measure period of the input clock and to generate a phase-shifted (quadrature) copy of it. To achieve low phase noise (jitter/period is ~0.1% or better), PSoC must operate at highest frequency possible (80 MHz). Unfortunately, the standard Counter component (v3.0) is limited to about 63 MHz, and can count at highest sampling rate of BUS_CLK / 4, which yields phase noise of about 0.6%: jitter / period = 4 x 100kHz / 65MHz = 0.6%.
To achieve better accuracy, the standard Counter (v3.0) component has been modified to operate at full speed of 80MHz. Updated custom component (Counter_ex) can operate in 8/16/24 and 32-bit modes, counting at full bus speed (80 MHz) with low phase noise: 100 kHz / 80 MHz = 0.125%. The phase noise drops further at lower input frequencies.
Attached are two demo projects and Counter_ex component library showing:
(a) quadrature signal generation while sweeping frequency of the input signal;
(b) sweeping the phase of the output while keeping input signal frequency fixed.
Optional DDS32 component library can be found here:
Re: DDS24: 24-bit DDS arbitrary frequency generator component
Optional Annotation Library component can be found here:
YouTube video:
Quadrature generator and phase-shifter using PSoC5 - YouTube
/odissey1
Figure 1. External signal (Pin_12) is captured by the Counter. Phase-shifted copy output is on Pin_122.
Figure 2. Yellow trace - input signal (100 kHz), Cyan - quadrature output. Fuchsia - Counter "tc", Blue - "comp".
Figure 3. KIT-059 connection diagram.
Show Less
PFA sample code for PS2 keyboard interface to Cypress controller this code is checked with PS2 keyboard working ok the press keys display on UART, But in this
code we want to implement code for ps2 keyboard like if we press any matrix key then particular ps2 keycode is transfer to PC. OR Please send any sample code for
ps2 keyboard using cypress controller.
Show LessOur friends at Atmosphere IoT recently created a very innovative and fun project leveraging Cypress' CYW20819 Bluetooth 5 MCU in a Smart Tea Kettle application. The system essentially remotely monitors the temperature of a tea kettle and turns it off base on user preference and the type of drink being made. The CYW20819 Arduino Eval Kit (CYW920819EVB-02) was used for this project with a temp/humidity shield added to transmit sensor data via BLE to mobile app, and then trigger shutdown of the tea kettle at optimum temperature.
The project was built in DK IoT Studio which is based off the Atmosphere IoT platform and is the fastest and simplest way to create, deploy, and manage a complete embedded-to-cloud IoT solution.
Check out how it was built here!
Show Less
A user needed this so for drill I created this as a starting point for them.
Basically the requirement was to create, from two frequencies, two signals, a sum frequency
and a difference frequency.
The two DDS in the white box and LCD were used to generate test signals and LCD
for debug. Those can be eliminated in design to free up resources for using other stuff.
I did this in PSOC 5LP, it may fit in the lower end family, PSOC 4. Would have to try
that out.
Design could benefit from a little more coding, eg. eliminate a small dither in frequency
due to finite arithmetic used in DDS and counters.
Timebase Gate for counters is set at 100 mS, so resolution is 10 Hz..
Also if needed output waveforms could easily be Sinusoidal if needed by using the WaveDac
onchip component.
Regards, Dana.
Show Less最近、めっきりセンサ・ハンターと化している私の為に知人が面白いセンサを見つけたよと知らせてくれました。
少し前に AK9750 という赤外線を使用したリモートセンサのプロジェクトを作成してみましたが、
今回はタッチエンスというメーカーから出されているタッチエンス・ショッカクポットという触覚センサを動かしてみました。
タッチエンス・ショッカクポット POTU−001−1: センサ一般 秋月電子通商-電子部品・ネット通販
As recently, I've been quite busy hunting new sensors, my friend found a new one.
A little ago I tried AK9750, which is an IR remote sensor, but this time it's a touch motion sensor,
named Shockaku Pot.
タッチエンス・ショッカクポット POTU−001−1: センサ一般 秋月電子通商-電子部品・ネット通販
このセンサはホストと UART で通信を行います。
PSoC Creator の回路図はこんな感じになります。
This sensor communicate with the host via UART.
So the schematic is something like below.
MCU基板としては CY8CKIT-044 を使用しました。
ピンアサインは以下のようにしました。
Using CY8CKIT-044 as the host, pin assignment is like below.
Tera Term の画面は下記のようになります。
Tera Term log follows.
プニプニとスポンジをいじるとセンサの値が変わるのが新感覚のセンサですね。
ゲームのコントローラ的な用途やロボット的なアプリケーションでのユーザーインターフェースなどに
使えるのではないでしょうか?
後、手を放すと割と正確にセンター(0, 0, 0, 0) に戻るのが印象的でした。
The texture of sponge gives us somewhat new user experience.
I think that this could be used for a controller of a game machine or human interface of a robot like application.
I was also impressed that the sensor values returns to (0, 0, 0, 0) when I released my finger.
main.c
===============
#include "project.h"
#include "stdio.h"
#include "vt100.h"
#define SENSOR_PACKET_SIZE 8
uint8_t rx_buf[16] ; /* packet is 8 bytes */
int rx_index = 0 ;
int packet_received = 0 ;
char str[128] ; /* print buffer */
CY_ISR(shockaku_isr)
{
sensor_int_ClearPending() ;
SHOCKAKU_ClearRxInterruptSource(SHOCKAKU_INTR_RX_NOT_EMPTY) ;
if (SHOCKAKU_SpiUartGetRxBufferSize()) {
rx_buf[rx_index++] = SHOCKAKU_UartGetByte() ;
if (rx_index > SENSOR_PACKET_SIZE) {
sensor_int_Disable() ;
packet_received = 1 ;
}
}
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
Sensor_Reset_Write(0) ;
CyDelay(500) ;
Sensor_Reset_Write(1) ;
CyDelay(500) ;
UART_Start() ;
sensor_int_ClearPending() ;
sensor_int_StartEx(shockaku_isr) ;
SHOCKAKU_Start() ;
}
void measure(void)
{
SHOCKAKU_UartPutChar(0x6d) ;
}
void get_data(uint16_t ch[])
{
ch[0] = ((rx_buf[0] << 😎 | rx_buf[1]) & 0x3FF ;
ch[3] = ((rx_buf[2] << 😎 | rx_buf[3]) & 0x3FF ;
ch[1] = ((rx_buf[4] << 😎 | rx_buf[5]) & 0x3FF ;
ch[2] = ((rx_buf[6] << 😎 | rx_buf[7]) & 0x3FF ;
}
void print_data(uint16_t ch[])
{
locate(20, 3) ;
sprintf(str, "%6d %6d %6d %6d", ch[0], ch[1], ch[2], ch[3]) ;
print(str) ;
}
void plot_data(uint16_t ir_data[])
{
static int prev_x = 30, prev_y = 13 ;
int x, y ;
int radius_x, radius_y ;
int center_x, center_y ;
center_x = 30 ;
center_y = 14 ;
radius_x = 20 ;
radius_y = 8 ;
sprintf(str, "%4d", ir_data[0]) ;
put_str(center_x, center_y - radius_y, str) ;
sprintf(str, "%4d", ir_data[1]) ;
put_str(center_x - radius_x, center_y, str) ;
sprintf(str, "%4d", ir_data[2]) ;
put_str(center_x, center_y + radius_y, str) ;
sprintf(str, "%4d", ir_data[3]) ;
put_str(center_x + radius_x, center_y, str) ;
if ((ir_data[0] == 0) && (ir_data[2] == 0)) {
y = center_y ;
} else {
y = center_y + (radius_y * (ir_data[0] - ir_data[2])) / (ir_data[0] + ir_data[2]) ;
}
if (y > (center_y + radius_y)) { y = center_y + radius_y ; }
if (y < (center_y - radius_y)) { y = center_y - radius_y ; }
if ((ir_data[1] == 0) && (ir_data[3] == 0)) {
x = center_x + 3;
} else {
x = center_x + (radius_x * (ir_data[3] - ir_data[1])) / (ir_data[1] + ir_data[3]) ;
}
if (x > (center_x + radius_x)) { x = center_x + radius_x ; }
if (x < (center_x - radius_x)) { x = center_x - radius_x ; }
put_char(prev_x, prev_y, ' ') ;
put_char(x, y, '*') ;
prev_x = x ;
prev_y = y ;
locate(1, 20) ;
}
void splash(void)
{
cls() ;
locate(20, 1) ;
sprintf(str, "Shockaku Sensor Test (%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
locate(24, 2) ;
sprintf(str, "ch1 ch2 ch3 ch4") ;
print(str) ;
}
int main(void)
{
uint16_t ch[4] ;
init_hardware() ;
splash() ;
for(;;) {
measure() ;
if (packet_received) {
get_data(ch) ;
print_data(ch) ;
plot_data(ch) ;
packet_received = 0 ;
rx_index = 0 ;
SHOCKAKU_SpiUartClearRxBuffer() ;
sensor_int_Enable() ;
CyDelay(100) ;
measure() ;
}
CyDelay(100) ;
}
}
===============
moto
Show LessHi,
Here I am uploading annotation component for the CY8CKIT-044 PSoC4 M-series Pioneer Kit
The KIT-044 component shows pins with direct connection to the ADC_SAR bypass capacitor, OpAmps, I2C, UART, RGB LEDs, light and temperature sensors, accelerometer and FRAM. The component helps to visualize ports and pins and helps create connection diagrams for CY8CKIT-044 Pioneer Kit.
The KIT-044 annotation component can be used in conjunction with small-sized annotation components from PSoC Annotation Library, as well as Cypress stock annotation components (capacitors, resistors, etc.)
Attached archive contains KIT-044 component library. Upon installation it will show up in the folder:
/Community/Off-Chip/Annotation Library/Kits/
The component provided as-is, no liabilities. It is free to use, modify and distribute.
regards,
/odissey1
Message was edited by: odissey1 Changed link to a new version of the PSoC Annotation Library v1.0
Show LessHi,
Attached is a demo project of the DelSig_ADC - Filter - VDAC data streaming using DMA.
It is roughly based on the original example provided by Todd Dust, but with correction of the highest bit during DMA transfer from the Filter to VDAC8.
How to Create an Analog Filter with PSoC 5LP - YouTube
The Filter output is signed value (Sine), which, when reaches full amplitude, produces weird output from the VDAC, which treats incoming data as unsigned. To achieve the full scale output, here the data are converted to unsigned using extra logic (Control_Reg, Status_Reg and XOR element to correct highest bit). The DMA channel has been modified to include two Transfer Descriptors. First TD is transferring int8-type data from the Filter to the Control_Reg, and second TD immediately retrieves corrected data from the Status_Reg (uint8) and passes it to the VDAC8.
Project includes several custom Community components, which are used to make internal sine generator with tunable parameters. Those components can be omitted if external function generator is available:
WaveGen8 (RAM-DMA-VDAC8 wave generator, included in the project)
QuadDecoder_SW: https://community.cypress.com/thread/30654
DDS32: https://community.cypress.com/message/158566 (included in the project)
Annotation Library: https://community.cypress.com/thread/48049
/odissey1
Figure 1. DelSig_ADC to Filter data streaming using DMA
Figure 2. Filter to VDAC data streaming using DMA with two TDs. A signed output value (int8) is converted to the unsigned (uint8) using PLD logic in a single DMA pass.
Figure 3. Function Generator using DDS32, and WaveGen8 custom components
Figure 4. Project annotation diagram using PSoC Annotation Library.
Figure 5. Original demo project by Cypress showing Filter performance at 1 kHz and full swing. Blue trace - ADC input signal, Yellow trace: VDAC_1 output, Fuchsia - WaveGen reference.
Figure 6. Corrected Filter performance at 1 kHz. Blue trace - ADC input signal, Yellow trace: VDAC_1 output, Fuchsia - WaveGen reference. The steps are due to 48kHz ADC sampling rate. Filter LPF cut-off is set to 6kHz.
Figure 7. Filter performance at 6 kHz. Blue trace - ADC input signal, Yellow trace: VDAC_1 output, Fuchsia - WaveGen reference.
Figure 8. Filter performance at 7 kHz. Blue trace - ADC input signal, Yellow trace: VDAC_1 output, Fuchsia - WaveGen reference.
Added Figure 5 - Original project performance at full amplitude swing, showing issue when data is transferred from Filter to VDAC8 directly. Updated project archive now also includes an old DMA_1 configuration to show the issue.
Added a screenshot demonstrating issue with original project, when data was transferred by DMA from Filter to VDAC8 directly. Updated project archive includes old DMA_1 configuration to demo this issue.
Show Less