05-11-2008 10:29 PM
#include "xparameters.h"
#include "xgpio.h"
#include "stdio.h"
#include "xutil.h"
#include "xuartlite.h"
#include "xspi.h"
//*********declaracion de variables****************
int AC_DC_GND, arturo=1, jose=0, status;
long ADC_CH1, ADC_CH2, contador=0;
//decalraciond e instancias para modulos***********
XGpio acoples;
XGpio estado;
XGpio platano;
XGpio ADC_12bit;
XSpi control_adc;
//inicializacion de instancias ********************
INICIACION_INSTANCIAS(){
XGpio_Initialize (&estado, XPAR_LEDS_8BIT_DEVICE_ID);
XGpio_Initialize (&ADC_12bit, XPAR_DATOS_CONVERSOR_DEVICE_ID);
XGpio_Initialize (&acoples, XPAR_DIPS_4BIT_DEVICE_ID);
XGpio_Initialize (&platano, XPAR_BTNS_4BIT_DEVICE_ID);
XSpi_Initialize (&control_adc, XPAR_CONTROL_CONVERSOR_DEVICE_ID);
XSpi_SetOptions (&control_adc, XSP_MASTER_OPTION);
XSpi_SetSlaveSelect (&control_adc, 0x1);
}
//*************************************************
int main(void){
INICIACION_INSTANCIAS();
arturo=1;
jose=0;
//status=status++;
while(1){status=status++;
ADC_CH1 = XGpio_DiscreteRead (&ADC_12bit, 1);
ADC_CH2 = XGpio_DiscreteRead (&ADC_12bit, 2);
AC_DC_GND = XGpio_DiscreteRead (&acoples, 1);
XGpio_DiscreteWrite (&estado, 1, arturo);
XGpio_DiscreteWrite (&acoples, 2, AC_DC_GND);
XGpio_DiscreteWrite (&estado, 1, jose);
if(status <= 127){ XGpio_DiscreteSet(&estado, 1, 0x00); }else{XGpio_DiscreteSet(&estado, 1, 0xff); };}
}
05-12-2008 12:43 PM
05-13-2008 08:39 AM
05-13-2008 12:43 PM
50 KHz is pretty good. The 50 MHz system clock divided by the 256 counter is about 200 KHz, so if your output is 50 KHz that means that your loop is only taking four instructions per iteration, much better than I expected. Those functions apparently must be inlines.
What kind of "ports" are you trying to acquire at 4 MHz? If they're just a single bit each, you should probably build a shift register and holding register to collect 32 samples into a word, so the Microblaze can deal with them 32 bits at a time rather than one bit at a time. If they're wider, e.g., 8 bits or more, you might need DMA.
The Microblaze isn't magic; by itself it can't do anything that any other 50 MHz RISC processor can't do. If you need a 50 MHz processor to deal with a 4 MHz signal, that means you only get 12.5 instructions (on average) to deal with each sample, which isn't very much. The benefit of Microblaze is that it's in an FPGA, so you can easily add additional hardware to it such as DMA controllers, shift registers, etc.
05-13-2008 12:50 PM
By the way, is "status" really an int? I wasn't looking closely enough at the code before, and assumed you were using a char or unsigned char, which would overflow every 256 counts. An int is 32 bits (I think), so it would only overflow every four billion counts.
And you shouldn't write "status=status++"; the result of that is undefined. Just write either "status++" or "status=status+1".
Also, "status" isn't really a very good name for a counter. How about "count"?
05-16-2008 12:00 PM