Go Down

Topic: HELP to increase clock frequency of DUE (Read 141 times) previous topic - next topic

TYTY

I just start working with DUE, and I want to generate pulses whose width is about 0.2us. Therefore I want to change the registers to increase clock frequency, like PMC_WPMR(write protection register),but here is the problem...'PMC_WPMR' was not declared in this scope.....

Could anyone tell me how to increase clock frequency?

By the way, i tried to write high and then low to a pin,

digitalWrite(WritePin,HIGH);
digitalWrite(WritePin,LOW);

but the output signal width is about 2.5us, isn't that the default clock 4MHz? Why the output frequency is so low..... :(  :(  :(

PaulS

Quote
'PMC_WPMR' was not declared in this scope.....
What scope would that be?

Quote
but the output signal width is about 2.5us, isn't that the default clock 4MHz? Why the output frequency is so low
Because a lot goes on in digitalWrite() to figure out which physical pin on which port on the real hardware to set.

TYTY

Shoud I include any libary to change registers in DUE, or is there any functions to directly change frequency?

arduinocode:58: error: 'PMC_WPMR' was not declared in this scope
'PMC_WPMR' was not declared in this scope


If I could increase frequecy to 84MHz, would it be possible to generate 0.2us pulses without assembly language, since digitalWriteFast cannot apply to DUE....

MarkT

As far as I know none of the write-protection stuff is used at all on the Due,
all hardware is unprotected.

Which clock are you trying to alter?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

TYTY

I am trying to increase processor clock frequency to the highest, because I want to get an output with very narrow pulse width.

DrAzzy

#5
Jun 05, 2015, 06:30 pm Last Edit: Jun 05, 2015, 06:37 pm by DrAzzy
2.5us pulse width is not unreasonable on the Due at 84mhz - it's ~210 clock cycles (iirc it's 50-something clock cycles on the uno, but that's a much simpler chip). digitalWrite() is not particularly efficient, because it has to look up the registers. The Due has a lot of pins, so it's got more work to do than on an Uno.

If you need a very narrow pulse, use direct port manipulation to generate it.

Magician

You can configure one of timers to drive a pin, minimum 1/42 MHz - about 25 nsec, with 25 nsec resolution, setting TC_RA = 8 gives close to your spec. 200 nsec.

Code: [Select]
#define   SMP_RATE           8000UL
#define   CLK_MAIN       84000000UL
#define   TMR_CNTR       CLK_MAIN / (2 *SMP_RATE)


void setup()
{
  Serial.begin (115200) ;
  tmr_setup ();         
  pio_TIOA0 ();  // drive Arduino pin 2 at 48kHz to bring clock out
}

void pio_TIOA0 ()  // Configure Ard pin 2 as output from TC0 channel A (copy of trigger event)
{
  PIOB->PIO_PDR = PIO_PB25B_TIOA0 ;  // disable PIO control
  PIOB->PIO_IDR = PIO_PB25B_TIOA0 ;   // disable PIO interrupts
  PIOB->PIO_ABSR |= PIO_PB25B_TIOA0 ;  // switch to B peripheral
}
 
void tmr_setup ()
{
  pmc_enable_periph_clk (TC_INTERFACE_ID + 0 *3 + 0) ;  // clock the TC0 channel 0

  TcChannel * t = &(TC0->TC_CHANNEL)[0] ;    // pointer to TC0 registers for its channel 0
  t->TC_CCR = TC_CCR_CLKDIS ;  // disable internal clocking while setup regs
  t->TC_IDR = 0xFFFFFFFF ;     // disable interrupts
  t->TC_SR ;                   // read int status reg to clear pending
  t->TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 |   // use TCLK1 (prescale by 2, = 42MHz)
              TC_CMR_WAVE |                  // waveform mode
              TC_CMR_WAVSEL_UP_RC |          // count-up PWM using RC as threshold
              TC_CMR_EEVT_XC0 |     // Set external events from XC0 (this setup TIOB as output)
              TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_CLEAR |
              TC_CMR_BCPB_CLEAR | TC_CMR_BCPC_CLEAR ;
 
  t->TC_RC = TMR_CNTR;
  t->TC_RA = TMR_CNTR /2;
  t->TC_CMR = (t->TC_CMR & 0xFFF0FFFF) | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET ;  // set clear and set from RA and RC compares
  t->TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG ;  // re-enable local clocking and switch to hardware trigger source. 
}


Go Up