PRU pins

I am having a very strange issue trying to send pulses on the the P8_11 and P8_12 pins using pru0. The intent is to create a 100kHz pulse on P8_11 and periodically send a pulse on P8_12. I’ve tried using bit shifting and straight hex values and get the same results. As you can see in the code, the P8_11 and P8_12 pulses are sent to __R30 by a single line of code. However, using a logic analyzer, it shows the pulses being generated at separate times and the P8_12 pulse immediately reverts back to high after it is set low. It should not change to high until told to by the code.

Here is the code and logic analyzer results. Any ideas would be appreciated.

#include <stdint.h>

#include <pru_cfg.h>

#include “resource_table_empty.h”

// Clock is P8_11 - Bit 15 on __R30

// Start is P8_12 - Bit 14 on __R30

#define STOPPED 0 // Sensor is in Stopped state (Start pulse is high)

#define STARTING 1 // Sensor is in Starting state (Start pulse is low)

#define RUNNING 2 // Sensor is in Running state (Start pulse is high)

volatile register uint32_t __R30;

volatile register uint32_t __R31;

void main(void)

{

volatile uint32_t gpio; // gpio as sent to the register

volatile int clock = 1; // Define clock pulse and begin it high

volatile int sensorState = STOPPED; // Define sensor state

volatile int resetCount = 0; // Test counter for start pulse

/* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */

CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;

while(1){

if (clock == 1){ // Check for Start pulse on high clock cycle

resetCount++;

if (resetCount > 100){

resetCount = 0;

sensorState = STOPPED;

}

if (sensorState == STOPPED){ // Sensor is in stopped mode gpio = 0x8000; // Set Clock high, Start pulse low

sensorState = STARTING; // ISensor is in starting state

}

else if (sensorState == STARTING){ // Sensor in start mode gpio = 0xC000; // Set Clock high, Start high

sensorState = RUNNING; // Sensor is in running state

}

else{ // Sensor in running or stopping mode

gpio = 0xC000; // Set Clock high, Start high

}

}

else{

if (sensorState == STARTING){ // Sensor in start mode

gpio = 0x0000; // Set Clock low, Start low

}

else{

gpio = 0x4000; // Start is always high unless STARTING

}

}

__delay_cycles(1000);

__R30 = gpio; // Output appropriate clock and start pulses

if (clock == 1){

clock = 0;

}

else{

clock = 1;

}

}

}

image.png

The Start pulse should be low for the duration of one clock pulse being low.

Thanks

Mike Pitman

So, I’m having a hard time following your code there, based on what you’re explaining in English. We’ll just chalk that up to you code your way, I code mine, blah blah blah . . .

But what’s bothering me is this bit of(condensed ) code:

while(1){
if (clock == 1){ // Check for Start pulse on high clock cycle
. . .
}
__delay_cycles(1000);
__R30 = gpio; // Output appropriate clock and start pulses

if (clock == 1){
clock = 0;
}
else{
clock = 1;
}
}

You have two independent checks of the same variable. This may work, but is also a potential problem. I say “may” because I’m having a hard time following what you’re saying you’re trying to accomplish in English versus your code. I’m missing something. In order to fix this I would:

while(1){
if (clock == 1){ // Check for Start pulse on high clock cycle
clock = 0;
. . .
}
else{
clock = 1;
}
__delay_cycles(1000);
__R30 = gpio; // Output appropriate clock and start pulses
}

Another thing I’m having a hard time figuring out is why your clock state is binary, pulse cycle seems to be tri-state. But I’m not convinced I need to worry about that.

As for why your pin is not “sticking” low until to go high. My first instinct is there is a logic flaw in your code. However, something else did cross my mind. Is that pin floating ? Or is there a weak pullup / pulldown on it ?