Analog Input
R2026bRead ADC register value after conversion at Teensy 4.0 and 4.1 analog pins and trigger conversions from FlexPWM events
Since R2026b
Analog Input Teensy4 block
To add a block to a model, double-click the canvas and start typing the block name. Then, select the block from the list.
Libraries:
Simulink Support Package for Arduino Hardware /
Advanced /
TEENSY4
Description
Add-On Required: This feature requires the Simulink Support Package for Arduino Hardware add-on.
The Teensy Analog Input block reads analog-to-digital converter (ADC) register values after conversion from analog pins on Teensy 4.0 and 4.1 boards.
Use this block to:
Read up to three analog voltage inputs simultaneously or sequentially.
Run ADC conversions in a downstream function-call subsystem triggered by a Hardware Interrupt -configured interrupt service routine (ISR).
Run ADC conversions in a downstream function-call subsystem triggered by a Hardware Interrupt-configured interrupt service routine (ISR).
Run ADC conversions in a downstream function-call subsystem triggered by an interrupt service routine (ISR) configured with the Teensy Hardware Interrupt block.
Supported Arduino Boards
Teensy 4.0 (Arduino® Compatible)
Teensy 4.1 (Arduino Compatible)
Examples
Read an analog voltage from a Teensy pin and output the ADC value.
Add the Teensy PWM and Teensy Analog Input blocks to your model.

In the model settings, set Hardware board to either
Teensy 4.0 (Arduino Compatible) or
Teensy 4.1 (Arduino Compatible).
In the Teensy PWM block parameters, set Pin number to a PWM-capable Teensy pin. Identify the FlexPWM timer module associated with the selected pin. For more information, see Map Analog Input pin numbers on Teensy boards.
In the Teensy Analog Input block parameters, set Pin number 1 to a valid Teensy analog input pin.
Set ADC trigger timer to match the FlexPWM timer used by the Teensy PWM block.
Set ADC trigger event to select when the ADC conversion occurs relative to the PWM cycle (for example, Overflow to trigger at the start of each PWM period).
Connect the analog signal to the selected pin on the Teensy board. Use a Scope or Display block to observe the ADC output value.
Generate an interrupt when an ADC conversion completes on a Teensy board and trigger a function-call subsystem using the Teensy Hardware Interrupt block.
Add the Teensy PWM, Teensy Analog Input, and Teensy Hardware Interrupt blocks to your model.

In the model settings, set Hardware board to either
Teensy 4.0 (Arduino Compatible) or
Teensy 4.1 (Arduino Compatible).
In the Teensy PWM block parameters, set Pin number to a PWM-capable Teensy pin. Identify the FlexPWM timer module associated with the selected pin. For more information, see Map Analog Input pin numbers on Teensy boards.
In the Teensy Analog Input block parameters, set Pin number 1 to a valid Teensy analog input pin.
Set ADC trigger timer to match the FlexPWM timer used by the Teensy PWM block.
Set ADC trigger event to select when the ADC conversion occurs relative to the PWM cycle.
Select Enable ADC conversion complete interrupt.
In the Teensy
Hardware Interrupt block parameters, set Interrupt
group to Analog to digital converter
(ADC).
Set Interrupt
name to ADC_EOC_Channel_1 (or the
channel that corresponds to the ADC channel used by the Teensy Analog Input
block).
In the Events to serve table, select the ADC RESRDY event to trigger the function-call subsystem when the ADC conversion result is ready.
Extended Examples
Run PMSM Motor in Open Loop on Teensy Hardware
Use Simulink® Support Package for Arduino® Hardware to run a permanent magnet synchronous motor (PMSM) using open-loop voltage-frequency (V/F) control on a Teensy® development board.
- Since R2026b
- Open Model
Measure Phase Currents of PMSM Motor in Open Loop Teensy Hardware
Use Simulink® Support Package for Arduino® Hardware to measure three-phase currents of a permanent magnet synchronous motor (PMSM). The example deploys an open-loop voltage-frequency (V/F) control algorithm on a Teensy® development board.
- Since R2026b
- Open Model
Estimate Angle and Speed of PMSM Motor in Open Loop on Teensy Hardware
Use Simulink® Support Package for Arduino® Hardware to estimate the rotor angle and speed of a permanent magnet synchronous motor (PMSM) using an extended EMF observer. The example deploys an open-loop voltage-frequency (V/F) control algorithm and the observer on a Teensy® development board.
- Since R2026b
- Open Model
Sensorless Field-Oriented Control of PMSM Motor Using Teensy Hardware
Use Simulink® Support Package for Arduino® Hardware to implement a sensorless field-oriented control (FOC) of a permanent magnet synchronous motor (PMSM). The example deploys the control algorithm to a Teensy development board and drives the motor through the DRV8305EVM inverter.
- Since R2026b
- Open Model
Estimate Battery Current of PMSM in Open-Loop Control Using Arduino Hardware
Use Simulink® Support Package for Arduino® Hardware to estimate the battery current of a permanent magnet synchronous machine (PMSM) in open-loop control using Motor Control Blockset™. This example also shows how to actuate a PMSM motor and calculate phase currents that are indirectly used to estimate the current of the battery.
Ports
Output
The block outputs the ADC conversion value that it reads on the analog input
pin of the Teensy board. The Teensy boards have 12-bit resolution ADC, so the
output ranges from 0 to 4095. The number of output ports depends on the number
of analog input pins you specify in the Number of
analog input pins parameter. For example, if you set this
parameter to 3, the block enables three output ports
with port names ADC_Ch1(A0),
ADC_Ch2(A1), and
ADC_Ch3(A2).
Data Types: uint16
Parameters
Select how many ADC channels the block reads. The block creates the same number of output ports as the selected channel count.
Specify the Teensy board analog input pin number used for ADC conversion. To open the Arduino pin mapping table, click View pin map. To know how to assign pins for the Analog Input block, see Pin Mapping for Arduino Timer-Independent Blocks.
The number of Pin Number parameters matches the number of analog input pins you specify in the Number of analog input pins parameter.
Select how the block performs ADC conversion when you configure more than one ADC pin.
Sequential— The block reads the selected pins one after another and updates the outputs in a sequence. You can read one, two, or three pins in this mode.Simultaneous— The block reads multiple pins at the same time and updates the outputs together. You can use this mode only when Number of analog input pins is2.
Select the FlexPWM timer that triggers ADC conversion. To synchronize ADC sampling with a PWM output, include a Teensy PWM block in the model and configure both blocks to use the same FlexPWM timer. To view the pin mapping table, see Map PWM Pins to FlexPWM Timer Modules.
For example, if the Teensy
PWM block uses pin 4 on Teensy 4.0, the pin mapping table shows this
pin maps to FlexPWM2_0. Set ADC trigger timer to
FlexPWM2_0.
Select the FlexPWM timing event that triggers the ADC conversion.
Overflow— Trigger ADC conversion at the start of each PWM cycle when the PWM timer reloads.PWMCenter— Trigger ADC conversion in the middle of the PWM cycle (central point).RisingEdge— Trigger ADC conversion when the PWM signal transitions from low to high (rising edge).FallingEdge— Trigger ADC conversion when the PWM signal transitions from high to low (falling edge).
This parameter requires a Teensy PWM block in the model configured with the same FlexPWM timer module to generate the trigger signal.
Enable this interrupt after the voltage at the pin of the Teensy board is converted to a digital value. To handle the interrupt, configure the Interrupt group, Interrupt name, and Events to serve in the Teensy Hardware Interrupt block.
More About
Use this table to translate between analog pin numbers, analog pin names, and digital pin numbers on Teensy 4.0 and 4.1 boards when configuring blocks that require an analog input pin.
| Board | Digital Pin Number | Analog Pin Number | Pin Number N Parameter Value |
|---|---|---|---|
| Teensy 4.0 | 14-27 | A0-A13 | 0-13 |
| Teensy 4.1 | 17-27, 38-41 | A0-A17 | 0-17 |
To determine what pin number to use:
Identify the digital pin number on your Teensy board where the analog pin is connected (for example, digital pin
17).In the table, find the corresponding analog input pin (for example, digital pin
17corresponds to A3).Enter the analog pin number in the Pin number N parameter of the block (for example, enter
3for A3).
Extended Capabilities
The Teensy Analog Input block supports C/C++ code generation using Embedded Coder®.
Version History
Introduced in R2026b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)




