Triggering multiple output pins of Arduino simultaneously from Simulink

29 ビュー (過去 30 日間)
Md. Razon Chowdhury
Md. Razon Chowdhury 2022 年 2 月 8 日
編集済み: Md. Razon Chowdhury 2022 年 2 月 11 日
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?

回答 (1 件)

Highphi
Highphi 2022 年 2 月 8 日
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 件のコメント
Md. Razon Chowdhury
Md. Razon Chowdhury 2022 年 2 月 11 日
編集済み: Md. Razon Chowdhury 2022 年 2 月 11 日
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?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by