I attempted to create controlled hardware flag indicators to asynchronously show, in real time, the reletavie occurance of events in our programs. To this end, I created two indicator pulses with I named Test_Sig_Start and Test_Sig_End:
Test.h:
Gpio gpioOut1, gpioOut2;
int gOutputPinAsync1 = 26; // This is the GPIO number for Asynchronous output.
// Associated with P8_14!
int gOutputPinAsync2 = 27; // This is the GPIO number for Asynchronous output.
// Associated with P8_17!
int gOutputPinS = 0; // This is the GPIO number for Synchronous output.
//DIGITAL 0 - Corresponds to P8_07
bool gStatus = 0;
bool gStatus1 = 0;
int i=0;
void Test_Sig_Start()
{
gpioOut1.write(1); //write the status to the LED (gOutputPin)
gpioOut1.write(0); //write the status to the LED (gOutputPin)
}
void Test_Sig_End()
{
gpioOut2.write(1); //write the status to the LED (gOutputPin)
gpioOut2.write(0); //write the status to the LED (gOutputPin)
}
I used these in my test render() application:
/* TEST3
In this exercise, I toggle two digital outputs.
One (gOutputPinS) is synchronous with the BELA timing, operating under the disciplines of
digitalWrite(context, n, gOutputPinS, gStatus);
The other outputs, (gOutputPinA) operate in an asynchronous mode, operating under the disciplines of
gpioOut.
*/
#include <Bela.h>
#include <Gpio.h>
#include <Test.h>
float gInterval = 0.0001; // how often to toggle the LED (in seconds). Set to 100 uSec.
int gCount = 0; //counts elapsed samples
bool setup(BelaContext *context, void *userData)
{
Test_Setup(context, userData);
return true;
}
void render(BelaContext *context, void *userData)
{
for(unsigned int n = 0; n < context->digitalFrames; ++n){
if(gCount == (int)(context->digitalSampleRate * gInterval)){ //if enough samples have elapsed
gCount = 0; //reset the counter
// Test_Sig_End(); // Second pulse.
Test_Sig_Start(); // First pulse.
Test_Sig_End(); // Second pulse.
// Test_Sig_Start(); // First pulse.
if (gStatus1 == 0)
{
rt_printf("Time elapsed: DigitalSampleRate = %f AnalogSampleRate = %f Interval = %f Sec. Digital frames = %i Analog frames = %i\n",context->digitalSampleRate,context->analogSampleRate,gInterval, context->digitalFrames, context->analogFrames);
gStatus1 = 1;
}
// Test_Sync(context, n);
// gpioOut.write(gStatus); //write the status to the LED (gOutputPin)
}
gCount++;
}
}
void cleanup(BelaContext *context, void *userData)
{
// Nothing to do here
}
When I apply the START pulse or the END pulse seperately, they work and appear OK. A single such pulse is created every BELA frame.
Each pulse has a width of about 180 nSec. (Is this reasonable or acceptable?)
When I apply a (single) START and then an END pulse, or vice versa, I get the proper results, as shown in the attached images. The END pulse is, in fact, delayed by about 230 nSec. after the finish of the START pulse.
The problem appears when I try to create duplicate or more pulses of the same type:
a) Two consecutive START pulses or more – only the first is implemented!
b) END-START-END sequence – only the START-END is implemented!
c) START-END-START sequence – only the END-START is implemented!
d) Etc.
Another issue is the following:
If I want to create a software controlled delay between the START and END pulses
(for example,
Test_Sig_Start();
for (int i=0; i<100; i++); // Do nothing - artificial delay!!
Test_Sig_End();
Or something primitive of that nature)
The START and END pulses are not affected at all – they appear in the same time location as they do without the intermediate software commands. It appears that the physical asynchronous outputs are not governed by the actual software sequencing!
Can you please explain how I can fix it so that these physical outputs represent the actual time event within the software implementation.