fbpx

Expresate

Si además quieres enviarnos un Artículo para el Blog y redes sociales, pulsa el siguiente botón:

Avisos
Vaciar todo

GPIO de la raspberry lentisimo

6 Respuestas
2 Usuarios
0 Likes
5,734 Visitas
fusion
Respuestas: 391
Topic starter
(@fusion)
Ardero
Registrado: hace 17 años

He hecho el siguiente programa y lo he cargado en la raspberry, empleando para cronometrar la libreria chrono de C++11

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> //read, write, close, usleep
#include <fcntl.h> //constantes: O_RDWR, O_NOCTTY
#include <termios.h> //rs232
#include <time.h>
#include <chrono>
#include "mmapGpio.h"//gpio OJO!!! modificar base address 0x20 a 0x3F para raspberry2
#include "mmapGpio.cpp"//gpio

mmapGpio rpiGpio1; // instantiate an instance of the mmapGpio class

//20*10/9600=20.83ms
void delay_ms(long int ms) { timespec t1,t2;t1.tv_sec=0;t1.tv_nsec=ms*1000*1000; nanosleep(&t1,&t2); }
void delay_us(long int us) { timespec t1,t2;t1.tv_sec=0;t1.tv_nsec=us*1000; nanosleep(&t1,&t2); }
void delay_mbps(long int mbps) {timespec t1,t2;t1.tv_sec=0;t1.tv_nsec=mbps*(500000000L/BAUDRATE); nanosleep(&t1,&t2); }//cambio #V023

//configura gpio outputs e inputs:
void init_gpio();
//Lee estado del puerto de entrada
int lee_puerto(int puerto) { if (rpiGpio1.readPin(puerto) == mmapGpio::HIGH) return 1;else return 0;}
void pone_puerto(int puerto,int estado) { if (estado) rpiGpio1.writePinHigh(puerto );else rpiGpio1.writePinLow( puerto );}

using namespace std;
using namespace std::chrono;

class halla_tiempo_c
{
public:
high_resolution_clock::time_point t1,t2;
void inicia() { t1= high_resolution_clock::now(); }
double halla_tiempo() //retorna el tiempo en segundos
{
t2= high_resolution_clock::now();
duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
return time_span.count();
}
};

int main()
{
halla_tiempo_c tiempo1;
printf("===inicio prueba de reloj cronometrando 50 segundos, dar a entern");getchar();
tiempo1.inicia();
while (tiempo1.halla_tiempo()<50);
printf("===fin prueba de reloj cronometrando 50 segundos===============n");

pone_puerto(3,0);delay_ms(1);
printf("nInicializo y compruebo GPIOs:n");
init_gpio();
int uart_str;
printf("nInicializo y compruebo RS232:n");
rs232_setup(uart_str);
if (uart_str == -1) return -1;
long i,maxi=10000000L,j=0;
tiempo1.inicia();
for (i=0;i<maxi;i++)
{
pone_puerto(3,1);
while( lee_puerto(2)!=1) j++;
pone_puerto(3,0);
while( lee_puerto(2)!=0) j++;
}
double t2=tiempo1.halla_tiempo();
double frecuencia;
frecuencia=1.0*maxi/t2/1.0e6;
printf("nTiempo=%lg Frecuencia=%lg Mhzn",t2,frecuencia);
return 1;
}

void init_gpio()
{
//inputs:
rpiGpio1.setPinDir( 2,mmapGpio::INPUT);
//outputs:
rpiGpio1.setPinDir( 3,mmapGpio::OUTPUT);
}

Entonces he puenteado la GPIO02 con la GPIO03 y segun mi programa pongo un 1 y un 0 a una frecuencia de 2.57Mhz

He usado para ello la libreria mmapGpio

¿Teneis alguna manera de hacerlo más rapido?

Responder
5 respuestas
fusion
Respuestas: 391
Topic starter
(@fusion)
Ardero
Registrado: hace 17 años

Pues si, y he acabado en un post de uno que hace una radio FM a 103Mhz, pero para mis usos es demasiado complicado.

Es curioso que en el articulo que Phyton sea tan lento (28khz) y amenacen de que java sea de ese orden también 🙂

Responder
Página 2 / 2
Compartir: