I have a ZyBo circuit board which has a ArmV7 processor. I wrote a C program to output a clock and a corresponding data sequence on a PMOD. The PMOD has a switching speed of up to 50MHz. However, my program's created clock only has a max frequency of 115 Hz. I need this program to output as fast as possible because the PMOD I'm using is capable of 50MHz. I compiled my program with the following code line:
gcc -ofast (c_program)
Here is some sample code:
#include <stdio.h>
#include <stdlib.h>
#define ARRAYSIZE 511
//________________________________________
//macro for the SIGNAL PMOD
//________________________________________
//DATA
//ZYBO Use Pin JE1
#define INIT_SIGNAL system("echo 54 > /sys/class/gpio/export"); system("echo out > /sys/class/gpio/gpio54/direction");
#define SIGNAL_ON system("echo 1 > /sys/class/gpio/gpio54/value");
#define SIGNAL_OFF system("echo 0 > /sys/class/gpio/gpio54/value");
//________________________________________
//macro for the "CLOCK" PMOD
//________________________________________
//CLOCK
//ZYBO Use Pin JE4
#define INIT_MYCLOCK system("echo 57 > /sys/class/gpio/export"); system("echo out > /sys/class/gpio/gpio57/direction");
#define MYCLOCK_ON system("echo 1 > /sys/class/gpio/gpio57/value");
#define MYCLOCK_OFF system("echo 0 > /sys/class/gpio/gpio57/value");
int main(void){
int myarray[ARRAYSIZE] = {//hard coded array for signal data
1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,1,0,0,1,1,0,1,0,0,0,0,0,1,0,0,1,1,1,0,0,1,1,1,0,1,1,1,1,0,0,1,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,1,0,1,0,0,1,0,1,1,0,1,0,1,1,0,0,1,1,1,1,0,0,1,0,1,0,0,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,0,0,0,0,1,0,0,0,1,1,0,0,1,0,1,1,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,0,1,1,0,1,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,1,1,1,0,0,1,1,1,0,0,1,1,0,1,1,0,1,1,1,0,0,1,1,1,1,1,0,0,1,0,1,0,1,0,1,1,0,1,0,0,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0,0,0,1,1,1,0,1,1,1,1,0,1,1,0,1,0,1,0,1,0,0,1,0,1,1,1,0,1,1,1,0,0,1,1,1,0,1,0,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,0,0,1,0,1,1,0,1,0,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,1,1,1,1,1,1,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,1,0,1,0,1,0,0,1,1,0,0,1,1,0,1,0,0,1,0,0,1,0,1,1,1,1,1,1,0,1,1,0,1,0,1,1,1,1,1,1,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,0,1,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0
};
INIT_SIGNAL
INIT_MYCLOCK;
//infinite loop
int i;
do{
i = 0;
do{
/*
1020 is chosen because it is twice the size needed allowing for the changes in the clock.
(511= 0-510, 510*2= 1020 ==> 0-1020 needed, so 1021 it is)
*/
if((i%2)==0)
{
MYCLOCK_ON;
if(myarray[i/2] == 1){
SIGNAL_ON;
}else{
SIGNAL_OFF;
}
}
else if((i%2)==1)
{
MYCLOCK_OFF;
//dont need to change the signal since it will just stay at whatever it was.
}
++i;
} while(i < 1021);
} while(1);
return 0;
}
I'm using the 'system' call to tell the system to output 1 volt or 0 volts onto a pin on the board (to represent the data signal and clock signal. One pin for the data and another for the clock). That was the only way I knew to tell the system to output a voltage.
What can I do to make my executable program output to be at least in the magnitude of MegaHertz?