User Tools

Site Tools


en-us_commands:reference:analogwritefreq

analogWriteFreq()

analogWriteFreq() sets the PWM frequency of the specified output channel.

analogWriteFreq command operation flow

uint16_t analogWriteFreq(uint8_t ch, uint32_t frequencyHz)

Commands

Command Arguments Return Value Operation
analogWriteFreq(ch, frequencyHz) uint8_t ch
uint32_t frequencyHz
uint16_t Sets the PWM frequency of the specified output channel.

Example

void setup() {
  analogWriteFreq(3, 1000);  // Set the PWM frequency of the specified output channel.
 
  uint16_t maxValue = analogWriteMax(3);  // Return the maximum value available for the specified output channel.
 
  analogWrite(3, maxValue / 4);  // D46 / OC5A, approx. 25%
  analogWrite(4, maxValue / 2);  // D45 / OC5B, approx. 50%
  analogWrite(5, maxValue);      // D44 / OC5C, 100%
}
 
void loop() {
}

Precautions

  • analogWrite(0~15, value) is for Y analog output, and analogWrite(20~31, value) is for K/K2 high-speed pulse output.
  • High-speed pulse GPIOs are K D130~D135 and K2 D130~D141, fixed regardless of the number of Y modules.
  • Analog output uses raw 0~65535 values; high-speed pulse output uses Arduino-compatible 0~255 values.
  • analogWriteInit(), analogWriteFreq() and analogWriteMax() are for Y analog output channels. Do not use them for high-speed pulses 20~31.
  • Do not use analogWrite(130~141, value).
  • The 3 channels belonging to the same timer share TOP, prescaler and frequency.
  • Calling analogWriteFreq() automatically changes TOP, so it also changes the maximum duty value for subsequent analogWrite() calls.
  • Use the return value of analogWriteFreq() or analogWriteMax() to check the current maximum duty value.
  • Check for timer conflicts when using these commands with other PWM, pulse or high-speed counter functions that use Timer1, Timer3, Timer4 or Timer5.
  • MPAINO analog output modules may require a separate power supply and DIP switch settings.
  • The actual voltage or current output range must match the module DIP switches, supply, wiring and input specifications of the connected equipment.

Built-in Commands in the Same Category

en-us_commands/reference/analogwritefreq.txt · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki