Missing interrupt functions and no access to Timer Prescaler registers

Hi,

I was previously using a Mega 2560 for a guitar-related project and was using both interrupts for a capacitive sensor and also modified the PWM frequency to push it into a higher non-audible band. However my code no longer compiles for the GIGA.

The compiler has issues with the sei() function and cli() function, so is the enabling and disabling of interrupts no longer needed?

I was also using a third party library for the MEGA to modify the timer registers for prescalers to get higher PWM frequencies. How does one change the PWM frequency on a GIGA board?

Thank for any help anyone can give.

BR
Paul

sei() and cli() are specific to the AVR platform. The recommended API is interrupts() and noInterrupts() which are portable across any platform thus work on both MEGA and GIGA.

To answer the rest of your question, it would be useful if you could post your code, compilation errors and a link to the third-party library you have been using on the MEGA.

Hi, thanks for the quick response. I was using the PWM library by Sam Knight. I use the PWM outputs to drive Vactrols to simulate potentiometers.

Original repository
https://code.google.com/archive/p/arduino-pwm-frequency-library/downloads

Original Arduino Forum library post by Runnerup (Sam Knight):
https://forum.arduino.cc/index.php?topic=117425.0

and my code is below. The compilation errors are due to the fact that the library has not been updated to support the Giga board, so the variable names for the registers (TCCR1B etc.) are not included in the build (undefined value errors). I could hack the library and add a definition so that they were defined again, but are the timer registers compatible between Mega and Giga boards? (i.e are they are the same addresses and is it the same chip?)

Is there another way to change PWM frequency?

void pwmSetup() {

  // PWM pins
  pinMode(VOLUME1_PIN_A, OUTPUT);
  pinMode(VOLUME1_PIN_B, OUTPUT);
  pinMode(TONE1_PIN, OUTPUT);
  pinMode(VOLUME2_PIN_A, OUTPUT);
  pinMode(VOLUME2_PIN_B, OUTPUT);
  pinMode(TONE2_PIN, OUTPUT);
  pinMode(VOLUME3_PIN_A, OUTPUT);
  pinMode(VOLUME3_PIN_B, OUTPUT);
  pinMode(TONE3_PIN, OUTPUT);

 
  // Leave timer 0 alone, don't use pins 4, 13
  //change frequency for Timer 1: Pins 11,12
  int myEraser = 7; // this is 111 in binary and is used as an eraser
  int myPrescaler = 1; // this could be a number in [1 , 6]. In this case, 1 corresponds in binary to 001.
  TCCR1B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR1B to 0
  TCCR1B |= myPrescaler; //this operation (OR), replaces the last three bits in TCCR1B with our new value 001, 31kHz
  TCCR2B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR2B to 0
  TCCR2B |= myPrescaler; //this operation (OR), replaces the last three bits in TCCR2B with our new value 001, 31kHz
  TCCR3B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR2B to 0
  TCCR3B |= myPrescaler; //this operation (OR), replaces the last three bits in TCCR2B with our new value 001, 31kHz
  TCCR4B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR2B to 0
  TCCR4B |= myPrescaler; //this operation (OR), replaces the last three bits in TCCR2B with our new value 001, 31kHz

  // set initial volume
  pwmVolume(); 
}

I think I have the workaround for the higher frequency PWM, I wrote my own version of the analogWrite function that sets the frequency to 50KHz instead of 500Hz. I need to test it though.

Hi, thanks for the answer.

I do not have any code yet, since I am trying to get Interrupts to work on the Giga. How do you set it up?

As an example, how do you set up a recurring interrupt at 100Hz on the Giga? Preferably without any library, but if there are any compatible libraries then it is good to know.