Hi Bob and Ian,
I have used asynchronous mode and TMR1 to measure frequency and duty cycle in the past. My initial post here was more simple than that. I just didn't understand the "Microchiplish" of that comment.
As for my project per se, namely using various command modes to control the tuning and operation of the AS3935 device, this particular aspect is just 1 of the 16 modes that I have chosen to implement. In fact, there are four frequency measurement modes for different oscillators, so whatever solution there is for this one will probably work for the other three. I have the other 12 modes pretty much nailed down.
For some reason, AMS requires that the antenna resonance be tuned to ±3.5% of the target frequency of 500 kHz. As default, it outputs that frequency divided by 16 on the INT pin of the chip. One can pick other binary divisors up to 128. So, the target frequency on that pin can be set to 31.250 kHz ( 32 us period) to 3.9 kHz (256 us period). With my MCU at 32 MHz, that leaves me 256 to 2048 Tcy per cycle for housekeeping and math. It is not really high speed. Rather than using TMR0 as a prescale, I can effectively just set to chip to 1:128 as my prescale and use TMR1 directly. However, as for most of my projects, I do have a purpose, but the main reason for pursuing them is the challenge of getting something new to work.
Now, back to using TMR0 to gate TMR1...
The simplest approach is to use the rollover to start and stop TMR1 to get the period and frequency. But, I want to be more elegant than that, if possible. Using capture directly with TMR1 is another option, and I have have used that quite a bit in other projects. It is Plan B.
My initial idea here was to use the overflow pulse from TMR0 to create a capture-like event while allowing TMR1 to run continuously or be gated by hardware. My interpretation of TMR1 timing is that the rollover event should be no different than any other event as T1G_IN is a common path:
Initially, I was attracted to using the "toggle mode" or the "single-pulse and toggle combined mode," described below:
I have been unable to get either to work in simulation with MPLab SIM. In my very limited experience, namely with the 12F1840 and 16F1519 chips, I found that MPLab SIM simulation worked with the 16F1519 for capture, but not with the 12F1840. So, I am beginning to wonder whether the problem in simulation may be a function of that debugger.
My current plan is to strip the program to just this part,remove the AS3935 module (Out of an abundance of caution, I don't want to apply an external signal to its INT pin.) and proceed with hardware debugging. Failing at that, I will just use the capture mode and TMR1 alone.
Any advice on getting either of the two modes just mentioned to work using the TMR0 overflow signal would be greatly appreciated.
Regards, John
EDIT: 11:56 AM local Set up hardware simulation (signal generator + ICD3). Have only tested the single-pulse and toggle combined mode. Works as expected with input to TMR0. That is, on first rollover of TMR0, TMR1 starts and on second rollover, it stops. Monitored both TMR0 and polled T1GVAL.
Using MPLab SIM I got nothing. For example, T1GVAL never changed.