完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,
我在ST视觉开发中遇到了一个非常令人尴尬的问题。 当我在函数调用之前添加断点时,我将鼠标悬停在用鼠标发送的参数上,我可以看到它。但是当我进入函数时,参数变得错误:它具有完全随机的值。 此外,当mcu必须进行计算时,它可能会做错。 这种计算可能是错误的: result =(uint16_t)((sqrt((float)sum / measures_nb)/ 1023.0 * 3.3 / 0.1)* 1000); 如果我用另一个编译器执行此操作,结果是正确的。 除了+ split之外我禁用了所有优化,因为没有这个我得到.text溢出 如果有人能提供帮助,我感激不尽。 谢谢 以上来自于谷歌翻译 以下为原文 Hello, I'm facing a very embarrasing problem with variables in ST visual develop. When I add a breakpoint just before a function call and I hover the parameter being sent with my mouse I can see it. But when I step into the function, the parameter became wrong : it has totally random values. Also when the mcu has to do calculations, it can do it wrong. This kind of calculation can be wrong : result = (uint16_t)((sqrt((float)sum / measures_nb) / 1023.0 * 3.3 / 0.1) * 1000); If I do this with another compiler, the result is correct. I disabled all optimisations except +split because without this I get a .text overflow If someone can help, I appreciate. Thanks |
|
相关推荐
5个回答
|
|
sqrt()是否使用双打?
你想要sqrtf()吗? 它是在寄存器中保存值/变量而不是内存吗?堆栈框架在移动吗? 您应该查看与该函数相关的汇编代码。理想情况下,如果编译器生成这样的代码/汇编器列表类型文件。 不确定这里有多少STM8支持。 //这可能有更好的施法 result =(uint16_t)((sqrt((double)sum /(double)measures_nb)/ 1023.0 * 3.3 / 0.1)* 1000.0); 您还可以将值保存为double并首先检查。还要考虑使用测试值检查/调试PC编译器。 以上来自于谷歌翻译 以下为原文 Isn't sqrt() using doubles? Do you want sqrtf() ? Is it holding values/variables in registers and not memory? Is the stack frame moving? You should review the assembler code related with the function. Ideally a code/assembler listing type file if the compiler generates such. Not sure there is much STM8 support to be had here. // This might have better casting result = (uint16_t)((sqrt((double)sum / (double)measures_nb) / 1023.0 * 3.3 / 0.1) * 1000.0); You could also save the values as a double and check that first. Consider also checking/debugging on a PC compiler with test values. |
|
|
|
sqrt()是否使用双打?
是的。使用float而不是double会发生什么问题? 它是在寄存器中保存值/变量而不是内存吗?堆栈框架在移动吗? 我明天会检查这个,但你能解释一下你想知道什么,你正在谈论什么价值,因为我不是汇编,注册,...的专家。 谢谢 以上来自于谷歌翻译 以下为原文 Isn't sqrt() using doubles? Yes it is. What wrong could happen by using a float instead of a double ? Is it holding values/variables in registers and not memory? Is the stack frame moving? I will check this tomorrow but can you explain a little bit more what you want to know and what values you are talking about because i'm not an expert with assembler, register, ... Thanks |
|
|
|
float / double的选择很大程度上取决于数字和精度的范围,以及你想要进行计算的速度。
如果你可以保持一种形式而不是来回转换,那将节省大量时间。将常量保持为一种形式,并让编译器折叠数学。 result =(uint16_t)((sqrtf((float)sum /(float)measures_nb)/ 1023.0f * 3.3f / 0.1f)* 1000.0f); 抱歉,对STM8及其编译器/调试器没有任何特定的经验。如果将变量保存在寄存器而不是存储器中,则变量的可见性可能会受到限制。你必须阅读代码来衡量它在做什么 以上来自于谷歌翻译 以下为原文 The choice of float/double depends a lot on the range of numbers and precision, and the speed at which you want to do the computations. If you can stay in one form and not convert back-and-forth, that would save a lot of time. As will keeping the constants in one form, and having the compiler fold up the math. result = (uint16_t)((sqrtf((float)sum / (float)measures_nb) / 1023.0f * 3.3f / 0.1f) * 1000.0f); Sorry don't have any specific experience with the STM8 and its compiler/debugger. Visibility of variables may be limited if they are held in registers rather than memory. You'll have to read the code to gauge what it is doing |
|
|
|
你好,
在Cosmic stm8编译器中,双精度数被静默转换为float,因为它没有为此微实现实现double,因为它会使用太多资源。 对于未按预期显示的变量值,原因可能与Clive所说的一样:在某些点上,变量可能保存在寄存器或堆栈中,调试信息并不总是能够遵循这一点,在调试时会产生一些混乱。通常将变量声明为volatile是足以使它们正确显示,但这是一种肮脏的解决方法,您应该在检查值时删除关键字。 至于计算错误的结果,它可能与浮点数的精度有关:只是为了给你一个想法,浮点类型具有大约7个有用数字的精度,因此如果你的计算(或一些它的中间结果)需要更多的计算可能会出错:如果您使用更大的类型进行相同的计算(在PC上或实际实现双重类型的更大的微型),您将看到差异。 问候, 卢卡 以上来自于谷歌翻译 以下为原文 Hello, in the Cosmic stm8 compiler doubles are silently converted to float, since double is not implemented for this micro as it would use too many resources. For the values of variables not showing as you would expect, the reason is probably as Clive says: in some points variables might be held in registers or stack and the debug info is not always able to follow this, generating some confusion when you debug. Usually declaring the variables as volatile is enough to make them display correctly, but this is a dirty workaround, and you should remove the keyword when you have checked your values. As for the result of the calculation being wrong, it has probably something to do with the precison of the float: just to give you an idea, the float type has a precision of around 7 useful digits, therefore if your calculation (or some of its interlmediate results) requires more the calculation might go wrong: if you do the same calculation with bigger types (on a PC or on a bigger micro where the double type is actually implemented) you will see the difference. Regards, Luca |
|
|
|
在Cosmic stm8编译器中,双精度数被静默转换为float,因为它没有为此微实现实现double,因为它会使用太多资源。
目前STM8的所有编译器(SDCC,IAR,Cosmic,Raisonance)都将使用float而不是double。有些人默默地(至少是宇宙),有些人有警告(至少是SDCC)。 菲利普 以上来自于谷歌翻译 以下为原文 in the Cosmic stm8 compiler doubles are silently converted to float, since double is not implemented for this micro as it would use too many resources. Currently all compilers (SDCC, IAR, Cosmic, Raisonance) for the STM8 will use float instead of double. Some silently (at least Cosmic), others with a warning (at least SDCC). Philipp |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2649 浏览 1 评论
3213 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1787 浏览 1 评论
3617 浏览 6 评论
5996 浏览 21 评论
944浏览 4评论
1318浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
588浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1307浏览 3评论
1367浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 16:22 , Processed in 1.230675 second(s), Total 54, Slave 48 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号