I have an application which needs to determine the frequency of a signal using a S7G2-DK and SSP1.1.3. This can be done with an interrupt keeping track of pulses for a given period of time. It looks like the AGT module has a mode where it can count external events. I added g_timer Timer Driver on r_agt to the HAL/Common thread. When configuring the timer Mode, there are only options for one-shot and periodic. Then I checked the Pins/Peripherals and in Operation Mode there is an Event Counter.
My questions: Would using the AGT be a way to determine the frequency of a signal? Any advice on setting it up?
In reply to dpalu:
Consider using a GPT timer. These are 32-bit timers so will give you greater frequency range and resolution.
By using the input capture feature the GPT hardware will automatically measure your input waveform.
The frequency is the GPT timer frequency (PCLKA) divided by the Input Capture timer value.
By default the Input Capture module only does pulse width measurement, whereas you require pulse period measurement.
However, it is possible to reconfigure the GPT Input Capture module.
Please see my attached project that uses "direct register" access to reconfigure the GPT registers.
I wrote this for a SK-S7G2, and use GPT7 as GTIOCA on Port 3.4 was easily accessible.
You can port this to whichever GPT channel you wish by changing the code to the appropriate registers etc.
Hope this helps.
In reply to Richard:
In reply to MCP:
Please find attached a E2Studio (6.2.1) SSP1.5.3 project for the S7G2_SK.
It configures GPT0 for event counter mode, meaning that an edge on the GTIOCA pin will increment the GPT Counter. It is configured to count rising edges, but it can be configured to count falling edges, or both.
I have configured GPT1 to generate a 1s interrupt. This interrupt triggers the DTC (Data transfer Controller) to read and store the value of the GPT0 Counter in an array. GPT1 will also generate another interrupt ( at 1s + 500ms ) that does a simple subtraction of the 2 count readings so that you get a counts per second value. This is stored in the variable g_1s_photon_count.
GPT0 will also generate an interrupt when 256 edges have been detected. This value of 256 is set by a #define in the code so can be easily modified if required. This interrupt sets a software flag which is detected by the main processing loop and the state of LED1 on the S7G2_SK is toggled.
For testing, I have configured GPT11 to generate a 300kHz output. You can connect P5.0 (GPT11 output) to P5.12 (GPT0 input). The push buttons S4 and S5 will increase / decrease the GPT11 period / frequency.
You can set a real time watch on the variable g_1s_photon_count and see that this does vary with the frequency of GPT11.
Hope this helps and points you in the correct direction for your application