Arduino Due : Impossible to use the fonctiobn pulsein()
1 view (last 30 days)
Show older comments
Hello,
I want to run an ultrasonic sensor HC-SR04 with an Arduino Due with simulink
I program my s-function
Outputs:
digitalWrite(6, HIGH);
delayMicroseconds(10);
digitalWrite(6, LOW);
Distance[0] = pulseIn(7, HIGH)/58;
I pass all the details off the code. I have tried lot of thing on the code and with another sensor (grove ultrasonic sensor). I had a look with an oscilloscope too..
I know my code is good but my problem is that pulsein() never send me a good value.
I run succefully a code working with interuption but I want to know why the function pulsein() is not working
I run Matlab R2017A
Is someone add the same problems too? and is someone have a solution?
Thank you
4 Comments
omar Elkawokgy
on 20 Jul 2020
Edited: omar Elkawokgy
on 20 Jul 2020
I have came up with a work around to ignore the assebly "wiring_pulse.S". I used the C function present in the comment of the file itself ("wiring_pulse.S") as shown below:
/*
* The following routine was generated by avr-gcc 4.8.3 with the following parameters
* -gstabs -Wa,-ahlmsd=output.lst -dp -fverbose-asm -O2
* on the original C function
*
* unsigned long pulseInSimpl(volatile uint8_t *port, uint8_t bit, uint8_t stateMask, unsigned long maxloops)
* {
* unsigned long width = 0;
* // wait for any previous pulse to end
* while ((*port & bit) == stateMask)
* if (--maxloops == 0)
* return 0;
*
* // wait for the pulse to start
* while ((*port & bit) != stateMask)
* if (--maxloops == 0)
* return 0;
*
* // wait for the pulse to stop
* while ((*port & bit) == stateMask) {
* if (++width == maxloops)
* return 0;
* }
* return width;
* }
*
* some compiler outputs were removed but the rest of the code is untouched
*/
I added the function above in "wiring_pulse.c" after uncommenting it, also added its prototype in "wiring_private.h". I build and flashed without building or linking errors.
I have attached the files with changes surrounded with tag " /*OELKAWOK*/ "
Note: I have not verified this on a sensor yet, so I do not know if this function will get the correct data from the sensor or not
Answers (0)
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!