Code Examples Forum Discussions
In SPI_DMA example how queue works for multiple slaves in single node , unable to understand from documents of iLLD.@User16286
Show LessHi,
I've uploaded an example project that illustrates very efficient ISR coding of 11 UART Rx ports.
It is uses a SW circular FIFO buffer for each port with threshold detection of a message size (in this case 7 bytes) and FIFO buffer overrun.
With my implementation I can achieve nearly 300KBaud for each of 11 Rx ports with the BUS_CLK @ 79.5MHz. I can achieve 100KBaud with BUS_CLK at 24MHz.
This example is intended to be a starting point for your next project for very high performance data acquisition that also supports some error detection.
Requirements:
- PSoC5LP
- PSoC Creator 2.0 or higher.
- Many PSoCs with some minor modifications.
The project was created on a CY8CKIT-059 but can be built on virtually any PSoC5 platform.
Included is a document file explaining the project goals and a treatise on Interrupts.
Show LessTo all,
I've enhanced some of my previously submitted code shares (Terminal Component - Simplifies UART or USBUART communication and GetString() function that supports input character filtering. Includes menu-driven commands. ).
I've now expanded these previous submits and placed them in a Component Library that can be easily shared with all your projects and with other users.
Here is a list of the components in the library:
- Term - Terminal (UART) replacement that can be configured as UART or USBUART types.
- String_Funcs - This is an enhancement of the GetString() function. It is easier to use.
- MenuCmds - This feature was included in the GetString demo code I shared earlier. It is now a component with some improvements.
With each of the Components, I have include at least one demo project for each component to illustrate how these components can be used.
I've also included datasheets for the Components, the demo projects and a instructional on how to install a library/component to be shared across all your projects.
All the components have the source code included for educational purposes. If you know how to write component code, you can modify it.
The components String_Funcs and MenuCmds are designed to work with ANY PSoC. (They are mostly library functions.)
The Term component currently only works with the PSoC5.
I hope everyone who download's this component will find it useful.
Len
Message was edited by: Len Update: Added PSoC6 and PSoC4 demo code examples.
Message was edited by: Len Update: Added two more PSoC4 demo code examples. Both using the SCB_UART component and one of them with a Bootladable (-049 kit).
Message was edited by: Leonard Poma This library includes the latest version (2.3) of Term. Attached is also two demo examples of using Term.
Show LessUPDATED: 12.30.2021
Hi,
I'm attaching a project which includes a pre-component version of a 14-bit VDAC using the dithering method to generate the extra bits of resolution beyond the inherent 8-bits provided by the Cypress VDAC8 component.
In principle it is identical to the Cypress DVDAC (12-bits max resolution) in theory of operation. It even has the same API calls.
Besides having 2 additional bits of resolution (max 14-bits), it doesn't use the DMA to operate the dithering. Instead it uses a 100% HW state machine created with UDBs. Therefore, the dithering is always in-sync to the VDAC clock and is not prone to DMA latencies. In fact, it uses 0% CPU cycles to keep it running!
Project SW Requirements:
- PSoC Creator 4.2.
PSoC5LP Requirements:
- Use project DVDAC14_Demo_PSoC5
- The project supplied is designed to run on a stock CY8CKIT-059 with NO EXTERNAL components!
- The project can be modified to run on other PSoC5LP-based designs. (eg CY8CKIT-050, SparkFun boards, etc.)
PSoC3 Requirements:
- Use project DVDAC14_Demo_PSoC3
- The project supplied is designed to run on a stock CY8CKIT-030 with the addition on one small capacitor.
- The project can be modified to run on other PSoC3-based designs.
he project attached is a Demo code example that allows for user modify the DVDAC14 'component' parameters through the API calls to the included pre-component.
The Demo project uses my Term, MenuCmds and String_Funcs components to simplify the user access to the run-time features.
I have include the needed component libraries as imported into the project for your convenience.
Here is a link to my component library: Terminal-Support-Component-Library if you'd prefer to use these components as a shared resource for your other projects.
Why do this?
Because you (more specifically ... I) can. Cypress demonstrated that this is possible with their DVDAC12. I extended their idea to a HW-only solution as a learning experience and possibly a teaching tool to help show the value of the PSoCs that have UDBs. It has been my experience as an engineer that if you can move highly repetitive operations into a HW state-machine, you can achieve significant performance gains.
There might be some of you that ask: Can the DVDAC be made to support 16-bits? The short answer is yes. However, in this style of implementation you would need 32 UDB blocks. This would deplete your UDB resources. Additionally, the extra VDAC sensitivity virtually gained would be outweighed by the noise in practically any system.
Next Steps
I have released the DVDAC14 as a pre-component. It has about 80% of the component structures including the API calls.
I'm looking for user feedback. This includes implementation bugs if you find some. If you have some suggestions, I'd welcome the input.
Once I feel the pre-component version is stable I would consider making it into a full-fledged component.
Happy Holidays and Enjoy!
Show LessA PSoC6 CapSense UART tuner sample project is created based on ModusToolBox 2.3, project is also tested use ModusToolBox 2.4.
Please choose "ModusToolBox-->File-->Import-->ModusToolBox-->ModusToolBox App Import" option to import the unzipped "CapSense_TunerUart" project into ModusToolBox 2.3 or 2.4, then use "make getlibs" to download the extra libs from github before build the project.
Show Less
Hello,
This sample code implements SmartIO's Count Up Wrap function using a Divided Clock.
The Clock component is connected to the clock of SmartIO2.
GND is connected to TR0 (rst) and VDD is connected to TR1 (en) of Count Up Wrap, but since it cannot be directly connected, it goes through LUT0 and LUT1, respectively.
DU is a Count Up Wrap function, and the counter outputs a pulse with 6 counts match of 8bit counter.
The output of DU is registered out to gpio6 with LUT6 .
2_1 is connected to VDD and P2_0 is connected to GND by external wiring.
The following waveforms can be observed after programming.
Pin_PWM_CLK (P3_6) is a clock for waveform observation with an oscilloscope.
And note that the Clock component output is divided by two.
Best regards,
Yocchi
Show Less
Hello,
This sample code implements SmartIO's Count Up Wrap function using a TCPWM line clock.
TCPWM line is connected to the data4 of SmartIO.
GND is connected to TR0 (rst) and VDD is connected to TR1 (en) of Count Up Wrap, but since it cannot be directly connected, it goes through LUT0 and LUT1, respectively.
DU is a Count Up Wrap function, and the counter outputs a pulse with 6 counts match of 8bit counter.
The output of DU is registered out to gpio6 with LUT6 .
P2_1 is connected to VDD and P2_0 is connected to GND by external wiring.
The following waveforms can be observed after programming.
Pin_PWM_CLK (P1_2) is a clock for waveform observation with an oscilloscope.
Best regards,
Yocchi
Show LessHello,
This sample code implements SmartIO's Match DATA1 function using a GPIO input clock.
TCPWM_CLK is connected to the gpio4 of SmartIO.
TCPWM_SHIFTIN is input to TR2 (shift-in) of Equal DU DATA1 as a test pattern.
TR2 (shift-in) of Equal DU DATA1 shifts in from the MSB side as shown in the figure below.
Register Value is 0x03 and Size is 3.
Unfortunately, the connection between SmartIO and TCPWM requires external wiring.
The following waveforms can be observed after programming.
Best regards,
Yocchi
Show LessHello,
This is a sample code of SmartIO that wakes up from DeepSleep without using WDT.
Since the SmartIO counter is 8 bits, it can only count up to 6.4 ms when LFCLK (40 kHz) is used as the clock.
However, you can count up to 1.6384sec by connecting two SmartIOs.
This sample code counts 4ms for the first stage SmartIO and 400ms for the second stage SmartIO.
Unfortunately, the connection between SmartIO requires external wiring.
A GPIO interrupt is generated every 400ms and Wake up from Deep Sleep. The output of P0_0 is inverted when Active.
The two SmartIOs use the Count Up Warp feature.
The DU of the first SmartIO counts up using LFCLK by setting TR0 (rst) to 0 (Constant 0) and TR1 (en) to 1 (Constant 1). TR2 is unused.
The DU of the second SmartIO counts by inputting the 4ms pulse of the first SmartIO to TR1 (en).
External wiring should be as follows.
After programming, you can observe the waveform that inverts the output every 400ms from P0_0 with a power supply current consumption of about 2.5µA.
Best regards,
Yocchi
Show LessHi,
こんにちは、
I found the following discussion
下記のようなスレッドを見つけました
https://community.infineon.com/t5/PSoC-5-3-1/a-way-to-use-millies-from-arduino-in-Psoc/td-p/328317
and learned that my sample below was not enough.
以前上げた下記のサンプルでは不十分だったと知りました。
So here it is, an emulated "millis()" function of arduino in PSoC 😉
というわけで、Arduino の "millis()" という関数の真似をしてみました。
As I checked the Arduino Online Reference, the usage of millis() was
Arduino のオンラインリファレンスを参照したところ、millis() の使い方は下記のようなものでした
unsigned long time;
void setup() {
Serial.begin(9600);
}
void loop() {
time = millis();
Serial.println(time);
delay(1000); // 1秒おきに送信
}
So I changed the main loop something like
それで、こちらのメインループの以下のような形で動くようにしてみました
for(;;)
{
time = millis() ;
print_time(time) ;
CyDelay(1000) ;
}
To my previous sample, I added a couple of functions
以前のサンプルに、下記2つの関数を追加しました。
1. millis()
uint32_t millis(void)
{
return( tick_count ) ;
}
2. clear_millis()
void clear_millis(void)
{
tick_count = 0 ;
}
Schematic
CY8CKIT-044
CY8CKIT-059
Pins
CY8CKIT-044
CY8CKIT-055
Tera Term log
CY8CKIT-044
CY8CKIT-059
main.c
CY8CKIT-044
#include "project.h"
#include "stdio.h"
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(100) ;
print("\033[2J") ; /* clear screen */
CyDelay(100) ;
}
void splash(char *title)
{
cls() ;
if (title && *title) {
print(title) ;
print(" ") ;
}
snprintf(str, STR_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
print(str) ;
}
volatile uint32_t tick_count = 0 ;
CY_ISR(tick_callback)
{
tick_count++ ;
}
int find_empty_slot(void)
{
int result = -1 ;
uint32_t i ;
for (i = 0 ; i < CY_SYS_SYST_NUM_OF_CALLBACKS ; i++ ) {
if (CySysTickGetCallback(i) == NULL) {
result = i ;
break ;
}
}
return(result) ;
}
void show_delta_time(void)
{
static uint32_t prev_tick = 0 ;
uint32_t new_tick = 0 ;
uint32_t delta = 0 ;
new_tick = tick_count ;
delta = new_tick - prev_tick ;
prev_tick = new_tick ;
snprintf(str, STR_LEN, "Current: %d -> %d ms passed\n\r", new_tick, delta) ;
print(str) ;
}
void clear_millis(void)
{
tick_count = 0 ;
}
uint32_t millis(void)
{
return( tick_count ) ;
}
void print_time(uint32_t value)
{
char buf[65] ;
snprintf(buf, 64, "millis: %u\n\r", value) ;
print(buf) ;
}
int main(void)
{
uint32_t time = 0 ;
int sys_tick_slot = 0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
sys_tick_slot = find_empty_slot() ;
if (sys_tick_slot < 0) {
print("Sorry No empty SysTick Slot available\n\r") ;
while(1) { } /* halting here */
} else {
CySysTickStart() ;
CySysTickSetCallback(sys_tick_slot, tick_callback) ;
}
splash("millis() test with SysTick") ;
clear_millis() ; // optional
for(;;)
{
time = millis() ;
print_time(time) ;
CyDelay(1000) ;
}
}
CY8CKIT-059
#include "project.h"
#include "stdio.h"
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
UART_PutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(100) ;
print("\033[2J") ; /* clear screen */
CyDelay(100) ;
}
void splash(char *title)
{
cls() ;
if (title && *title) {
print(title) ;
print(" ") ;
}
snprintf(str, STR_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
print(str) ;
}
volatile uint32_t tick_count = 0 ;
CY_ISR(tick_callback)
{
tick_count++ ;
}
int find_empty_slot(void)
{
int result = -1 ;
uint32_t i ;
for (i = 0 ; i < CY_SYS_SYST_NUM_OF_CALLBACKS ; i++ ) {
if (CySysTickGetCallback(i) == NULL) {
result = i ;
break ;
}
}
return(result) ;
}
void show_delta_time(void)
{
static uint32_t prev_tick = 0 ;
uint32_t new_tick = 0 ;
uint32_t delta = 0 ;
new_tick = tick_count ;
delta = new_tick - prev_tick ;
prev_tick = new_tick ;
snprintf(str, STR_LEN, "Current: %d -> %d ms passed\n\r", new_tick, delta) ;
print(str) ;
}
void clear_millis(void)
{
tick_count = 0 ;
}
uint32_t millis(void)
{
return( tick_count ) ;
}
void print_time(uint32_t value)
{
char buf[65] ;
snprintf(buf, 64, "millis: %u\n\r", value) ;
print(buf) ;
}
int main(void)
{
uint32_t time = 0 ;
int sys_tick_slot = 0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
sys_tick_slot = find_empty_slot() ;
if (sys_tick_slot < 0) {
print("Sorry No empty SysTick Slot available\n\r") ;
while(1) { } /* halting here */
} else {
CySysTickStart() ;
CySysTickSetCallback(sys_tick_slot, tick_callback) ;
}
splash("millis() test with SysTick") ;
clear_millis() ; // optional
for(;;)
{
time = millis() ;
print_time(time) ;
CyDelay(1000) ;
}
}
Hope this can be some use for those with need of "millis()" 😉
これで“millis()” を使いたい方の助けになると良いのですが。 (^_^)v
17-Dec-2021
moto
Show Less