fast delay question 3.6

Status
Not open for further replies.

hanz

Member
dear reader,

Using a Teensy 3.6.
For a a project I need to have a very short delay shorter then 1µs should be near 0.05µS (followed by a interrupt).
Is it possible?

I checked out :

https://github.com/PaulStoffregen/FreqCount

But this is driven by an external clock( the freq to measure) Can I some how set the LPTMR_CSR, PSR, CMR, CNR and / or the MCG_IRCLK to use an internal clock to make a fast delay?

Thanks hanz




from the headerfile:
static inline void counter_init(void)

{

SIM_SCGC5 |= SIM_SCGC5_LPTIMER;

LPTMR0_CSR = 0;

LPTMR0_PSR = 0b00000100; // bypass prescaler/filter

LPTMR0_CMR = 0xFFFF;

LPTMR0_CSR = 0b00100110; // counter, input=alt2, free running mode

CORE_PIN13_CONFIG = PORT_PCR_MUX(3);

}
 
Perhaps use a PIT timer in one-shot mode? If F_BUS is 60MHz on a Teensy 3.6 @180MHz, letting it count to 3 would give 0.05uS before launching an interrupt.
 
Beware. If you are trying to continuously interrupt at a 20mhz rate, you won't succeed. Depending on what you are doing in your ISR, you typically can't expect more than a 1 to 3 mhz interrupt rate.

also consider https://forum.pjrc.com/threads/29105-Sub-Micro-Second-Pulses

here is a sketch toggling pin 12 in the isr
Code:
// PIT timer ISR toggle pin 12, use scope or analyzer
//https://forum.pjrc.com/threads/42643-Timer-1-cycle-problems?p=136712&viewfull=1#post136712

const uint8_t out_pin = 12;
#define OUT_PIN_PTOR GPIOC_PTOR
#define OUT_PIN_BMASK CORE_PIN12_BITMASK

void setup() {
  pinMode(out_pin, OUTPUT);

  SIM_SCGC6 |= SIM_SCGC6_PIT;
  __asm__ volatile("nop");   //timing problem on T3.5
  PIT_MCR = 0x00;
  NVIC_ENABLE_IRQ(IRQ_PIT_CH1);
  PIT_LDVAL1 = 1; // count to 1
  PIT_TCTRL1 |= 0x00000003; // enable Timer 1 interrupts (TIE = 1) & start Timer 1 (TEN = 0)
}

void pit1_isr(void) {
  PIT_TFLG1 = 1;  // clear interrupt  first
  OUT_PIN_PTOR = OUT_PIN_BMASK;
}

void loop() {}
On T3.6, scope shows pin changing every 200 ns, with LDVAL of 1
Reference: https://forum.pjrc.com/threads/42643-Timer-1-cycle-problems
 
Last edited:
Status
Not open for further replies.
Back
Top