4 ms·
Since the author cares about a few cycles per check by using the interrupt instead of directly reading the PWM register, they should look up how to access the c
by kevin_b_er 10y ago
Since the author cares about a few cycles per check by using the interrupt instead of directly reading the PWM register, they should look up how to access the constants table (4.4.1.1).
The compiler can be coaxed, with some rather ridiculous clpru compiler-specific variable definitions, into referencing addresses from the constant table by a C number rather than loading up a general purpose register.
It is in the clpru compiler documentation under section 5.14.4
It is also discussed in some TI slides (flash required) in part 18
http://software-dl.ti.com/public/hpmp/software/pru_compiler_tips_tricks/index.html http://software-dl.ti.com/public/hpmp/software/pru_compiler_...
PDF slides: http://software-dl.ti.com/public/hpmp/software/pru_compiler_tips_tricks/presentation_content/external_files/PRU_Compiler_Tips_slides.pdf http://software-dl.ti.com/public/hpmp/software/pru_compiler_... (PDF page 28)
TI states in their slides that this constant register table access "Barely counts as C code." I think they're right. It is, however, slightly faster. When trying to do cycle-perfect timing, such micro optimizations start to actually matter.
- kens 10y agoThanks for mentioning the constants table. In my case, saving a few cycles isn't important but eliminating jitter is very important, which is why I use interrupts. Reading the PWM register took 5 cycles, so I ended up with 25 nanoseconds of jitter, which caused bit errors in my Alto Ethernet emulator. Polling interrupts take 1 cycle, so I end up with no jitter. (Does anyone else think it's bizarre that TI calls them "interrupts" when you need to poll them?) You might think 1 cycle would cause 5 ns jitter, but the timer uses the same clock so everything is synchronized. I considered using the constants table if I needed to shave off some cycles, but as you point out the code required is pretty hideous. And you also need to define all the constants in the linker file too? That's just crazy.