cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

 my problem is:

   

How do I count the number of high-level output of a comparator zero-crossing?

I have to count how many zero-crossing exist in a second, therefore a counter must count for 1 second and give back the number of zero-crossing and put it in a global variable.

   

any idea?

thanks all!

0 Likes
Reply
4 Replies
Employee

Here is one method

   
        
  1. Connect the Comparator bus to the Clock of an 8 bit or 16 bit counter.  Choose between 8 bit or 16 bit based on the number of Zero Crossing pulses you expect in a second.
  2.     
  3. Initialize the counter to to 0xFF or 0xFFFF using the Counter_WritePeriod function.
  4.     
  5. Configure another counter for a period of 1 second.  For example, you can use a 16 bit counter with a period of 32000 and clock of 32K or any such combination.  Enable the terminal count interrupt of this counter. Let us call this TimeBase
  6.     
  7. Start the TimeBase counter and enable its interrupt
  8.     
  9. Start the main counter
  10.     
  11. Inside the interrupt of the TimeBase counter, start the main counter, read its count value and subtract it from 0xFF or 0xFFFF.  That will give you number of Zero Crossings in a second.
  12.    
   


Best Regards,
Ganesh

0 Likes
Reply
Anonymous
Not applicable

I did this project, I do not know if it is right .. Can you see it please?

   

regards

0 Likes
Reply
Employee

There were some problems with your project.

1. When you set the clocksync parameter to Use Sysclk Direct, it overrides the Clock input and makes 24MHz IMO as the clock to the digital block.  So, in your project, both the counter and timer will be running at 24MHz.  The correct clock sync parameter is SyncToSysclk
2. TimerINT.asm file is an assembly file.  You cannot write C code inside this file.  Instead, write your ISR in C in main.c, declare it as interrupt handler using #pragma interrupt_handler and then place an ljmp to this ISR inside the TimerINT.asm file.

I have modified the project with the above and have added an LCD to display the read value.  If you have a suitable board with an LCD connected to Port2, you can use this to test the project.  However, I have not tested the project.

Best Regards,
Ganesh

0 Likes
Reply
Anonymous
Not applicable

thanks!

   

 I now try, and I tell you, thanks. 

   

maybe you can save space by converting, first, analog to digital, and after write code in main?

0 Likes
Reply