====== analogWriteInit() ====== ''analogWriteInit()'' sets the resolution and prescaler of the output timer. {{:en-us_commands:reference:analogwriteinit.svg?900|analogWriteInit command operation flow}} ''void analogWriteInit(uint8_t ch, uint16_t top = 65535, uint16_t prescaler = 1)'' ===== Commands ===== ^ Command ^ Arguments ^ Return Value ^ Operation ^ | ''analogWriteInit(ch, top, prescaler)'' | ''uint8_t ch''\\ ''uint16_t top = 65535''\\ ''uint16_t prescaler = 1'' | ''void'' | Sets the resolution and prescaler of the output timer. | ===== Example ===== void setup() { analogWriteInit(0, 65535, 1); // Set the output timer's resolution and prescaler. analogWrite(0, 32767); // Approx. 50% analogWrite(1, 65535); // 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|analogWriteFreq() View detailed description]] * [[:en-us_commands:reference:analogwritemax|analogWriteMax() View detailed description]] * [[:en-us_commands:reference:ianalogwriteinit|IanalogWriteInit() View detailed description]] * [[:en-us_commands:reference:ianalogwrite|IanalogWrite() View detailed description]] * [[:en-us_commands:reference:ianalogwritef|IanalogWritef() View detailed description]] [[:en-us_commands:builtin|← Built-in Command List]]