Triggering multiple output pins of Arduino simultaneously from Simulink

75 views (last 30 days)
Using DigitalWrite command in Arduino for multiple pins creates a delay, which can be solved as follows.
PORTB = 0b00110000; (Pin 12 and 13 becomes high simultameously)
However, when I use simulink for the same purpose, there is a 30 us delay (from oscilloscope) between the pin 12 and pin 13 high time.
I know that internal codes of simulink uses DigitalWrite command for a digital output pin and it works for only a single pin at a time.
In Arduino code, it is possible to write on a Port say, PORTB = 0b00110000; (Pin 12 and 13 becomes high simultameously)
Is there any way by which we can write on a Port of Arduino similarly from simulink?
I think, there is no building option.
However, is there any alternative way say by modifying any code to write on a port of Arduino from simulink?
How the delay time can be reduced to zero?

Answers (1)

Highphi
Highphi on 8 Feb 2022
Unfortunately, the way Arduino evaluates code is step by step, therefore parallel evaluation does not exist on that hardware.
30 us is probably the closest to 'simultaneous' you will be able to get.
  1 Comment
Md. Razon Chowdhury
Md. Razon Chowdhury on 11 Feb 2022
Edited: Md. Razon Chowdhury on 11 Feb 2022
When we write 'PORTB = 0b00110000' command in Arduino emulator, all the pins are triggered accroding to the '1' or '0' value as in the code simultaneously. All the pins are triggered at a same time, which are clear from the oscilloscope, even no us delay. Probably, they are triggered at a same machine clock cycle.
The delay problem begins when we write a number of 'DigitalWrite' commands one after another although any delay is not inserted in between them.
DDRB/DDRD/DDRC and PORTB/PORTD/PORTC commands solve the delay problem. However, these can be used only in Arduino emulator code.
Is it possible to use the DDRB/DDRD/DDRC and PORTB/PORTD/PORTC commands from simulink?
Summary:
Arduino emulator: Supports 'DigitalWrite' command, but it has delay. Problem can be solved using DDR and PORT commands.
Simulink : Supports 'DigitalWrite' command, but it has delay. Is it possible to use DDR and PORT commands here?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!