en-us_commands:reference:analogwriteinit
This is an old revision of the document!
Table of Contents
analogWriteInit()
analogWriteInit() sets the resolution and prescaler of the output timer.
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 chuint16_t top = 65535uint16_t prescaler = 1 | void | Sets the resolution and prescaler of the output timer. |
Example
void setup() { analogWriteInit(0, 65535, 1); analogWrite(0, 32767); // Approx. 50% analogWrite(1, 65535); // 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/analogwriteinit.1788785565.txt.gz · Last modified: by 127.0.0.1
