Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
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.
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.