Go Down

Topic: strange timer problem (Read 787 times) previous topic - next topic

KamilP

Hey people,

I have a problem and I'm getting desperate.
Let me first explain what I want to do:

I've connected an external clock to Timer 0, Channel 0. Its running in the RC Compare mode.
also, I set the TIOA0 Pin as an output.

The goal is to realize a frequency divider. The value I write in RC should be the divider-value.
So what I should get at the TIOA0 Pin is the Input-frequency * RC-value.
When I watch both Signals on the oscilloscope I see that the Signal at the TIOA0 Pin is bouncing and I get different results.
Its bouncing between the right result  (input-frequency * RC-value) and (input-frequency*RC-value - 1).
Also, the whole program doesn't work any more for frequencies lower than 300Hz.

If there are any questions, feel free to ask, any help would be great

Code: [Select]

int ulPin = 2;
int freqTeiler = 2;

void externClockSetup() {

  uint32_t xc_tclk, tcclk_xc;

  pmc_set_writeprotect(false);
  pmc_enable_periph_clk((uint32_t)TC0_IRQn);

  xc_tclk = TC_BMR_TC0XC0S_TCLK0;
  tcclk_xc = TC_CMR_TCCLKS_XC0;

  TC0->TC_BMR |= xc_tclk;

  TC_Configure(TC0, 0, tcclk_xc | TC_CMR_WAVE | TC_CMR_BURST_NONE | TC_CMR_WAVSEL_UP_RC | TC_CMR_ACPC_TOGGLE);// | TC_CMR_CPCSTOP);// | TC_CMR_CPCDIS);

  TC_SetRC(TC0, 0, freqTeiler);
  TC_Start(TC0, 0);
 
}


void setup() {

  Serial.begin(9600);
  Serial.setTimeout(100);
  pinMode(PIO_PB26, INPUT);
  pinMode(57, INPUT);
 
  PIO_Configure(g_APinDescription[ulPin].pPort,
    g_APinDescription[ulPin].ulPinType,
    g_APinDescription[ulPin].ulPin,
    g_APinDescription[ulPin].ulPinConfiguration);

  externClockSetup();
}


void loop() {
}




Go Up