Keil Logo

DMA Problem!!! please help

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Author
Majd Ghadab
Posted
5-Jun-2018 21:58 GMT
Toolset
ARM
New! DMA Problem!!! please help

Hello
i am trying to build a simple DMA program to read ADC values and its working but not completely

the problem is here: at first this code is working
1.

          u[0]=((float)ADC_Data[0])*3;
                sprintf(str,"%.2fv   ",u[0]);
                LCD_SetPos(0,0);
                LCD_String(str);

when changed to : or even divide by 1 its not working any more and the LCD is too slow

          u[0]=((float)ADC_Data[0])*3/4096;
                sprintf(str,"%.2fv   ",u[0]);
                LCD_SetPos(0,0);
                LCD_String(str);

2. the debugger is updating the correct u[0] in this code without a problem:

          u[0]=((float)ADC_Data[0])*3;
                sprintf(str,"%.2fv   ",u[0]);
                LCD_SetPos(0,0);
                LCD_String(str);

but in this code not !!! why even when i put the 3 lines to comments its must not affect the u[0] value

          u[0]=((float)ADC_Data[0])*3;
//              sprintf(str,"%.2fv   ",u[0]);
//              LCD_SetPos(0,0);
//              LCD_String(str);

please please i spend hours ... hours without any success please help why the division is not working and the bug in updating u[0] value i tryied to use volatile variable double or others but always when i use division the code runs very slow

the full code is generated with Cubemx.

http://www.mediafire.com/file/qyrd8j0u0zlt7pl/main.zip/file

Author
Westonsupermare Pier
Posted
6-Jun-2018 01:54 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help
volatile uint16_t ADC_Data[3]; // Changed by DMA, not normal code flow, must be volatile
double d[3]; // sprintf works on doubles
char str[32]; // plenty of space
..

d[0]=(double)ADC_Data[0]) * (3.0 / 4096.0); // use floating point
sprintf(str,"%.2lfv   ",d[0]);
LCD_SetPos(0,0);
LCD_String(str);
Author
Westonsupermare Pier
Posted
6-Jun-2018 01:56 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

Can't edit, extra bracket removed..

d[0]=(double)ADC_Data[0] * (3.0 / 4096.0); // use floating point

Author
Majd Ghadab
Posted
6-Jun-2018 14:56 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

Hello thank you thank you very much for the help the code is working now the problem was only the .0 after the number
i have change float to double and mcu runs very very slow but with float its running normal
puting the variable as volatile or changeing the string size didn't affect the speed ?
i am now satisfied with program with float but why not working with double !
in the futur i may face this problem again so please can you help me how to fix it
there are tow files the first runs perfect and the second runs the lcd very slow
thanks

http://www.mediafire.com/file/w3z38n16g803tfl/mainNormalspeed.zip/file
http://www.mediafire.com/file/wa1l2nqyvi9k7vb/mainslow.zip/file

Author
Westonsupermare Pier
Posted
6-Jun-2018 15:34 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

Define SLOW, you have this grinding in a tight loop, the LCD is likely to flicker/tear.
Put a HAL_Delay(1000); in the loop

No behaviour here I can actually see.

Don't have your hardware, don't have a buildable project. No idea of the clocking or connectivity.

Author
Majd Ghadab
Posted
6-Jun-2018 17:35 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

Hello and thanks for replay
what i meant by slow :
when using float lcd scans is very fast and not noticable and the lcd flickers from speed regardldess of halt delay .. i removed halt delay because the scanning was very slow
anyway i was working with this LCD library and it works for sure with no problem
but using double makes every letter when scaning needs about 300ms that means for the whole scan of line it needs 1 to 2 seconds !!
only changing the float to double makes this happens.
the same problem was when i didn't use .0 after the float number
anyway this is the whole project with cubemx and Keil project
thanks in advance
http://www.mediafire.com/file/37tpd2dr1qhdloa/ADCDMA.rar/file

Author
Majd Ghadab
Posted
6-Jun-2018 17:55 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

please see the videos how the run with float and double

https://youtu.be/KyVJ0R99AL0

https://youtu.be/06e2t2754nM

Author
Majd Ghadab
Posted
6-Jun-2018 18:37 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

i think the problem is because stm32 doesn't support the double-precision division
check the file: page 16
http://www.stmicroelectronics.com.cn/resource/en/application_note/dm00047230.pdf
maybe thats why it takes too much time or ??
has anyone any idea please reply thanks.

Author
Westonsupermare Pier
Posted
6-Jun-2018 19:15 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

The processor is running at tens of millions of cycles per second, the fact it doesn't natively support floating point in either float OR double mode shouldn't be an issue.

You're probably perceiving a strobe-scope issue, put the 1 second delay in the loop as suggested earlier. Or for that matter toggle a GPIO pin and put it on a scope, determine if it is running at human perceivable speeds, or not.

Author
Westonsupermare Pier
Posted
6-Jun-2018 19:17 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

You are using an STM32F103, this is a Cortex-M3 processor, it doesn't have an FPU

Author
Majd Ghadab
Posted
6-Jun-2018 22:36 GMT
Toolset
ARM
New! RE: DMA Problem!!! please help

NOW i understood !! i red too many threads and articels the problem is :
conflict between LCD and DMA
STM32f103 is not as STM32F4 it has a differnt DMA architectur
anyway no LCD everything works
with LCD i should edit the timing in LCD library to work but it is not a solution anyway

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.