CASP models can interface with hardware input outputs on embedded micro-controller boards. This example, models hardware ADC input and PWM/DAC outputs on Arduino Uno board.
Pre-Requisites
- Arduino Uno R3 board.
- Suitable Arduino board supporting DAC output (such as Arduino Due, Arduino Uno R4 etc.).
- A 10K Pot, 470 ohms resistor, LED, bread board and sufficient jumper wires.
- CASP software is installed.
- Arduino BSP is installed.
- The project files are located at CASP installed directory ‘CASP/support/examples/hardware_interface/02_ai_pwm_dac’. These are also available for download at this link.
Description
The input voltage at pin A0 is varied by connecting an external pot (variable resistance) as shown in the circuit diagram. On the output side, PWM is used on pin-3 and DAC output on pin-DAC0 (on supported Arduino board). The outputs of PWM (and DAC0 if used) are connected to external LED with a suitable current limiting resistor in series. Logic is modelled to vary the brightness of the LED with respect to the voltage at A0. User needs to manually change the target to switch between Arduino Uno and Arduino Due/Arduino Uno R4 to use DAC0 during modelling. Please go through the individual block parameters used in the model along with respective documentation for better understanding.

CASP Model

Procedure
- Run CASP and open the project ‘CASP/support/examples/hardware_interface/02_ai_pwm_dac/02_ai_pwm_dac.prj’ from CASP installed directory.
- Open ‘Setup Simulation’ window and change the ‘Target Programmer Port’ to which the board is connected.
- Change the target board option suitably if any other board is used in place of Arduino Uno.
- Click Run button to build the model and program the board.
