在没有“循环"的情况下重复某条指令一定次数? [英] Repeat an instruction a certain number of times without a "loop"?

查看:24
本文介绍了在没有“循环"的情况下重复某条指令一定次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前用过 PIC,现在我用的是 STM32F415.在我的代码的时间关键部分,我需要设置一个非常精确的延迟来调整 DAC-DMA 的周期,这些 DAC-DMA 一起工作以创建周期性模拟信号.

I've used PICs before and now I'm using with STM32F415. On a time-critical part of my code I need to put a very exact delay to adjust the period of the DAC-DMA that are working together to create a periodic analog signal.

我想添加的延迟从 0 到 63 个时钟周期(如果我能够做 10-63 个时钟周期,那也可以).在 PIC24F 汇编中,有一条指令REPEAT",它允许我将下一条指令重复一定次数.这对我很有用,因为我可以这样做:

The delay I want to add goes from 0 to 63 clock cycles (If I were able to do 10-63 clock cycles it would be OK aswell). In PIC24F assembly, there's the instruction "REPEAT" which allows me to repeat the next instruction a certain number of times. That would work great for me as I'd be able to just do:

REPEAT #0xNUMBER
NOP

我试图找到与 STM32F4 类似的东西,但我在指令集、参考手册和互联网上搜索都没有运气.

I'm trying to find something similar with the STM32F4, but I had no luck searching in the instruction set, Reference Manual, and on the Internet in general.

我已经尝试在 C 中使用 for/while 循环和一个专用于它的计时器,但是所需的额外指令消耗了太多时间(40-50 个周期,具体取决于我的编程方式).

I've already tried to use for/while loops in C and a timer dedicated to it, but the extra instructiosn required consume too much time (40-50 cycles depending on the way I program it).

如果有人有想法或知道如何去做,这对我来说非常有用.

If someone has an idea or knows how to do it, It would be very useful for me.

非常感谢.

英语不是我的母语,因此对于任何可能的错误,我深表歉意.让我知道,我会努力改进它:)

编辑 1(17 年 7 月 23 日)

感谢大家的回答,我最近很忙,不能一一回复.我会尝试@berendi 门控时钟解决方案,它似乎最适合我的应用程序.学习了很多关于STM32我不知道的东西,谢谢大家!

Thanks to everyone answering, I've been very busy and couldn't answer every one of you individually. I'll try @berendi solution of gated clocks, it seems as the best fit for my application. I'm learning a lot of things about the STM32 I didn't know, thank you everyone!

推荐答案

我停止使 de DMA-DAC 工作的计时器,进行延迟,然后再次启用它.

I stop the timer that makes de DMA-DAC work, do the delay and then enable it again.

所以,如果我理解正确的话,您有定时器 A 控制您的 DAC,在每次计数器溢出时触发转换,并且您希望将其延迟可变数量的时钟周期.

So, if I'm understanding it correctly, you have Timer A controlling your DAC, triggering a conversion at each counter overflow, and you'd like to delay it for a variable number of clock cycles.

STM32F4 的大多数(如果不是全部)定时器支持门控模式从机操作,您可以选择另一个定时器(定时器 B)作为主控,定时器 A 仅在触发时计数定时器 B 的输出为低电平.换句话说,定时器 A 将在定时器 B 的上升沿停止计数,并在下降沿恢复计数.现在,将定时器 B 配置为在启用时输出单个脉冲,其中脉冲宽度是您想要的延迟,然后定时器 A 将延迟脉冲的确切持续时间.

Most (if not all) timers of the STM32F4 support gated mode slave operation, where you can select another timer (Timer B) as a master, and Timer A counts only as long as the trigger output of Timer B is low. In other words, Timer A will stop counting on a rising edge from Timer B, and resume counting on a falling edge. Now, configure Timer B to output a single pulse when enabled, where the pulse width is the delay you want, then Timer A will be delayed for the exact duration of the pulse.

参见参考手册中关于单脉冲模式、定时器和外部触发同步的章节,以及对 CR1、CR2 和 SMCR 寄存器的描述.

See the chapters on One-pulse mode, Timers and external trigger synchronization, and the description of the CR1, CR2, and SMCR registers in the reference manual.

这篇关于在没有“循环"的情况下重复某条指令一定次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆