- 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.
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
- Labels:
-
PSoC 345 LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Kenshow-san,
Thank you very much for your contribution of CE.
Best regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I updated this program as follows:
・PSoC Creator 4.4 from 4.3
・Swapping function was used to switch the PWM period naturally
I checked the swap of period in the PWM_1 configuration.
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()) */
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
}
}
}
}
Thanks,
Kenshow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I did some code like this as well a couple of years ago...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your good information.
In a general microcomputer design, the LED is controlled by software as shown on the web you pointed out. However, in the case of PSoC, the feature is that it can be implemented using hardware (UDB). This will relieve the CPU load.
The part that gradually slows down the PWM was controlled by software in this time, but in combination with the timer, this can also be replaced with hardware (although it is a little difficult).
There are various approaches to the program, so I hope you can see it as one of the designs. Of course, information like your indication one is also welcome.
Thanks,
Kenshow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am going to post a program using DMA as another approach.
Thanks,
Kenshow