- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi 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
- Labels:
-
PSoC 345 LP