en-us_commands:reference:analogwritemax
This is an old revision of the document!
Table of Contents
analogWriteMax()
analogWriteMax() returns the maximum value available for the specified output channel.
uint16_t analogWriteMax(uint8_t ch)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
analogWriteMax(ch) | uint8_t ch | uint16_t | Returns the maximum value available for 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, andanalogWrite(20~31, value)is for K/K2 high-speed pulse output.- High-speed pulse GPIOs are K
D130~D135and K2D130~D141, fixed regardless of the number of Y modules. - Analog output uses raw
0~65535values; high-speed pulse output uses Arduino-compatible0~255values. analogWriteInit(),analogWriteFreq()andanalogWriteMax()are for Y analog output channels. Do not use them for high-speed pulses20~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 subsequentanalogWrite()calls. - Use the return value of
analogWriteFreq()oranalogWriteMax()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.
en-us_commands/reference/analogwritemax.1788791732.txt.gz · Last modified: by 127.0.0.1
