- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I may be missing simple here and am hoping that is all it is. I setup this logic circuit in order to create a simple state machine (I tried with the LUT as well and encountered the same issue). The way it is supposed to work is if the button is pressed the LED turns on, if the button is pressed again nothing happens. If it is pressed again the LED turns off, then the cycle repeats. The issue I am encountering is that the LED always follows the clock pulse and always turns on whenever the button is pressed.
I attempted switching the clock input for the flip-flops with the button, however the same issue persisted. The clock (tied to the Clk_pin) was made from two cascading watchdog timers for 1 Hz. I changed this to an on board clock at 367 Hz (minimum frequency division for CY8CKIT-044 Pioneer kit) and the issue still persisted.
I have attached the code I made for the 1 Hz clock I created with the schematic design and timer setup.
------------------------------------------
void Clk()
{
ClkPin_Write(~ClkPin_Read());
}
int main()
{
/* Enable the global interrupt */
CyGlobalIntEnable;
CySysWdtSetInterruptCallback(CY_SYS_WDT_COUNTER1,Clk);
CySysWdtSetCascade(CY_SYS_WDT_CASCADE_01);
CySysWdtSetMatch(0,512);
CySysWdtSetMatch(1,64); //So our total divide is 512*64
for(;;)
{
CySysPmDeepSleep();
}
}
Solved! Go to Solution.
- Labels:
-
ispn:39614:1:0
-
l1:314:1:0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adam,
I give your issue a try.
Attached is a VERY SIMPLE project using your select PSoC4 device.
Here is the simplified schematic.
It has the following specs:
- Button/LED logic is ALL in HW state machine. The code only starts the timer. There is NO SW intervention after that.
- The Button/LED logic is in a LUT with registered outputs.
- LED drive is active high. If you need active low logic, you can invert the LED output in the LUT or place a NOT gate in the output.
- The Button input is active low. If you need active high logic, you can invert LUT logic or place a NOT gate in the input.
- The HW state machine logic is clocked at 10Hz. The timer is based on the HFCLK. The LFCLK is not needed here.
- The Button debounce time is 100ms. This should be slow enough to filter out switch bounces.
- The Button and LED port pin assignments were system default. You may need to assign them to the correct pins in your 044 kit.
Here is a flow diagram of the HW state machine.
Here is the LUT table. Note: some of the states are "illegal". If these LUT states are encountered, it "resets" to the Button idle state.
I do not have a PSoC4 of the type you selected to test the project. HOWEVER ... I did convert the project to a PSoC5LP of which I have a kit. It does work. So I have confidence the PSoC4 project also work and the project builds without error.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Adam21 ,
Could you please share the stripped-down version of your project in which you are implementing this state machine.
And have you used button debouncing for this purpose?
Thanks and regards
Sobhit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is my first time using these forums, how do I submit files if it does not allow the cywrk file type?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Adam21 ,
Create an archive for your project and upload the zip file in your reply.
See the above image for reference.
Thanks and regards
Sobhit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adam,
I give your issue a try.
Attached is a VERY SIMPLE project using your select PSoC4 device.
Here is the simplified schematic.
It has the following specs:
- Button/LED logic is ALL in HW state machine. The code only starts the timer. There is NO SW intervention after that.
- The Button/LED logic is in a LUT with registered outputs.
- LED drive is active high. If you need active low logic, you can invert the LED output in the LUT or place a NOT gate in the output.
- The Button input is active low. If you need active high logic, you can invert LUT logic or place a NOT gate in the input.
- The HW state machine logic is clocked at 10Hz. The timer is based on the HFCLK. The LFCLK is not needed here.
- The Button debounce time is 100ms. This should be slow enough to filter out switch bounces.
- The Button and LED port pin assignments were system default. You may need to assign them to the correct pins in your 044 kit.
Here is a flow diagram of the HW state machine.
Here is the LUT table. Note: some of the states are "illegal". If these LUT states are encountered, it "resets" to the Button idle state.
I do not have a PSoC4 of the type you selected to test the project. HOWEVER ... I did convert the project to a PSoC5LP of which I have a kit. It does work. So I have confidence the PSoC4 project also work and the project builds without error.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I implemented this project as a PSoC4 project just fine (aside from updating components) however, I noticed that the LED turned on as the project was loaded right away. Pressing the button did change the LED state but only after 4-5 presses (varied on how long you held the button for). I double checked that the logic was the same as the screen shot you provided and it was. Was there a particular way you had set up the "Timer_Debounce" block to avoid this issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also forgot to add that after the LED turned off it I couldn't get it turn back on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adam,
Can you provide your project where you implemented my LUT?
Since I don't have a 044 kit, I had to convert it to a 059 kit (PSoC5LP).
I can try to take your implementation and convert it to the PSoC5LP to see if I get the same results.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adam,
My implementation on the PsoC5LP seems to work without issue.
Your implementation of my recommended LUT might have some issues. Hence placing your project on this forum should be helpful.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I only loaded the project you produced to see the LED follow the LUT but it didn't seem to quite follow it. I am attaching the file that I loaded to my device although it should be the same as what you initially uploaded. As I said before the LED turns on when the program is first loaded and takes more button presses than the LUT requires to turn it off instead of the single or even double button presses as per your diagram. I am attempting on wiring a external button in place of the clock so I have more control over when input is sent the LUT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adam,
What is the polarity of your LED drive?
LED active high:
LED ON | 1 |
LED OFF | 0 |
or
LED active low:
LED ON | 0 |
LED OFF | 1 |
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is an active low. Implementing the not gate did fix that as it was something I did initially over look. Tying a external button to the pin of the LUT did help me realize that it was a clocking issue. So when the both buttons were pressed (the CLK button would mimic a rising edge) it would change more consistently with the LUT. Feeding the internal clock into the clock input of the LUT without going through the counter fixed the issue I was having. Thank you for your help I greatly appreciate it. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just a side note. You might be able to implement this logic totally in hardware using the Smart I/O. The Smart I/O can run in deep-sleep if you clock it using the low-frequency clock.
So no need to use the CPU at all here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Rodolfo,
Good point. However, I believe the part Adam is using doesn't support SmartIO.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I see. I looked at the current suggested implementation. The timer that comes with the PSoC is very powerful. There are a bunch of features you can leverage in there, not only a timer. If you use the count and reload terminals, you can implement a debounce into the timer itself. You only need a toggle flip-flop to turn on/off the LED.
Attached you find a simple project (I used PSoC 6, but you can port it to PSoC 4). Here is a screenshot.
You can customize the Period and Compare values to adjust the debouncing time. Note you need to use Clk_Peri/2 to clock your components.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adam21,
If you only need to debounce a button, then you can check existing component
ButtonSw32: button switch debouncer component
It doesn't consume PSoC4 hardware resources, which are quite limited, and allows up to 32 buttons.