Code Examples Forum Discussions
I have provided a KBA on how to generate QRCodes using SEGGER's emWin middleware library.
This KBA also includes PSoC Creator and ModusToolbox examples.
Here's the link: Using emWin's QR-Code functions – KBA231613
It cool and it works!
Len
Show LessHello,
This is a sample project for handling I2C slave errors for CY8CKIT-145-40XX.
I have also prepared an I2C master project for programming into another CY8CKIT-145.
I prepared a photo when connecting with the connection diagram.
Please refer to the pdf in the attached project file.
Show LessHello,
This is a sample project in which table data of sine waveform is placed in FLASH with FLASH row assignment, sine waveform is generated from this table with idac, inverting bias is performed at + 1.2V, and input to ADC.The gain of Opamp is x1 times. The sampling period is 100Hz.
When the chart is displayed on the Bridge Control Panel, it looks like the following.
Best regards,
Yocchi
Show LessHi,
As you know, the DMA of PSoC 4 has 2 descriptors to implement PING-PONG, or back-to-back buffering translation.
So I was expecting to configure them for two different translations, which will result utilizing a DMA channel just like they were a couple of DMA channels.
In my previous study, I used 8 DMA channels to implement ADC-DMA-UART for displaying human readable hexadecimal strings.
A study of simple ADC and DMA and UART (CY8CKIT-044)
This time I tried to combine each ADC_RAW_H and ADC_RAW_L, DMA_H_ADR and DMA_L_ADR into one DMA with 2 descriptors.
And also I merged 4 DMAs used to send the result output into one DMA, but it required another DMA to transfer the char addresses into the result string,
I ended up 4 DMAs total, and 3 of them are using two descriptors.
Actually I have been trying to use this dual descriptor feature since I tried to write a simple oscilloscope sample.
A study of simple oscilloscope using ADC and DMA (CY8CKIT-044) version 1
But somehow I have managed to keep failing to use this feature.
This time I decided to challenge this for good, it took me more than a whole week though...
Although I could not find explicit description(s) how to do this.
Following is how I could make it work.
I use DMA_ASC for a sample.
(1) Obviously I "Number of descriptors" needs to be 2
(2) Descriptor 0 Configuration
Transfer mode: Entire descriptor chain per trigger
Post completion actions: "Chain to descriptor 1" (This is automatically checked.)
(3) Descriptor 1 Configuration
Transfer mode: Entire descriptor per trigger
Post completion actions: Chain to descriptor 0
Note: For me this configuration was hard to come up with.
Since descriptor 0 works without farther configuration, it took me very long time and many trials to figure out that
descriptor 1 needs to be manually validated
So initialization for this DMA_ASC looks like
====================
DMA_ASC_Start((void *)h_char, (void *)(&CYDMA_DESCR_BASE.descriptor[DMA_STR_CHANNEL][0].src)) ;
DMA_ASC_SetSrcAddress(1, (void *)l_char);
DMA_ASC_SetDstAddress(1, (void *)(&CYDMA_DESCR_BASE.descriptor[DMA_STR_CHANNEL][1].src)) ;
CyDmaValidateDescriptor(DMA_ASC_CHANNEL, 1) ;
====================
With above modification(s), the schematic was modified
from the previous schematic
to the current schematic
Pins
Tera Term log
main.c
========================
#include "project.h"
#include "stdio.h"
#include "ascii_byte_table.h"
uint32_t h_char_address = (uint32_t) ascii_h ;
uint32_t l_char_address = (uint32_t) ascii_l ;
uint8_t *h_char = (void *)&h_char_address ;
uint8_t *l_char = (void *)&l_char_address ;
char out_str[7] = { '0', 'x', 'H', 'L', '\n', '\r', '\0' } ;
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
ADC_Start() ;
DMA_UART_Start((void *)out_str, (void *)UART_TX_FIFO_WR_PTR) ;
DMA_STR_Start((void*)h_char, (void *)(&out_str[2])) ;
DMA_STR_SetSrcAddress(1, (void *)l_char);
DMA_STR_SetDstAddress(1, (void *)(&out_str[3])) ;
CyDmaValidateDescriptor(DMA_STR_CHANNEL, 1) ;
DMA_ASC_Start((void *)h_char, (void *)(&CYDMA_DESCR_BASE.descriptor[DMA_STR_CHANNEL][0].src)) ;
DMA_ASC_SetSrcAddress(1, (void *)l_char);
DMA_ASC_SetDstAddress(1, (void *)(&CYDMA_DESCR_BASE.descriptor[DMA_STR_CHANNEL][1].src)) ;
CyDmaValidateDescriptor(DMA_ASC_CHANNEL, 1) ;
DMA_ADC_Start((void *)ADC_SAR_CHAN0_RESULT_PTR, (void *)h_char) ;
DMA_ADC_SetSrcAddress(1, (void *)h_char) ;
DMA_ADC_SetDstAddress(1, (void *)l_char) ;
CyDmaValidateDescriptor(DMA_ADC_CHANNEL, 1) ;
}
int main(void)
{
init_hardware() ;
UART_UartPutString("\x1b[2J\x1b[;H") ;
UART_UartPutString("ADC-DMA-UART 2-descriptors Test\n\r") ;
Timer_Start() ;
for(;;)
{
}
}
========================
ascii_byte_table.h
========================
#ifndef _ASCII_BYTE_TABLE_H_
#define _ASCII_BYTE_TABLE_H_
#include "project.h"
extern const uint8_t ascii_h[256] ;
extern const uint8_t ascii_l[256] ;
#endif
========================
ascii_byte_table.c
========================
#include "project.h"
#include "ascii_byte_table.h"
const uint8_t ascii_h[256]
__ALIGNED(0x100u)
= {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
'2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
'3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
'4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
'5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
'6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
'7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
'8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
'9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',
'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B',
'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D',
'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E',
'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F'
} ;
const uint8_t ascii_l[256]
__ALIGNED(0x100u)
= {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
} ;
========================
moto
Show LessHi all,
I made a program to control electronic dice from BLE. The remote control side of BLE used the program of Central that I posted previously as it was, and controlled the start and stop of the dice by the movement of the slider. In the photo, the top is the electronic dice and the bottom is the remote control. The remote control below is connected to the mobile battery to supply power.
The environment used is as follows:
・PSoC Creator 4.2
・CY8CKIT-062-BLE
As for the circuit of the dice, I did not like the circuit I posted last time, so I returned it to the previous one and added the BLE component. Please refer to the previous post for LED placement. The circuit and the pin assignment in PSoC6 are as follows.
The program of BLE event handler is as follows:
void genericEventHandler(uint32_t event, void *eventParameter)
{
cy_stc_ble_gatts_write_cmd_req_param_t *writeReqParameter;
/* Take an action based on the current event */
switch (event)
{
/* This event is received when the BLE stack is Started */
case CY_BLE_EVT_STACK_ON:
case CY_BLE_EVT_GAP_DEVICE_DISCONNECTED:
PWM_BLINK_Start();
Cy_BLE_GAPP_StartAdvertisement(CY_BLE_ADVERTISING_FAST, CY_BLE_PERIPHERAL_CONFIGURATION_0_INDEX);
break;
case CY_BLE_EVT_GATT_CONNECT_IND:
Cy_TCPWM_TriggerReloadOrIndex(PWM_BLINK_HW,PWM_BLINK_CNT_NUM);
Cy_TCPWM_PWM_Disable(PWM_BLINK_HW,PWM_BLINK_CNT_NUM);
break;
case CY_BLE_EVT_GATTS_WRITE_REQ:
writeReqParameter = (cy_stc_ble_gatts_write_cmd_req_param_t *)eventParameter;
if((CY_BLE_LED_GREEN_CHAR_HANDLE == writeReqParameter->handleValPair.attrHandle) ||
(CY_BLE_LED_BLUE_CHAR_HANDLE == writeReqParameter->handleValPair.attrHandle))
{
val = writeReqParameter->handleValPair.value.val[0];
if(val>100) val = 100;
if(val>valp){
PWM_1_SetCounter(0);
PWM_1_SetPeriod0(399);
PWM_1_Start(); // Start rolling dice
sw=1; // sw is on
valp = val;
}
if(val<valp){
/* Roll dice slowly */
PWM_1_SetCounter(0);
PWM_1_SetPeriod0(1999);
CyDelay(1500); // keep rolling slowly for 1.5sec
PWM_1_Disable();// Stop rolling dice
sw=0; // sw is off
valp=0;
}
}
Cy_BLE_GATTS_WriteRsp(writeReqParameter->connHandle);
break;
default:
break;
}
}
Reference information
- Concept of electronic dice: Let's make the dice of seven eyes with PSoC 6 (M4), the protagonist of the game
- PSoC 6 BLE controller (This Code Example is PSoC6_LED_BleCentral.cyfsn.zip):BLE demo using 2 kits
- PSoC 6 Electronic Dice (previous post): Let's make the dice of seven eyes on PSoC 6 with CapSense & sound,the protagonist of the game
Thanks,
Kenshow
Show LessHi,
As I accumulated homework in my previous sample/study,
I wanted attack one by one.
A study of simple oscilloscope using ADC and DMA (CY8CKIT-044) version 1
So the first one I challenged was
Display ADC value into UART without using CPU (except initialization).
As you know, the result of ADC component is a binary value,
I must figure out (aka hack) a way to convert a binary value into UART readable ascii letters.
Of course if we use CPU, it's a peace of cake, but without CPU it was not.
After a few days of struggle I came up with the following trick.
(1) I limit the result value of ADC as 8bit. So it's a couple of ascii letters, such as "00" "1A", etc.
(2) I prepared a couple tables which has the upper letter and the lower letter of the value.
(3) At first I assign the beginning of the above tables into the letter to UART DMA. (DMA_ASC_H and DMA_ASC_L)
(4) Each ADC results, the value will be DMAed to the LSB of each table address variable(s). (DMA_RAW_H and DMA_RAW_L)
Note: As a register is 4 bytes structure, I needed to create a 4 bytes variable then DMA the variable word to word.
(5) Then the table address value will be DMAed to the source address of Letter to UART DMA. (DMA_H_ADR and DMA_L_ADR)
The higher nibble letter table
Note: For the trick, the table is aligned to 0x100 boundary.
======================
const uint8_t ascii_h[256]
__ALIGNED(0x100u)
= {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
'2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
'3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
'4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
'5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
'6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
'7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
'8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
'9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',
'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B',
'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D',
'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E',
'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F', 'F'
} ;
======================
The lower nibble letter table
Note: For the trick, the table is aligned to 0x100 boundary.
======================
const uint8_t ascii_l[256]
__ALIGNED(0x100u)
= {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
} ;
======================
Note ascii_h[0xAB] = 'A' and ascii_l[0xAB] = 'B'
Schematic
Almost a Rube Goldberg machine...
Pins
main.c
========================
#include "project.h"
#include "stdio.h"
#include "tty_utils.h"
#include "ascii_byte_table.h"
#define DEBUG_INFO 0
uint32_t h_char_address = (uint32_t) ascii_h ;
uint32_t l_char_address = (uint32_t) ascii_l ;
uint8_t *h_char = (uint8_t *)&h_char_address ;
uint8_t *l_char = (uint8_t *)&l_char_address ;
volatile int dma_done_flag = 0 ;
CY_ISR(dma_done_isr)
{
dma_done_flag = 1 ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
tty_init() ;
ADC_Start() ;
DMA_PRE_Start( (void *)prefix, (void *)UART_TX_FIFO_WR_PTR) ;
DMA_ASC_H_Start((void *)h_char, (void *)UART_TX_FIFO_WR_PTR) ;
DMA_ASC_L_Start((void *)l_char, (void *)UART_TX_FIFO_WR_PTR) ;
DMA_EOL_Start( (void *)eol, (void *)UART_TX_FIFO_WR_PTR) ;
DMA_H_ADR_Start((void *)h_char, (void *)(&CYDMA_DESCR_BASE.descriptor[DMA_ASC_H_CHANNEL][0].src)) ;
DMA_L_ADR_Start((void *)l_char, (void *)(&CYDMA_DESCR_BASE.descriptor[DMA_ASC_L_CHANNEL][0].src)) ;
DMA_RAW_H_Start((void *)ADC_SAR_CHAN0_RESULT_PTR, (void *)h_char) ;
DMA_RAW_L_Start((void *)ADC_SAR_CHAN0_RESULT_PTR, (void *)l_char) ;
dma_done_int_ClearPending() ;
dma_done_int_StartEx(dma_done_isr) ;
}
void dump_dma_ch(int ch)
{
snprintf(str, STR_BUF_LEN, "DMA%d\n\r", ch) ;
print(str) ;
print("descriptor 0 :") ;
snprintf(str, STR_BUF_LEN, "0x%08X -> 0x%08X CTRL:0x%08X Status:0x%08X\n\r",
(uint32_t)CYDMA_DESCR_BASE.descriptor[ch][0].src,
(uint32_t)CYDMA_DESCR_BASE.descriptor[ch][0].dst,
(uint32_t)CYDMA_DESCR_BASE.descriptor[ch][0].ctl,
(uint32_t)CYDMA_DESCR_BASE.descriptor[ch][0].status
) ;
print(str) ;
print("descriptor 1 :") ;
snprintf(str, STR_BUF_LEN, "0x%08X -> 0x%08X CTRL:0x%08X Status:0x%08X\n\r",
(uint32_t)CYDMA_DESCR_BASE.descriptor[ch][1].src,
(uint32_t)CYDMA_DESCR_BASE.descriptor[ch][1].dst,
(uint32_t)CYDMA_DESCR_BASE.descriptor[ch][1].ctl,
(uint32_t)CYDMA_DESCR_BASE.descriptor[ch][1].status
) ;
print(str) ;
}
void dump_dma(void)
{
print("DMA_RAW_H: ") ;
dump_dma_ch(DMA_RAW_H_CHANNEL) ;
print("DMA_RAW_L: ") ;
dump_dma_ch(DMA_RAW_L_CHANNEL) ;
print("DMA_H_ADR: ") ;
dump_dma_ch(DMA_H_ADR_CHANNEL) ;
print("DMA_L_ADR: ") ;
dump_dma_ch(DMA_L_ADR_CHANNEL) ;
print("DMA_ASC_H: ") ;
dump_dma_ch(DMA_ASC_H_CHANNEL) ;
print("DMA_ASC_L: ") ;
dump_dma_ch(DMA_ASC_L_CHANNEL) ;
print("DMA_PRE: ") ;
dump_dma_ch(DMA_PRE_CHANNEL) ;
print("DMA_EOL: ") ;
dump_dma_ch(DMA_EOL_CHANNEL) ;
print("DMA_ASC_LF: ") ;
snprintf(str, STR_BUF_LEN, "h_char: 0x%08X l_char: 0x%08X\n\r",
h_char_address, l_char_address) ;
print(str) ;
print("\n\r") ;
}
int main(void)
{
init_hardware() ;
splash("ADC-DMAx2 Test") ;
print("\n\r") ;
Timer_Start() ;
for(;;)
{
}
}
========================
Tera Term log
moto
P.S. Diagram for data flow added 25-Oct-2020
Show LessHi all,
In order to study how to turn on and control many LEDs, I created a board with a matrix. I decided to make a roulette wheel using 36 LEDs. This time I will run it with DMA in PSoC4.
The environment used is as follows:
・PSoC Creator 4.4
・CY8CKIT-044
36 LEDs are mounted on the Arduino board, and 12 GPIOs are used to configure a 6x6 matrix. The circuit looks like this:
The actual Arduino board was made as shown in the picture below. There were quite a lot of wiring and it got messed up.
For the circuit, delete the part that was built in the digital hardware last time, and change the data setting of GPIO output to be done by DMA. The circuit and pin layout are as follows.
All three DMA settings are the same. For word transfer, increment the source address (specify array data) and fix the destination address (specify GPIO register address). The Configuration of one of them is shown.
Press the SW2 switch to rotate the roulette wheel, and release it to slow down and stop.
The program is as follows:
#include "project.h"
int data1[6]={0x1F,0x2F,0x37,0x3B,0x3D,0x3E};
int data2[36]={0x08,0x08,0x08,0x08,0x08,0x08,
0x04,0x04,0x04,0x04,0x04,0x04,
0x02,0x02,0x02,0x02,0x02,0x02,
0x01,0x01,0x01,0x01,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00};
int data3[36]={0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x02,0x02,0x02,0x02,0x02,0x02,
0x01,0x01,0x01,0x01,0x01,0x01};
uint32_t sw=0; //sw is off (Stop rolling dicce)
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
*(int *)0x40040200 = 0x1F; // Initial LED setting
*(int *)0x40040100 = 0x08; // Initial LED setting
*(int *)0x40040300 = 0x00; // Initial LED setting
DMA_1_Start(data1,(void *)0x40040200);
DMA_2_Start(data2,(void *)0x40040100);
DMA_3_Start(data3,(void *)0x40040300);
for(;;)
{
if(sw==0){
// if(Cy_GPIO_Read(SW2_PORT,SW2_NUM)==0){
if(SW2_Read()==0){
PWM_1_WritePeriod(399);
PWM_1_WriteCounter(0);
PWM_1_Start(); // Start rolling dice
sw=1;
}
}
if(sw==1){
//if(Cy_GPIO_Read(SW2_PORT,SW2_NUM)==1){
if(SW2_Read()==1){
/* Roll dice slowly */
PWM_1_WritePeriodBuf(1999);
PWM_1_TriggerCommand(1, PWM_1_CMD_CAPTURE);
CyDelay(1000); // keep rolling slowly for 1sec
PWM_1_WritePeriodBuf(3999);
PWM_1_TriggerCommand(1, PWM_1_CMD_CAPTURE);
CyDelay(1000); // keep rolling slowly for 1sec
PWM_1_WritePeriodBuf(7999);
PWM_1_TriggerCommand(1, PWM_1_CMD_CAPTURE);
CyDelay(1500); // keep rolling slowly for 1sec
PWM_1_Stop(); // Stop rolling
sw=0; // sw is off
}
}
}
}
When you press the SW2 switch, the roulette wheel rotates, and when you release it, it gradually stops slowly.
Thanks,
Kenshow
Show LessHi all,
In order to study how to turn on and control many LEDs, I created a board with a matrix. I decided to make a roulette wheel using 36 LEDs.
The environment used is as follows:
・PSoC Creator 4.3
・CY8CKIT-044
36 LEDs are mounted on the Arduino board, and 12 GPIOs are used to configure a 6x6 matrix. The circuit looks like this:
The actual Arduino board was made as shown in the picture below. There were quite a lot of wiring and it got messed up.
The circuit creates a counter to count 6 by combining the components of Coutner and Compare in column side. It is used to select the De-Multiplexer to select the output.
The row side of the LED matrix is counted after 6 counts. As a result, the lighting of a LED moves to shift like a roulette. The circuit and pin layout are as follows.
Press the SW2 switch to rotate the roulette wheel, and release it to slow down and stop.
The program is as follows:
#include "project.h"
uint32_t sw=0; //sw is off (Stop rolling dicce)
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
// PWM_1_Start();
for(;;)
{
if(sw==0){
// if(Cy_GPIO_Read(SW2_PORT,SW2_NUM)==0){
if(SW2_Read()==0){
PWM_1_WritePeriod(399);
PWM_1_WriteCounter(0);
PWM_1_Start(); // Start rolling dice
sw=1;
}
}
if(sw==1){
//if(Cy_GPIO_Read(SW2_PORT,SW2_NUM)==1){
if(SW2_Read()==1){
/* Roll dice slowly */
PWM_1_WritePeriod(800);
PWM_1_WriteCounter(0);
CyDelay(1000); // keep rolling slowly for 1.5sec
PWM_1_WritePeriod(2000);
PWM_1_WriteCounter(0);
CyDelay(1000); // keep rolling slowly for 1.5sec
PWM_1_WritePeriod(4000);
PWM_1_WriteCounter(0);
CyDelay(1000); // keep rolling slowly for 1.5sec
PWM_1_WritePeriod(8000);
PWM_1_WriteCounter(0);
CyDelay(1500); // keep rolling slowly for 1.5sec
PWM_1_Stop();// Stop rolling
sw=0; // sw is off
}
}
}
}
When you press the SW2 switch, the roulette wheel rotates, and when you release it, it gradually stops slowly.
Thanks,
Kenshow
Show Less
Hi,
Before I posted a similar sample
A Simple Oscilloscope (CY8CKIT-044) using SerialPlotter
But in a discussion below, very fast sampling was required.
May I just measure the PWM pulse with SAR_ADC(CY8CKIT-044)
As I was not familiar with DMA, I have been studying it for a while now.
This sample is the first (somewhat) working version of my simple oscilloscope using ADC and DMA.
It is supposed to be sampling 2us each.
It seems to be working OK, but I want to implement the following 2 functionalities.
Probably in the later versions.
(1) Utilize 2 descriptors to prevent time lag. (But I can not detect it, even with current version using only 1 descriptor, which wonders me.)
(2) Implement a trigger to stop the signal at certain phase. (But I'd like to challenge this after (1))
SerialPoltter Screen
schematic
pins
main.c
Note: as usual I cheated by using my tty_utils.[ch] to make uart hanling easier,
but it's not the main topic of this sample anyway.
====================
#include "project.h"
#include "stdio.h"
#include "tty_utils.h"
#define RESULT_BUF_SIZE 1024
#define SAMPLING_CYCLE 2 /* us */
#define CLOCK_FREQ_MHZ 12
uint16_t result_buf[RESULT_BUF_SIZE] ;
int num_result = RESULT_BUF_SIZE ;
volatile int measured_flag = 0 ;
CY_ISR(meaure_done_isr)
{
measured_flag = 1 ;
}
void init_hardware(void)
{
uint32_t dma_dsc ;
CyGlobalIntEnable; /* Enable global interrupts. */
tty_init() ;
isr_1_ClearPending() ;
isr_1_StartEx(meaure_done_isr) ;
Counter_WritePeriod(num_result) ;
Counter_WriteCounter(0) ;
Counter_Start() ;
ADC_Start() ;
DMA_Start((void *)ADC_SAR_CHAN0_RESULT_PTR, result_buf) ;
dma_dsc = DMA_GetNextDescriptor() ;
DMA_SetNumDataElements(dma_dsc, num_result) ;
Timer_Init() ;
Timer_WritePeriod(SAMPLING_CYCLE * CLOCK_FREQ_MHZ) ;
Timer_WriteCounter(0) ;
}
void clear_buf(void)
{
int i = 0 ;
for (i = 0 ; i < RESULT_BUF_SIZE ; i++ ) {
result_buf = 0 ;
}
}
void dump_buf(void)
{
int i = 0 ;
for (i = 0 ; i < num_result ; i++ ) {
snprintf(str, STR_BUF_LEN, "%d\n\r", result_buf) ;
print(str) ;
}
}
int main(void)
{
int count = 0 ;
init_hardware() ;
splash("ADC-DMA Test") ;
Timer_Start() ;
for(;;)
{
if (measured_flag) {
measured_flag = 0 ;
dump_buf() ;
Counter_WriteCounter(0) ;
Timer_WriteCounter(0) ;
Timer_Start() ;
}
}
}
====================
moto
Show LessDear Arath-san and for those who may be interested,
I created a sample project using CY8CKIT-044.
Request
==========================
What will be the code for:
When the ADC measure 4V display the label "Maximum Voltage" and display it
in Putty terminal.
==========================
Note: As it must handle 4V (or higher), I set J9 of CY8CKIT-044 to 3-2 (5V)
Also in the Design Wide Resources > System
I set VDDA, VDDD, VDDIO to 5.0
schematic
Note: To test the program, I connected a POT (5.0V, P2(0), GND)
pins
ADC Configuration
main.c
===================
#include "project.h"
#include "stdio.h"
#define STR_BUF_LEN 64
char str[STR_BUF_LEN+1] ;
void print(char *str)
{
UART_UartPutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(20) ;
print("\033[2J") ; /* clear screen */
CyDelay(20) ;
}
void splash(char *prog_name)
{
cls() ;
if (prog_name && *prog_name) {
print(prog_name) ;
}
print(" (") ;
print(__DATE__) ;
print(" ") ;
print(__TIME__) ;
print(")\n\r") ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
ADC_Start() ;
}
int16_t measure(void)
{
int16_t raw_count ;
int16_t mV ;
int ch = 0 ;
ADC_StartConvert() ;
ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) ;
raw_count = ADC_GetResult16(ch) ;
mV = ADC_CountsTo_mVolts(ch, raw_count) ;
return( mV ) ;
}
void show_value(int16_t mV)
{
int overflow_flag = 0 ;
int negative = 0 ;
if (mV >= 4000) {
overflow_flag = 1 ;
}
if (mV < 0) {
negative = 1 ;
mV = -1 * mV ;
print("-");
}
snprintf(str, STR_BUF_LEN, "%d.%03d ", mV/1000, mV%1000) ;
print(str) ;
if (overflow_flag) {
print("Maximum Voltage") ;
}
print("\n\r") ;
}
int main(void)
{
int16_t mV ;
init_hardware() ;
splash("CY8CKIT-044 ADC Test with limit Voltage") ;
for(;;)
{
mV = measure() ;
show_value(mV) ;
CyDelay(1000) ;
}
}
===================
putty setup
putty output
moto
P.S. BTW, you could post a question/request in this Code Example Space,
then you may not have to wait for a day. (As I was taking off, yesterday)
Show Less