The processor is running with a processor clock of 100MHz.
I only have the following GPIO pins available for use:
P0.2, P0.3, P0.23, P0.24, P0.25 and P0.26
I tried to use a timer interrupt to generate a 5MHz clock signal, but AFAICT there just aren't enough processor cycles available to handle a timer interrupt every 10 clocks (which makes sense) and I only achieved a 1MHz signal out and there were probably not many processor cycles available to do any other work!
Is there a neat way to get a 5MHz clock out those pins using hardware to toggle it (perhaps using one of the peripherals)? Ideally I'd like to use P0.23 and P0.26 for the clock signal (but not both at the same time).
Thanks, David
I've done this the old fashioned way by bit-banging the clock and data at a lower rate (1MHz) which the receiving device can handle and I can generate. Thanks,David
Please remember
I only have the following GPIO pins available for use:
P0.2, P0.3, P0.23, P0.24, P0.25 and P0.26
Hello @perdrix
For match function, there is External Match Output pins, while not for those pins(P0.2, P0.3, P0.23, P0.24, P0.25 and P0.26).
For you those pins, I think only can use timer interrupt to control GPIO.
BR
Alice
Maybe because I didn't quite understand how that works!
Remember that for a 5MHz clock on a GPIO port that needs to be toggled every 100ns or every ten processor cycles. If by using the match registers I can do that w/o consuming processor cycles, I am all ears!!!
Please could you help me with some example code.
The code I used looked like:
void TIMER1_IRQHandler (void)
{
if((LPC_TIM1->IR & 0x01) == 0x01) // if MR0 interrupt
{
LPC_TIM1->IR |= (1 << 0); // Clear MR1 interrupt flag
if (enablePGC)
{
LPC_GPIO0->FIOPIN ^= PGC; // Toggle PGC (programming clock)
}
else LPC_GPIO0->FIOPIN &= ~(PGC);// Force PGC low
}
}
LPC_SC->PCONP |= 1 << 1; // Power up Timer 1
LPC_SC->PCONP |= 1 << 22; // Power up Timer 2
LPC_SC->PCLKSEL0 |= 1 << 4; // Clock for Timer 1 = CCLK
LPC_SC->PCLKSEL1 |= 1 << 12; // Clock for Timer 2 = CCLK
LPC_TIM1->MR0 = 10; // 5MHz
LPC_TIM1->MCR |= (1 << 0) | (1 << 1); // Interrupt and Reset on MR0
// Reset Timers 1 and 2
LPC_TIM1->TCR = 0x02;
LPC_TIM1->TCR = 0x00;
LPC_TIM2->TCR = 0x02;
LPC_TIM2->TCR = 0x00;
// Clear pending interrupts for Timer 1 and enable timer interrupts
NVIC_ClearPendingIRQ(TIMER1_IRQn);
NVIC_EnableIRQ(TIMER1_IRQn); // Enable timer interrupt
LPC_TIM1->TCR |= 1 << 0; // Start timer 1
If you could show me how to do that using the match stuff I'd be most grateful - I got quite confused reading about EMR and MAT0.n registers
Woohoo! I think I got Match working:
I user Timer0 and MR1, setting up as follows:
LPC_PINCON->PINSEL7 = (2<<20); // P3.26 becomes MAT0.1
LPC_PINCON->PINMODE7 |= (2 << 20); // Pin 3.26 == MAT0.1 no pull or pull down
LPC_SC->PCONP |= 1 << 1; // Power up Timer 1
LPC_SC->PCLKSEL0 |= 1 << 2; // Clock for Timer 0 = CCLK
LPC_TIM0->MR1 = 9; // Approx 100ns
LPC_TIM0->MCR = (1 << 4); // Reset on MR1 (no interrupt)
LPC_TIM0->EMR = (1 << 1) | (3<<6); // Drive MAT0.1
// Reset Timer 1
LPC_TIM0->TCR = 0x02;
LPC_TIM0->TCR = 0x00;
LPC_TIM0->TCR |= 1 << 0; // Start timer 1
The only odd things are:
Can you clarify those issues for me please?
Thanks, David
Hmmm I generate the clock signal, but how do I clock data out using that clock? Maybe I need to rethink to use one of the peripherals
David