重复一个指令一定次数而没有“循环”? [英] Repeat an instruction a certain number of times without a "loop"?

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

问题描述

我之前使用过PIC,现在我正在使用STM32F415。
在我的代码的时间关键部分,我需要非常精确的延迟来调整正在协同工作的DAC-DMA周期以创建周期性模拟信号。



我想添加的延迟从0到63个时钟周期(如果我能够做10-63个时钟周期,那将是正常的)。在PIC24F程序集中,有一个指令REPEAT允许我重复下一个指令一定次数。这对我来说很有用,因为我可以做到这一点:

  REPEAT#0xNUMBER 
NOP

我正在寻找与STM32F4类似的东西,但是我没有运行在指令集中搜索,参考手册和互联网一般。



我已经尝试使用C中的/ while循环和专用于它的计时器,但需要额外的指导消耗太多的时间(40-50个周期取决于我编程的方式)。



如果有人有一个想法或知道如何做,这将是非常有用的对我来说



非常感谢。



英语不是我的母语,所以我对任何可能的错误抱歉让我知道,我会尝试改进它:)



编辑1(23-jul-17) p>

感谢大家的回答,我一直很忙,不能单独回答你们每一个人。
我会尝试@berendi门控时钟的解决方案,它似乎是最适合我的应用程序。
我正在学习很多关于STM32的事情,我不知道,谢谢大家!

解决方案


我停止使DMA-DAC工作的计时器,执行延迟,然后
再次启用。


所以,如果我正确理解它,你有一个TimerA控制你的DAC,触发在每个计数器溢出的转换,你想延迟一个可变数量的时钟周期。



STM32F4的大多数(如果不是全部)定时器支持门控模式从站操作,您可以在其中选择另一个定时器(定时器B)作为主站,以及只要定时器B的触发输出为低电平,定时器A才会计数。换句话说,定时器A将在定时器B的上升沿停止计数,并在下降沿继续计数。现在,配置定时器B在使能时输出单个脉冲,其中脉冲宽度是所需的延迟,则定时器A将延迟脉冲的确切持续时间。





请参阅有关单脉冲模式,定时器和外部触发同步的章节,以及参考手册中CR1,CR2和SMCR寄存器的描述。


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.

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

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.

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.

Thanks a lot.

English is not my mother-tongue language so I'm sorry for any possible mistakes. Let me know and I'll try to improve it :)

EDIT 1 (23-jul-17)

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!

解决方案

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

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.

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.

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天全站免登陆