Changing CPU Clock speed of Adafruit Feather

I have a program I wrote for an Arduino Uno (16MHZ) that I would like to implement on my feather (48MHZ), but I haven't been able to find a way to change the CPU clock speed. Is this something that can be done through any general software commands?

Why do you want to change the clock speed?

1 Like

Why do you think you need to change the CPU clock speed?

They are completely different CPUs (AVR and ARM Cortex-M0) - so there is no direct relation between the clock speeds.

It would make implementation of my previous code easier. It involves lots of timers and interrupts. I would have to redo all the register commands that I had done because of the higher clock frequency. The register prescalar values wont work with 48MHZ as opposed to 16MHZ.

If there is an easier way of going about this issue that you can think of, I am also all ears.

All the timers are different on those processors. Nothing intended for specific Arduino Uno hardware will work on the Feather.

For informed advice, post the code, using code tags.

1 Like

Here is all my code for the portions that have to do with the timers. Hopefully this is the right format to post if not sorry for inconvenience I'm new. Basically I'm wondering if the best way to go about this would just be to restart this portion of the code with the 48MHZ CPU frequency in mind.

 //setup timer1 to FASTPWM on pin 10
  TCCR1A=0B00100011;
  TCCR1B=0B00011001;
}

//perform measurement of delay of the trailing edge
long int meas(int period, int minlen, int maxlen, int steplen, int nloop){
  long int sum=0;
  int nmiss=0;
  OCR1A=period;        //set the period
  TIFR1 |= 0B00000001; //clear the timer overflow bit
  for(int iloop=0; iloop<nloop; iloop++){
    for (int len=minlen; len<maxlen; len+=steplen){
      OCR1B=len;                         //set the pulselength
      while ((TIFR1 & 0B00000001) == 0); //wait for timer overflow
      TIFR1 |= 0B00000001;               //clear the timer overflow bit
      while (TCNT1<(period-cycles));     //wait till pulse is almost finished
      if( (TIFR1&0B00100000) !=0){       //check if trailing edge has been detected
        sum+=(ICR1-len);  
        TIFR1 |= 0B00100000;             //clear the input capture flag
      } else {
        nmiss++;
      }
      //update phase
      phase+=absdiff;
      //blink and click when phase rolls through
      if(phase>phasemax){
        phase-=phasemax;
        LEDcycle=LEDcycles;
        PORTB=(PORTB|0B00100000); //switch on LED
        PORTB=(PORTB^0B00010000); //invert sound pin - click!
      }
      //switch off LED when it's been on long enough
      if(LEDcycle>0){
        LEDcycle--;
        if(LEDcycle==0)PORTB=(PORTB&(!0B00100000));
      }  
    }
  }
  if (nmiss>0)sum=0; //invalidate the result if there have been missing pulses
  return sum;
}

They are completely different chips, with completely different timers & completely different registers - you will have to redo them all anyhow!

That code must be completely rewritten for the Feather. You will need to study the data sheet of the Feather to see what is possible and how to go about it.

There are ways of making the measurement that are not hardware specific.

2 Likes

Sounds good, thanks.

Again, it's not just the clock frequency that's different - that's the least of your worries!

The entire timer hardware is completely different - the code is just not portable at all.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.