Code Examples Forum Discussions
Hello.
I am new to PSOC
I am trying to measure the duty cycle of PWM signal, and I do get the high count right, but I do not get the low count and the period.
I attached the Oscilloscope screen, from the PWM module output on pin m_2.
Attached the main C file.
Attached the UART output.
Thanks.
Hanan.
Hello Community!
For those of you that live on the northern hemisphere the "Dark Times" have begun. Time to stay at home instead of strolling through the nature, much time to evaluate something new.
I have written a simple RTOS (Real-Time Operating System) and I want to give it to the PSoC community. At first I provide you with a script to make you comfortable with the general concepts of RTOSses. Read that first, I would be glad for any comments on it.
The supplied project archive is made for the CY8CKIT-044 PSoC® 4 M-Series Pioneer Kit and is using some of the on-board hardware, as the accelerometer and the daylight sensor. The project needs a terminal emulation program on the PC and will display its result on the computer screen.
The RTOS (I named it ARTS) would run on a CY8CKIT-043 PSoC® 4 M-Series Prototyping Kit, but due to the lack of additional hardware it could be a bit boring to watch an LED blinking. When you have set up some external hardware as sensors or actuators it can get interesting again.
I have to admit, there is no manual for ARTS. I did my very best to describe the APIs in the ARTS.h file. I would suggest you to go through that description. Any comments welcome.
Bob
Show Lesshi
Can we get any example about usb to i2s ? we want to play a audio voice from usb to i2s
the develop software is modus
hardware is CY8C6247BZI-D54
thanks
james
Show LessHI,
I am using PSOC4 (CY8C4247LQI-BL483), i am using internal rtc, RTC_SetDateAndTime(dateTime[0],dateTime[1]); RTC_GetDateAndTime(&dateTimeStruct), with 12 hours format
The time is updating but the am and pm does not update (eg it won't switch from 11:59AM to 12:00PM, the rtc will update to 12:00PM). Hence the date and the month is not incrementing/ changing.
Need some help with the same.
Cheers
Show LessHello everybody,
I am still a noobie here and hope that you can help me :-).
I have written a program in which I determine a voltage drop (ADC converter) via a shunt resistor, then calculate the current for me and then output the measured value via HTerm.
Now I would like to have the readings displayed in a stream-time diagram and, optimally, store the values in a .csv or .xls.
I would like it if the Excel list looks like this:
Date | Time | Voltage Ush [mV] | Current Ipv [mA} |
---|---|---|---|
14.06.2019 | 11:31:45 | 402,786234 | 6,7130771 |
14.06.2019 | 11:32:22 | 403,324678 | 6,7220780 |
14.06.2019 | 11:33:01 | 405,124255 | 6,7520709 |
The final version would be to average every minute over a measurement and then every five minutes to average the previous average. So that a value is output every 5 minutes.
So should be the diagram that every 5 minutes a new value is displayed.
Thank you very much and sunny greetings from Germany
jg.vs
I am using the PSoC 4000S device in a product I am working on and I need to use a thermistor to measure temperature. I do not see the thermistor component selection available in Creator for this device. Is this component not available in the PSoC 4000S? If it is not available how best can I use a thermistor on a 4000S device?
Thanks
Scott
Show LessThis time, actually a while ago, I came across a chance to make a sample project of thermistor.
Although the circuit seemed to be easy, the calculation was not as easy as I was expecting.
According to the web page of the thermistor, we can calculate the resistance of a thermistor with following equation.
Rt : Resistance at temperature t (kelvin)
R0: Resistance at T0
B: Thermistor related constant. For 103AT-11 it is 3435 +/- 1%
Conversion from Tk (Kelvin) to Tc (Celsius) is Tc = Tk - 273.15
Dividing both sides by R0, we get
Replacing e to log
Dividing both sides by B
From the Datasheet the resistance value of this thermistor is 10.0K at 25 degree Celsius,
so if we replace R0 to R25 and T0 to T25 (Klevin for 25c) the equation is now
Moving 1/T25 from the right side to the left side
Reducing the left side
Then reforming the equation according to T
Finally we get
In the figure below
Rt = R1 x Vt / (VDDA -Vt)
If we normalize the ADC value (ADin) of input voltage 0V ~ VDDA V to 0.0 ~ 1.0
Rt = R1 x ADin / (1 - ADin)
Now we can write a code
Rt = R1 * ADin / (1 - ADin) ;
K = 1.0 / (log(Rt / R25) / B + 1.0/T25) ;
T = K - 273.15 ;
To make the long story short, here is the whole enchilada!
(aka, project attached...)
moto
Show LessA few days ago, I saw a question about how to use WDT reset.
How can I set WDT to reset directly? PSoC 4100S (CY8C4125AXI-S433)
Then I wrote a sample just trigger WDT interrupt and/or Software Reset,
but I failed to Implement feeding the dog.
So in this example I tried to provide a simple sample which does
(0) Report the reason of the previous reset
(1) Software Reset
(2) WDT Timeout Reset
and to make it easier to realize, I let the LED blink a few times
when program got started (or restarted).
数日前、WDTリセットの使用方法についての質問トピックがありました。
How can I set WDT to reset directly? PSoC 4100S (CY8C4125AXI-S433)
その時は、とりあえず WDT リセットを発生するか、
Software Reset を発生するサンプルを書いてみましたが、
そもそも正常な WDT のクリアは実装していませんでした。
今回、このサンプルでは、下記の機能を付けてみました
(0) 起動時、直前のリセット原因を(わかる範囲で) 表示する
(1) Software Reset を発生させる
(2) WDT Reset を発生させる
実際にリセットが掛かったのかが分かりにくかったので、
起動時(又は再起動時) に数回 LED を点滅させてみました。
The schematic
Pin for TSoC
Pin for CY8CKIT-149
main.c
============================
#include "project.h"
#include "stdio.h"
#include "string.h"
#define STR_LEN 32
#define RX_BUF_LEN 128
#define SPACE ' '
#define TAB '\t'
#define CR '\r'
#define LF '\n'
volatile char rx_buf[RX_BUF_LEN] ;
volatile int rx_write_index = 0 ;
int rx_read_index = 0 ;
char str[STR_LEN+1] ; /* print buffer */
int str_index = 0 ;
int wdt_feed_flag = 1 ;
inline int is_delimiter(uint8_t c) ;
int get_str(void) ;
void str2upper(char str[]) ;
void init_hardware(void) ;
void splash(void) ;
void prompt(void) ;
void blink_led(void) ;
void print(char *str) ;
CY_ISR_PROTO(usr_isr) ;
void help(void)
{
print("=== reset test command ===\n") ;
print("sw : cause software reset\n") ;
print("wdt : cause watch dog reset (wait a few seconds)\n") ;
print("help : print this message\n") ;
print("==========================\n") ;
}
void print_reset_cause(void)
{
// uint32_t value ;
// value = CY_SYS_RES_CAUSE_REG ;
print("Reason of previous reset: ") ;
if (CY_SYS_RESET_WDT == CySysGetResetReason(CY_SYS_RESET_WDT)) {
print("Watch Dog Timeout") ;
} else if (CY_SYS_RESET_PROTFAULT == CySysGetResetReason(CY_SYS_RESET_PROTFAULT)) {
print("Protection Violation") ;
} else if (CY_SYS_RESET_SW == CySysGetResetReason(CY_SYS_RESET_SW)) {
print("Software") ;
} else {
print("Unknown") ;
}
print("\n") ;
}
void disable_wdt(void)
{
CY_SYS_WDT_DISABLE_KEY_REG = 0xACED8865 ;
}
void enable_wdt(void)
{
CY_SYS_WDT_DISABLE_KEY_REG = 0x0000 ;
}
void feed_wdt(void)
{
CY_SYS_SRSS_INTR_REG |= CY_SYS_RESET_WDT ;
}
void init_hardware(void)
{
disable_wdt() ;
UART_SpiUartClearRxBuffer() ;
UART_SpiUartClearTxBuffer() ;
UART_ClearRxInterruptSource(UART_GetRxInterruptSource()) ;
uart_rx_int_ClearPending() ;
uart_rx_int_StartEx(usr_isr) ;
UART_Start() ;
CyGlobalIntEnable; /* Enable global interrupts. */
}
void do_command(char *cmd)
{
str2upper(cmd) ;
if (strcmp(cmd, "WDT") == 0) {
// enable_wdt() ;
wdt_feed_flag = 0 ;
} else if (strcmp(cmd, "SW") == 0) {
CySoftwareReset() ;
} else if (strcmp(cmd, "HELP") == 0) {
help() ;
} else {
print("Unknown command: ") ;
print(cmd) ;
print("\n") ;
help() ;
}
}
int main(void)
{
init_hardware() ;
splash() ;
print_reset_cause() ;
help() ;
blink_led() ;
enable_wdt() ;
prompt() ;
for(;;) {
if (get_str() > 0) {
do_command(str) ;
prompt() ;
}
if (wdt_feed_flag) {
feed_wdt() ;
}
}
}
inline int is_delimiter(uint8_t c)
{
int result = 0 ;
switch(c) {
case CR:
case LF:
case TAB:
case SPACE:
result = c ;
break ;
}
return( result ) ;
}
int get_str(void)
{
int result = 0 ;
if (rx_read_index != rx_write_index) {
if (is_delimiter(rx_buf[rx_read_index])) {
if (str_index > 0) {
str[str_index] = 0 ;
str_index = 0 ;
result = 1 ;
}
} else {
str[str_index++] = rx_buf[rx_read_index] ;
if (str_index >= STR_LEN) {
str[STR_LEN] = 0 ;
str_index = 0 ;
result = -1 ;
}
}
rx_read_index = (rx_read_index + 1) % RX_BUF_LEN ;
}
return( result ) ;
}
CY_ISR(usr_isr)
{
UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY) ;
if (UART_SpiUartGetRxBufferSize()) {
rx_buf[rx_write_index] = UART_UartGetByte() ;
rx_write_index = (rx_write_index + 1) % RX_BUF_LEN ;
}
}
void print(char *str)
{
UART_UartPutString(str) ;
}
void splash(void)
{
sprintf(str, "\nWDT Test (%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
}
void blink_led(void)
{
int i ;
for (i = 0 ; i < 10 ; i++ ) {
LED_Write(!LED_Read()) ;
CyDelay(100) ;
}
}
void prompt(void)
{
print("> ") ;
}
void str2upper(char str[])
{
int i ;
for (i = 0 ; str ; i++ ) {
if (('a' <= str)&&(str <= 'z')) {
str -= ('a' - 'A') ;
}
}
}
/* [] END OF FILE */
============================
Tera Term Log
moto
Show LessI spent several hours looking here and on the Internet for a simple example that shows how to write a byte to EEPROM and then how to get it back. I need to save setup information so a restart can retrieve it and use the latest settings. I found many examples that involve EEPROM as well as LCDs, thermocouples, ADCs, arrays, vectors, and so on. These examples ARE NOT helpful. They contain too much "clutter" that confuses nonexperts like me and others. I often wonder if some people post examples simply to display their programming expertise rather than to educate others.
This criticism extends to other PSoC Creator devices in the 5LP chip I often work with. I spent a lot of time trying to get simple examples for Timers, PWMs, quadrature encoders, and other building blocks. For the most part, basic examples don't exist. The "Code Examples" section of the Cypress site could use a way to rate examples, perhaps as appropriate for beginners, moderately experienced users, long-time users, experts, and Cypress staff people. And every device should have a "beginners-level" example.
I looked at the example for a quadrature decoder this morning. It uses PWMs, and other components. But people would be better served if the example used a simple $3 incremental encoder and explained ways to use the APIs to do useful things. If someone wants to go beyond that more-advanced examples might help.
I like the PSoC devices, but lack of basic "start up" examples will point me to other MCU manufacturers.
Show Less