I seem to have discovered an anomaly with the __delay_cycles command trying
to get precise timing on the PRU's.  Jason asked that I post my results for
all to see.

My desire was to create a steady clock pulse on P8.11 and then set P8.12
low for just a single low cycle of P8.11.  Then P8.12 was to go back high.

In using the __delay_cycles command, the timing on P8.12 was extremely
random and would bounce back up to 3.3 volts immediately instead of staying
low for a clock cycle.  This can be seen in the following images.[image:
Inline image 1]
[image: Inline image 2]
[image: Inline image 3]

However, replacing the __delay_cycles command with a "for" loop created
output seen in the following image which is exactly what I needed.
[image: Inline image 4]

I have no idea why the __delay_cycles is working this way.  The really
strange thing is if I cause P8.12 to follow P8.11, i.e. to rise when P8.11
rises and fall when P8.11 falls, then the output is exactly as expected.
In fact, I can even make P8.12 to mirror P8.11 by causing it to fall when
P8.11 rises and rise when P8.11 falls but not to stay down for just one low
cycle of P8.11.  Another interesting note is that the assembly code
generated by the C compiler shows the delays exactly as one would expect
but the output is still random.  At any rate, the output pulses are as
desired by using the "for" loops.

Here is the pertinent code.  It contains both the working and non-working
code.  The non-working code is commented out and replaced with the "for"
loops that do work.

The variables that set __R30 are hex values pertaining to the appropriate
bits for pins P8.11 and P8.12.  For example, gpioClockHighStartLow =
0x8000, gpioClockLowStartLow = 0x0000, gpioClockHighStartHigh = 0xC0000 and
gpioClockLowStartHigh = 0x4000.

while(1){
for (resetCount = 0; resetCount < 100; resetCount++){
if (sensorState == STARTUP){ // Sensor is in startup mode
__R30 = gpioClockHighStartLow; //Set Clock High and Start Low
for (delayCount = 0; delayCount < 1000; delayCount++){
x++;
}
// __delay_cycles(1000);
__R30 = gpioClockLowStartLow; //Set Clock Low and Start Low
// __delay_cycles(1000);
for (delayCount = 0; delayCount < 1000; delayCount++){
x++;
}
sensorState = RUNNING; // Indicate sensor is in running state
}
__R30 = gpioClockHighStartHigh; //Set Clock High and Start High
// __delay_cycles(1000);
for (delayCount = 0; delayCount < 1000; delayCount++){
x++;
}
__R30 = gpioClockLowStartHigh; //Set Clock Low and Start High
// __delay_cycles(1000);
for (delayCount = 0; delayCount < 1000; delayCount++){
x++;
}
}
resetCount = 0;
sensorState = STARTUP;
}

If anyone can shed any light on what I'm seeing with the __delay_cycles
command I would be interested in hearing about it.  Thanks.

Mike Pitman

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/CAJ2u6KNt7WQwOkMFLKNXptKPDqXnGfZU0HwAO5bjJCbE1W9PoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to