Posted: 05:26am 07 Sep 2022 |
|
|
|
Might be talking out of my posterior but I suspect there might be PEEK/POKE tricks(?)
This is from ByPic. A prescale of 256 gives a resolution of 6.4uS. Looks like it can do way better.
// Timer projects // #option echo off #option only on // only load functions that don't already exists // include all of the registers although only some are needed #include "http://byvac.com/mBlib/flb/Library/PIC32MX1_Family/BRegisters/MX1_reg_ timer.bas" // interrupts hold the flag addresses #include "http://byvac.com/mBlib/flb/Library/PIC32MX1_Family/BRegisters/MX1_reg_ interrupt.bas" constant TIMERON 1 << 15 // on bit constant T3IF 1 << 14 // *********************************************************************** ****** // clocked with PCLK that is running at 40MHz, prescale 256 = 156.25kHz (6.4uS) // setting PR2 1/6.4uS = 156250 should see the counter reset every second so // using 1562500 is 10 seconds. // *********************************************************************** ****** function t23_set() @TMR2=0 // clear counter // timer_on | prescale_256 | 32_bit_on | Internal_clock @T2CON = 0x8078 @PR2=1562500 endf // just to look at timer values function t23_test() t23_set() while comkey?(2) = 0 if (peek(IFS0) & T3IF) = T3IF print "\n Flag triggered" @IFS0CLR = T3IF // must clear flag endif wend endf
Craig |