Here is one method
- 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.
- Initialize the counter to to 0xFF or 0xFFFF using the Counter_WritePeriod function.
- 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
- Start the TimeBase counter and enable its interrupt
- Start the main counter
- 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.
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.
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?