Help needed with creating a very short delay in ZBasic
Posted: Mon Mar 19, 2018 1:35 am
Hi forum,
First time posting here
This question might belong in the general ZBasic category. I have some generic transistors (2n3904 and 2n3906) than could be on simultaneously (sort of in a totem pole configuration). I don't want them to be on simultaneously.
Now these supposedly are pretty fast with 250MHz switching, but if they were a lot slower for some reason, e.g. 4MHz, then would it be a problem in I switch one OFF and the next program statement (native mode or C) switch the other ON.
I think that the Off and On signals will come just a clock or 2 apart. IOW, at least at a speed of 7.3MHz. The slow transistors switch more slowly than that, so it might be possible for both to be partly ON at the same time. It would only be brief, but I guess that it would not be "good" to have happen anyway.
What is done about this by real engineers?
If I want to create a very short delay, the equivalent of a "NOP" in C or Assembler, how do I do that in ZBasic? I see PulseOut is only good for about 2uS (29 clocks?) which is longer than I would prefer. Do we know the precise shortest duration of a PulseOut in clock cycles and what arg would I give PulseOut for get it?
It looks as if adding a short delay between turning one off and the other on is a good idea.
On a VM chip, consider the code below which toggles two different output pins (assuming they've previously been configured to be outputs). On a ZX-24p, the delay from the first pin changing to the second pin changing is about 9.6uS.
That is longer than I had planned on the delay between turning one off and the other on. Even a really slow 1MHz power transistor has a storage time of 5uS, so 9.6uS is fine.
The side effect of this issue is significant for my project. I am building an Equivalent Series Resistance meter . It uses an 8uS pulse to briefly charge a capacitor. Assuming the capacitor is discharged when tested, then the voltage across the cap is proportional to the ESR.
But if the minimum time between turning a pin on then off is 9.6uS, then I can not achieve that rather short pulse time. I had thought about turning a pin on, then doing a ~8uS pulse out, then turning it off. Clearly, that will not be effective!
I had also considered setting up a timer to have a 8uS high time and a 492uS low time. Then I could poll the output pin for a falling edge, then when found, check the comparator interrupt flag to see if it saw a transition. the precise duration of the pulse is not too important, but the repetition rate is pretty important. It needs to be close to 2KHz.
What this tells me, the timing is so tight that I need to reconsider how I am achieving the result. This will be a little harder than I thought. Isn't that always true. I probably need to use a timer with a 8us pulse and a 500uS period. I may need to use two channels to control the two transistors independently. This will be fun.
Any thought?
First time posting here
This question might belong in the general ZBasic category. I have some generic transistors (2n3904 and 2n3906) than could be on simultaneously (sort of in a totem pole configuration). I don't want them to be on simultaneously.
Now these supposedly are pretty fast with 250MHz switching, but if they were a lot slower for some reason, e.g. 4MHz, then would it be a problem in I switch one OFF and the next program statement (native mode or C) switch the other ON.
I think that the Off and On signals will come just a clock or 2 apart. IOW, at least at a speed of 7.3MHz. The slow transistors switch more slowly than that, so it might be possible for both to be partly ON at the same time. It would only be brief, but I guess that it would not be "good" to have happen anyway.
What is done about this by real engineers?
If I want to create a very short delay, the equivalent of a "NOP" in C or Assembler, how do I do that in ZBasic? I see PulseOut is only good for about 2uS (29 clocks?) which is longer than I would prefer. Do we know the precise shortest duration of a PulseOut in clock cycles and what arg would I give PulseOut for get it?
It looks as if adding a short delay between turning one off and the other on is a good idea.
On a VM chip, consider the code below which toggles two different output pins (assuming they've previously been configured to be outputs). On a ZX-24p, the delay from the first pin changing to the second pin changing is about 9.6uS.
Code: Select all
Register.PinA = &H80
Register.PinA = &H40
That is longer than I had planned on the delay between turning one off and the other on. Even a really slow 1MHz power transistor has a storage time of 5uS, so 9.6uS is fine.
The side effect of this issue is significant for my project. I am building an Equivalent Series Resistance meter . It uses an 8uS pulse to briefly charge a capacitor. Assuming the capacitor is discharged when tested, then the voltage across the cap is proportional to the ESR.
But if the minimum time between turning a pin on then off is 9.6uS, then I can not achieve that rather short pulse time. I had thought about turning a pin on, then doing a ~8uS pulse out, then turning it off. Clearly, that will not be effective!
I had also considered setting up a timer to have a 8uS high time and a 492uS low time. Then I could poll the output pin for a falling edge, then when found, check the comparator interrupt flag to see if it saw a transition. the precise duration of the pulse is not too important, but the repetition rate is pretty important. It needs to be close to 2KHz.
What this tells me, the timing is so tight that I need to reconsider how I am achieving the result. This will be a little harder than I thought. Isn't that always true. I probably need to use a timer with a 8us pulse and a 500uS period. I may need to use two channels to control the two transistors independently. This will be fun.
Any thought?