Hello All;
I need a delay that (in a perfect world) I can configure in software for 1 to 16uS in 1uS steps. During initial setup I read a BCD switch to obtain the needed delay. This is necessary to accommodate different pieces of hardware that might be connected to the device. I then set a delay based on the switch setting. This allows it to be field configurable.
I am using an ATtiny2313A with an 8MHz clock which yields a 125ns clock cycle.
After spending a few days at the Bascom simulator checking machine cycles used vs. code used, the shortest execution time I could come up with is the following Bascom code snippet:
Reset PORTB.0
Do
Count = Count + 1 'Increment counter
Loop Until Count = Sig_delay 'Stay here until delay time ends
Set PORTB.1
Sig_delay is the BCD switch setting, numerically in the range of 1-16. The above loop obviously cannot provide the needed resolution, it's the result of a test to see how short I could generate a configurable delay using Bascom statements.
Using the Bascom simulator, I find the delay after the Reset and before the Set to total 2.000uS for Sig_delay=1. Subsequently, each increment of Sig_delay adds 1.750uS to the delay time. I can see where the machine cycles are coming from, but not sure of a way to speed things up. I'm not that far away, but might I need to resort to assembler using another technique . . . ? The above test code would produce 2us for BCD=1, 3.75us for BCD=2, 5.5uS for BCD=3, etc. Not too bad, but not quite enough resolution.
Please keep in mind that I cannot string NOPs together, it has to work from a variable that is set on startup.
If you have any ideas, I'd appreciate hearing them. Please keep in mind I'm an analog type of guy, and very new to AVR devices - Maybe 2 weeks. I could use a pointer in the right direction.
Regards, Ken
[b:d499e07c9b][color=red:d499e07c9b](BASCOM-AVR version : 2.0.7.6 )[/b:d499e07c9b][/color:d499e07c9b]
↧