how to generate 12bits resolution voltage from DAC pin of arduino due board in simulink

13 visualizaciones (últimos 30 días)
Hi, I am using Arduino due board DAC pin to generate voltage. I want resolution to be 12bits. But when i use in simulink, it generates 8bit resolution voltage from 0.56v to 2.76v. Please let me know how to generate the 12bit resolution voltage from DAC pins in simulink using Arduino due board. Block says it accepts 0-4095 values, but it does not react accordingly. It does Not react for each increament, it reacts only for multiple of 16 (example: 0, 16, 32, 48, 64 ........etc..).
Can you please let me know how to solve this problem.
Can we do this in PYTHON? :)
is there any solution using creating s-block??
Thanks

Respuestas (1)

Manikanta Aditya
Manikanta Aditya el 20 de Mzo. de 2023
Hi Aakash,
As per my understanding, you would like to know how to generate 12-bit resolution voltage from DAC pin of Arduino Due boards in Simulink.
To change the output total number of bits to 12, Please follow the steps mentioned below:
  • Open the Segmented DAC block by double clicking it.
  • Under Segment Settings, click on the ‘New Segment’ option. This allows you to add a new segment.
  • Change the number of bits to 4 in the newly added Segment.
  • Click on Apply’.
  • Then you can see that the total number of bits are changed to 12. Now you can generate the 12-bit resolution voltage from DAC pins in Simulink using Arduino Due board.
For further reference, please check this link to know about Design and Evaluate Segmented DAC:
I hope this resolves the issue you are facing.
  12 comentarios
aakash dewangan
aakash dewangan el 6 de Abr. de 2023
Hello Arun,
Yes. you understood the exact problem. Thank you.
Please let me know how to resolve the problem?
Thank you
Arun Kumar
Arun Kumar el 14 de Abr. de 2023
Editada: Arun Kumar el 14 de Abr. de 2023
Hi Aakash,
Please modify the MW_analogWriteDAC.cpp file by running the following command:
edit(fullfile(fileparts(codertarget.arduinobase.internal.getSpPkgRootDir),'arduinobase','src','MW_analogWriteDAC.cpp'))
This will opoen the MW_analogWriteDAC.cpp file in the MATLAB editor.
Replace the existing MW_DACWrite function with the following function:
extern "C" void MW_DACWrite(uint8_T channelFlag, uint32_T value)
{
#if defined(_ROTH_DUE_)
static int init_12bitDac = 0;
if(init_12bitDac==0){
analogWriteResolution(12); /* set the resolution of the Arduino analogWrite() function to 12 bits */
init_12bitDac = 1;
}
analogWrite(((channelFlag == 0)? DAC0 : DAC1), value);
#elif defined(_ROTH_MKR1000_) || defined(_ROTH_NANO33_IOT_)
/* dividing the data by 4 to adjust for upscaling by 4 in Arduino analogWrite API */
analogWrite(DAC0, (value>>2));
#elif defined(_ROTH_MKRZERO_) || defined(_ROTH_MKRWIFI1010_)
/* dividing the data by 4 to adjust for upscaling by 4 in Arduino analogWrite API */
analogWrite(15u, (value>>2));
#elif defined(_ROTH_ESP32_)
dacWrite(((channelFlag == 1)? DAC1 : DAC2), value);
#endif
}
This will change the resolution of DAC to 12 bit on Arduino due board. Please note that this change will only work for Arduino due. Other arduino boards are not affected by this change.
Hope this helps!
Thanks,
Arun

Iniciar sesión para comentar.

Categorías

Más información sobre Setup and Configuration en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by