Hi I’m a beginner.
I’m trying to set up a timer/counter to count an external clock input from MTIOA2, which is on pad PB27.
Here are the settings I have for the pad:
*AT91C_PMC_PCER = BIT1|BIT2|BIT3BIT12|BIT13|BIT14; // Clock power settings
*AT91C_PIOB_PER = (AT91C_PIO_PB27); //MTIOA2 PIO enable register
*AT91C_PIOB_ODR = (AT91C_PIO_PB27); //MTIOA 2 output disable register
*AT91C_PIOB_PPUDR = (AT91C_PIO_PB27); //MTIOA2 pull up disable
Here are the settings I have for the timer/counter:
*AT91C_TCB_BMR = BIT0|BIT1|BIT2|BIT3|BIT5; //XC0 is set to TIOA2, XC1, and XC2 are set to no external clock
*AT91C_TC0_CMR = BIT0|BIT2; // Set TC0 to use XC0 as a clock
*AT91C_TC0_IDR = 0xFF; // disable all timer interrupts
*AT91C_TC0_CCR = BIT2|BIT0; // Reset and enable clock
Here’s the code I’m using for testing that the counter is incrementing.
if((*AT91C_TC0_CV)>1){ //check if the counter is greater than one
display(0,1,1,0);
}
if((*AT91C_TC0_SR&BIT0)==BIT0){ //check if the overflow bit is high
display(1,0,0,1);
}
I’m inputting a square wave using a function generator, and I’ve used “*AT91C_PIOB_PDSR&AT91C_PIO_PB27==BIT27” to test the input value, and it looks like it’s staying high rather than fluctuating.
Thanks, any help is appreciated.