Nothing in particular - just that that it would rollover and be confusing. I was perhaps conflating it with micros rolling in ~87 secs where it was used for longer as a reference.
Also the quick look I gave to the elapsedus code didn't turn out right - given everything coming or going needs to be handled with 1/F_CPU_ACTUAL in the proper fashion. Having a steady 1 MHz value to feed it would make it fit in less code and run faster. The T_3.x version of elapsedus and micros goes to some effort to resolve/round the current value - running overhead extra code.
Mike, does NeoPixel modifiy the CycleCounter or just start and use it as a running value? <edit> seems to have two places it starts it and then just reads it for it's value. Though it uses F_CPU for resolution that will be wrong.
Thanks. you need to go deeper to find hardware timer that is being used. For example, IntervalTimer uses PIT (maybe all 4 channels), PWM uses some channels of QTIMER and flexPWM timer, IRremote uses flexPWM1 timer, FreqMeasure uses FLEXPWM4...
uint32_t ccmicros(void)
{
uint32_t ccdelta = ARM_DWT_CYCCNT, usec;
ccdelta -= systick_cycle_count;
usec = 1000*systick_millis_count + (ccdelta/(F_CPU_ACTUAL/1000000));
return usec;
}
extern "C" void systick_isr(void)
{
[B] systick_cycle_count += F_CPU_ACTUAL/1000;[/B]
systick_millis_count++;
MillisTimer::runFromTimer();
}
uint32_t micros(void)
{
uint32_t msec, tick, elapsed, istatus, usec;
static uint32_t prev_usec=0;
static int doprint=180;
__disable_irq();
tick = SYST_CVR;
msec = systick_millis_count;
istatus = SCB_ICSR; // bit 26 indicates if systick exception pending
#ifndef SYSTICK_EXT_FREQ
const uint32_t fcpu = F_CPU;
#endif
__enable_irq();
istatus &= SCB_ICSR_PENDSTSET;
#ifdef SYSTICK_EXT_FREQ
if ((istatus & SCB_ICSR_PENDSTSET) && (tick == 0 || tick > (SYSTICK_EXT_FREQ / 2000))) {
#else
if ((istatus & SCB_ICSR_PENDSTSET) && (tick == 0 || tick > (fcpu / 2000))) {
#endif
msec++;
}
#if defined(SYSTICK_EXT_FREQ) && SYSTICK_EXT_FREQ <= 1000000
elapsed = (SYSTICK_EXT_FREQ / 1000) - tick;
if (tick == 0) elapsed = 0;
usec = msec * 1000 + elapsed * (1000000 / SYSTICK_EXT_FREQ);
#elif defined(SYSTICK_EXT_FREQ) && SYSTICK_EXT_FREQ > 1000000
elapsed = (SYSTICK_EXT_FREQ / 1000) - tick;
if (tick == 0) elapsed = 0;
usec = msec * 1000 + elapsed / (SYSTICK_EXT_FREQ / 1000000);
#else
elapsed = (fcpu / 1000) - tick;
if (tick == 0) elapsed = 0;
usec = msec * 1000 + elapsed / (fcpu / 1000000);
#endif
if (usec < prev_usec && doprint) {
if (doprint > 0) doprint--;
}
prev_usec = usec;
return usec;
}
base rtc ticks=: 471
micros: 471617000 // base times before ALL test groups
ccmicros: 471617026
millis: 471617
micros: 471620330 // base times after ALL test groups
ccmicros: 471620343
millis: 471620
// This group updates 60,000 cpu cycles apart or 0.1 ms
471617105 471617205 471617305 471617405 471617505 471617605 471617705 471617805 471617905 471618005
471618105 471618205 471618305 471618405 471618505 471618605 471618705 471618805 471618905 471619005
471619105 471619205 471619305 471619405 471619505 471619605 471619705 471619805 471619905 471620005
// This group updates 6000 cpu cycles apart or 0.01 ms
471620015 471620025 471620035 471620045 471620055 471620065 471620075 471620085 471620095 471620105
471620115 471620125 471620136 471620146 471620156 471620166 471620176 471620186 471620196 471620206
471620216 471620226 471620236 471620246 471620256 471620266 471620276 471620286 471620296 471620306
// This group updates 600 cpu cycles apart or 0.001 ms
471620307 471620308 471620309 471620310 471620311 471620312 471620313 471620314 471620315 471620316
471620317 471620318 471620319 471620320 471620321 471620322 471620323 471620324 471620325 471620326
471620327 471620328 471620329 471620330 471620331 471620332 471620333 471620334 471620335 471620336
// pad config registers control pullup/pulldown/keeper, drive strength, etc
#define CORE_PIN0_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_02
#define CORE_PIN1_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_03
// pad config registers control pullup/pulldown/keeper, drive strength, etc
#define CORE_PIN0_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_03
#define CORE_PIN1_PADCONFIG IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B0_02
seems to fix the inversion problem with pins 0 and 1 (and presumably with pins 24 and 25).
I started this so I willing to play along You might want to check out TXCOUNT and maybe tx watermark? Maybe one of these will help.Let me know if anyone wishes to play along, and I could update my GITHUB projects with this WIP
000 ALT0 — Select mux mode: ALT0 mux port: FLEXCAN2_RX of instance: flexcan2
001 ALT1 — Select mux mode: ALT1 mux port: XBAR1_INOUT17 of instance: xbar1
010 ALT2 — Select mux mode: ALT2 mux port: LPUART6_RX of instance: lpuart6
IOMUXC_FLEXCAN2_RX_SELECT_INPUT for Flexcan
xbar_connect (saw this in pwm.c)
Yep - Still WIP - But I pushed up T4_WIP branches for my SPIN and ili9341_t3n github projects...
Will be busy with some other stuff this morning... Will play more later. Also want to move some of my CS pin hacks out of the ILI9341_t3n library and put into SPI library update. That is define pin 10 is pinIsChipSelect in hardware table and to have the setCS put the pin into SPI mode...
i.e. let SPI do the normal SPI stuff here...
Problem(?) - not sure if it is..
I replaced set_arm_clock(600000000); with set_arm_clock(12000000); (12MHz) - teensy ist still fast but that is not the problem
If I use this, the T4 blinks slowly (orange LED) after upload, and I have to press the button.
Tim,@Frank: Was the set_arm_clock(12000000) in the active sketch before upload? So the T4 is not doing a restart after the upload? Is that because USB is offline at 12 MHz?
I refined my [cc]micros() using ARM_DWT_CYCCNT and it is working with noInterrupts(). It takes about 19% longer and the codeline added to systick_isr() - is that better than wasting a GPT timer to work around the slow systick driven clock?
Current test running is on the way to us wrap - currently at 2,857,980,987 with 1024 * 2748000 successful tests of 1us update … then I'll try one more edit without int disable - my _isr occurred test correction was faulty.
Yes it was active, and USB is online.. so I don't know the reason.@Frank: Was the set_arm_clock(12000000) in the active sketch before upload? So the T4 is not doing a restart after the upload? Is that because USB is offline at 12 MHz?
Good job! That's fine in my opinion Does the code disable interrupts? If yes, is there a way without it?I refined my [cc]micros() using ARM_DWT_CYCCNT and it is working with noInterrupts(). It takes about 19% longer and the codeline added to systick_isr() - is that better than wasting a GPT timer to work around the slow systick driven clock?
Tim,
Meant to say it last night, but, great work on the microsecond timer, hope it gets incorporated.
...
........................................ #1024's=4116000 @ccus=4279366619 <> us=4279366610
........................................ #1024's=4120000 @ccus=4283522713 <> us=4283522710
........................................ #1024's=4124000 @ccus=4287678817 <> us=4287678810
........................................ #1024's=4128000 @ccus=4291834926 <> us=4291834920
........................................ #1024's=4132000 @ccus=1023739 <> us=1023734
........................................ #1024's=4136000 @ccus=5179837 <> us=5179834
........................................ #1024's=4140000 @ccus=9335940 <> us=9335934
........................................ #1024's=4144000 @ccus=13492033 <> us=13492024
........................................ #1024's=4148000 @ccus=17648127 <> us=17648124
........................................ #1024's=4152000 @ccus=21804225 <> us=21804224
........................................ #1024's=4156000 @ccus=25960333 <> us=25960324
........................................ #1024's=4160000 @ccus=30116431 <> us=30116424
........................................ #1024's=4164000 @ccus=34272524 <> us=34272524
........................................ #1024's=4168000 @ccus=38428632 <> us=38428624
........................................ #1024's=4172000 @ccus=42584735 <> us=42584734
........................................ #1024's=4176000 @ccus=46740843 <> us=46740834
........................................ #1024's=4180000 @ccus=50896951 <> us=50896944
........................................ #1024's=4184000 @ccus=55053054 <> us=55053054
........................................ #1024's=4188000 @ccus=59209152 <> us=59209144
........................................ #1024's=4192000 @ccus=63365245 <> us=63365244
........................................ #1024's=4196000 @ccus=67521343 <> us=67521334
........................................ #1024's=4200000 @ccus=71677441 <> us=71677434
........................................ #1024's=4204000 @ccus=75833534 <> us=75833534
........................................ #1024's=4208000 @ccus=79989627 <> us=79989624
........................................ #1024's=4212000 @ccus=84145735 <> us=84145734
........................................ #1024's=4216000 @ccus=88301838 <> us=88301834
........................................ #1024's=4220000 @ccus=92457931 <> us=92457924
........................................ #1024's=4224000 @ccus=96614029 <> us=96614024
........................................ #1024's=4228000 @ccus=100770122 <> us=100770114
........................................ #1024's=4232000 @ccus=104926227 <> us=104926224
........................................ #1024's=4236000 @ccus=109082325 <> us=109082324
........................................ #1024's=4240000 @ccus=113238424 <> us=113238424
50K micros: 1647897
50K ccmicros: 1950699
50K micros: 1597772
50K ccmicros: 1601041
... #1024's=2336000 @ccus=2447826438 <> us=2447826430
uint32_t ccmicros(void)
{
uint32_t ccdelta, usec, smc, smc2;
do {
smc = systick_millis_count;
ccdelta = ARM_DWT_CYCCNT;
ccdelta -= systick_cycle_count;
smc2 = systick_millis_count;
} while ( smc != smc2 );
usec = 1000*smc + (ccdelta/(F_CPU_ACTUAL/1000000));
return usec;
}
static void systick_isr_sync(void)
{
systick_cycle_count = ARM_DWT_CYCCNT;
systick_millis_count++;
if ( 2 == systick_millis_count )
[B] _VectorsRam[15] = systick_isr;
[/B]}
static void configure_systick(void)
{
_VectorsRam[14] = pendablesrvreq_isr;
[B]_VectorsRam[15] = systick_isr_sync;[/B]
SYST_RVR = (SYSTICK_EXT_FREQ / 1000) - 1;
SYST_CVR = 0;
SYST_CSR = SYST_CSR_TICKINT | SYST_CSR_ENABLE;
SCB_SHPR3 = 0x20000000; // Systick = priority 32
ARM_DEMCR |= ARM_DEMCR_TRCENA;
ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; // turn on cycle counter
systick_cycle_count = ARM_DWT_CYCCNT;
}
extern "C" void systick_isr(void)
{
[B]systick_cycle_count += F_CPU_ACTUAL/1000;[/B]
systick_millis_count++;
MillisTimer::runFromTimer();
}
uint8_t buf[] = {0, 1};
SPI.transfer(buf, NULL, sizeof(buf));
........................................ #1024's=4108000 @ccus=4288978220 <> us=4288978220
........................................ #1024's=4112000 @ccus=4293134314 <> us=4293134310
........................................ #1024's=4116000 @ccus=2323112 <> us=2323104
........................................ #1024's=4120000 @ccus=6479219 <> us=6479214
........................................ #1024's=4124000 @ccus=10635321 <> us=10635314
........................................ #1024's=4128000 @ccus=14791424 <> us=14791424
50K micros: 1657928
50K ccmicros: 1650100
50K micros: 1657870
50K ccmicros: 1650285
50K micros: 1657862
50K ccmicros: 1651132
50K micros: 1657872
50K ccmicros: 1650306
50K micros: 1657854
50K ccmicros: 1652015
50K micros: 1657862
50K ccmicros: 1650303
50K micros: 1657855
50K ccmicros: 1653517
50K micros: 1657869
50K ccmicros: 1650305
50K micros: 1657855
50K ccmicros: 1655375
50K micros: 1657866
50K ccmicros: 1650303
Now the hardest part … jousting with GitHub to get a Pull request entered ...
Tim u got that right:
...
T:\arduino-1.8.8T4_146\hardware\teensy\avr\cores\teensy4\IntervalTimer.cpp:38:119: error: expected ',' or ';' before '__attribute'
static void (*funct_table[4])(void) __attribute((aligned(32))) = {dummy_funct, dummy_funct, dummy_funct, dummy_funct} __attribute((aligned(32)));
^
TimAnd tempmon_init broke my build after copying merged files - so I got current core Teensy4 - now I'm stuck on this. Is this a bug in github CORE files or something out of sync on my end?
ILI9341 Test!
SPI MISO: 12 MOSI: 11, SCK: 13
Display Power Mode: 0x94
MADCTL Mode: 0x48
Pixel Format: 0x5
Image Format: 0x80
Self Diagnostic: 0xC0
Benchmark Time (microseconds)
Screen fill 993370
Text 49080
Lines 465640
Horiz/Vert Lines 81250
Rectangles (outline) 51720
Rectangles (filled) 2061730
Circles (filled) 288390
Circles (outline) 203800
Triangles (outline) 106080
Triangles (filled) 670390
Rounded rects (outline) 97400
Rounded rects (filled) 2241290
Done!
LI9341 Test!
SPI MISO: 12 MOSI: 11, SCK: 13
After TFT Begin
13
Display Power Mode: 0x10
MADCTL Mode: 0x10
Pixel Format: 0x10
Image Format: 0x10
Self Diagnostic: 0x10
Benchmark Time (microseconds)
Screen fill 244740
Text 10920
Lines 68330
Horiz/Vert Lines 20010
Rectangles (outline) 12780
Rectangles (filled) 502180
Circles (filled) 73360
Circles (outline) 62200
Triangles (outline) 16330
Triangles (filled) 166190
Rounded rects (outline) 27460
Rounded rects (filled) 547750
Hit key to continue
T:\arduino-1.8.8T4_146\hardware\teensy\avr\cores\teensy4\IntervalTimer.cpp:38:119: error: expected ',' or ';' before '__attribute'
static void (*funct_table[4])(void) __attribute((aligned(32))) = {dummy_funct, dummy_funct, dummy_funct, dummy_funct} __attribute((aligned(32)));