Arduino Uno 25kHz pwm

Hello,
i'm looking for a way to change the standard firmata so that 2-4 pins can output a PWM signal with 25khz.

Background:
The Arduino Uno is connected to a Raspberry, which sends the "control commands" to the Arduino (The software is called NodeRed Interacting with Arduino : Node-RED).

Someone from the internet has now sent me the following code (without further instructions and unformatted). Unfortunately I don't know what to do with it now.
Is this a code of my own, do I have to insert it somewhere in the standard fimata or what do I have to do with it?

//PWM output @ 25 kHz, only on pins 9 and 10. // Output value should be between 0 and 320, inclusive. void analogWrite25k(int pin, int value) { switch (pin) { case 9: OCR1A = value; break; case 10: OCR1B = value; break; default: // no other pin will work break; } } void setup() { // Configure Timer 1 for PWM @ 25 kHz. TCCR1A = 0; // undo the configuration done by... TCCR1B = 0; // ...the Arduino core library TCNT1 = 0; // reset timer TCCR1A = _BV(COM1A1) // non-inverted PWM on ch. A | _BV(COM1B1) // same on ch; B | _BV(WGM11); // mode 10: ph. correct PWM, TOP = ICR1 TCCR1B = _BV(WGM13) // ditto | _BV(CS10); // prescaler = 1 ICR1 = 320; // TOP = 320 // Set the PWM pins as output. pinMode( 9, OUTPUT); pinMode(10, OUTPUT); } void loop() { // Just an example: analogWrite25k( 9, 110); analogWrite25k(10, 210); for (;;) ; // infinite loop }

Unfortunately it is no longer available for family reasons.

Can anyone help me?

//PWM output @ 25 kHz, only on pins 9 and 10.
// Output value should be between 0 and 320, inclusive.
void analogWrite25k(int pin, int value)
{
  switch (pin)
  {
    case 9:
      OCR1A = value;
      break;
      
    case 10:
      OCR1B = value;
      break;
      
    default: // no other pin will work
      break;
  }
}


void setup()   // Configure Timer 1 for PWM @ 25 kHz.
{
  TCCR1A = 0; // undo the configuration done by...
  TCCR1B = 0; // ...the Arduino core library
  TCNT1 = 0; // reset timer
  TCCR1A = _BV(COM1A1) // non-inverted PWM on ch. A
           | _BV(COM1B1) // same on ch; B
           | _BV(WGM11); // mode 10: ph. correct PWM, TOP = ICR1
  TCCR1B = _BV(WGM13) // ditto
           | _BV(CS10); // prescaler = 1
  ICR1 = 320; // TOP = 320
  // Set the PWM pins as output.
  pinMode( 9, OUTPUT);
  pinMode(10, OUTPUT);
}


void loop()
{
  // Just an example:
  analogWrite25k( 9, 110);
  analogWrite25k(10, 210);
  for (;;) ; // infinite loop
}

Oh, Thanks.

Gummix:
Is this a code of my own, do I have to insert it somewhere in the standard fimata or what do I have to do with it?

Can anyone help me?

You will need to make your own version of Firmata. Which style of Firmata does closest to what you want? There are lots of examples in File->Examples->Firmata. My guess is that you would be using "OldStaandardFirmata" or "SimpleAnalogFirmata". Find the source for those examples in the 'examples' folder of the Firmata library folder in your Arduino installation. Copy the example folder into your sketch folder and then you can open it and start making changes.

Hi,
i use the normal "StandardFirmata"
so I can control the Arduino with the Rasperry. Only the frequency of the PWM signals is wrong.

Gummix:
i use the normal "StandardFirmata"

So start by opening File->Examples->Firmata->StandardFirmata and using File->Save as... to make your own copy. Aside from setting up the necessary timers your changes will probably be in analogWriteCallback() where PWM output is done.