Propeller C double pulses
Hi everyone,
I am trying to use the propeller to generate two very short pulses using C language for research purposes. I want to control each pulse timing and the time between them. The time has to be in nanoseconds (i.e. 100 ns).
Using pulse_out I was able to get a pulse width of 12.5 ns which is very good. The problem is with the 2nd pulse. writing two pulse_out commands won't do the job. I can control the timing of the first and 2nd pulses, but I am not able to control the time in between the two. Writing:
set_io_dt(1);
pulse_out(0,1);
pulse_out(0,1);
would give me two pulses of 12.5 ns with a huge 100 us in between.
is there another way to implement this? I can do this in PASM, but I want to use C language.
Thanks
I am trying to use the propeller to generate two very short pulses using C language for research purposes. I want to control each pulse timing and the time between them. The time has to be in nanoseconds (i.e. 100 ns).
Using pulse_out I was able to get a pulse width of 12.5 ns which is very good. The problem is with the 2nd pulse. writing two pulse_out commands won't do the job. I can control the timing of the first and 2nd pulses, but I am not able to control the time in between the two. Writing:
set_io_dt(1);
pulse_out(0,1);
pulse_out(0,1);
would give me two pulses of 12.5 ns with a huge 100 us in between.
is there another way to implement this? I can do this in PASM, but I want to use C language.
Thanks
Comments
It sure is faster, but not fast enough. it reduces from 100 us to 25 us.
I would recommend you look into writing your timing critical code in one of the following methods:
* C/C++ with the appropriate method(s) forced into fcache
* Inline assembly with the assembly block forced into fcache
* C/C++ compiled as "cogc", such that it is compiled to native PASM and executed in a dedicated cog
* Raw PASM (PASM and GAS syntax are both supported by newer versions of PropGCC), running in a dedicated cog
https://github.com/parallaxinc/PropWare/blob/develop/PropWare/serial/uart/uarttx.h#L103
1us on the Prop is 80 clock cycles, or 20 instructions. Interpreted code isn't likely going to be fast enough.
-hil
Everything is "available." But to be less pedantic, what exactly do you mean by that? Are you looking for C/C++ functions to wrap specific assembly instructions, like "waitcnt(a, b)" wraps "waitcnt a, b"?
-Phil
I've never actually used the video capabilities on the prop, so I don't know for sure, but is this what you're looking for? https://github.com/parallaxinc/propgcc/blob/5fc1abdabd91af35f92540696466b523333480b4/lib/include/propeller.h#L205
-Phil
I'm surprised to see those registers are defined in a different header file... but oh well.
int main()
{
low(0);
while(1)
{
__asm__(
" mov outa,#0\n\t "
" mov outa,#1\n\t"
);
}
This results in a very fast switching. A delay of 50 ns is achieved between the pulses. However, writing:
int main()
{
low(0);
__asm__(
" mov outa,#0\n\t "
" mov outa,#1\n\t"
" mov outa,#0\n\t "
" mov outa,#1\n\t"
" mov outa,#0\n\t "
);
}
results in a time delay of 200 ns between the pulses. The only difference is the "While" loop. I don't know why this would affect the execution speed of the assembly instructions.
Because the while loop is put into fcache that runs it at full cog speed (20 mips), while your "unrolled" loop executes at hubread speed (1/16 of the clock or 5 mips).