lunes, 15 de junio de 2009

Segundo intento sdcc (12f675)

Mi segunda prueba, me demostró que aunque el sdcc me evite usar el ensamblador me siento más comodo programando en ensamblador, la costumbre es más fuerte.

En este caso estoy utilizando el conversor de ADC del PIC 12F675 para enviar la lectura de una foto resistencia (LDR) a la PC por medio de RS232

/* ----------------------------------------------------------------------- */
/* Template source file generated by piklab */
#include

/* ----------------------------------------------------------------------- */
/* Bits de configuración: adapte los parámetros a su necesidad */
typedef unsigned int word;
word at 0x2007 CONFIG = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_OFF & _CP_OFF & _CPD_OFF;

unsigned char Count,Temp,SerBuf;

#define Tx 1
#define Rx 2

void baud(unsigned char baudrate)
{
_asm
baud:
movlw D'16'
movwf _Count
baud1: decfsz _Count,F
goto baud1

half_baud:
movlw D'16'
movwf _Count
hbaud1: decfsz _Count,F
goto hbaud1
_endasm;
}

void recv_suart()
{
_asm
inch_n: btfsc GPIO,Rx
goto inch_n
movlw 8
movwf _Temp
clrf _SerBuf
call half_baud
;btfsc GPIO,Rx
;goto inch_n
inch_n1:
call baud
bcf STATUS,0
rrf _SerBuf,F
btfsc GPIO,Rx
bsf _SerBuf,7
decfsz _Temp,F
goto inch_n1
call baud
_endasm;
}

void send_suart()
{
_asm
outch_n:
;movwf _SerBuf
movlw 8
movwf _Temp
bcf GPIO,Tx
call baud
outch_n1:
rrf _SerBuf,F
btfss STATUS,0
bcf GPIO,Tx
btfsc STATUS,0
bsf GPIO,Tx
call baud
decfsz _Temp,F
goto outch_n1

rrf _SerBuf,F
bsf GPIO,Tx
call baud
call baud
_endasm;

}
void on_adc() {
_asm
movlw 0x01
movwf ADCON0
_endasm;
}

void off_adc() {
_asm
clrf ADCON0
_endasm;
}

void read_adc() {
_asm
bsf ADCON0,1
waitfc: btfsc ADCON0,1
goto waitfc
_endasm;
}
void initPIC()
{
/*Poner a Ceros el Puerto*/
_asm
BANKSEL GPIO
movlw 0x02
movwf GPIO
movlw 0x07
movwf CMCON
BANKSEL ANSEL
movlw 0x11
movwf ANSEL
movlw 0x0d
movwf TRISIO
BANKSEL GPIO
_endasm;
}

/*Rutina de Retardo*/
void delay(int ret) {
int r;
for(r=0;r<=ret;r++) { } } void main() { initPIC(); SerBuf=0x70; send_suart(); SerBuf=0x69; send_suart(); SerBuf=0x63; send_suart(); SerBuf=0x31; send_suart(); SerBuf=0x32; send_suart(); SerBuf=0x66; send_suart(); SerBuf=0x36; send_suart(); SerBuf=0x37; send_suart(); SerBuf=0x35; send_suart(); SerBuf=0x0D; send_suart(); recv_suart(); send_suart(); while(1){ on_adc(); read_adc(); off_adc(); SerBuf=ADRESH; send_suart(); GP5=1; delay(20000000); GP5=0; delay(20000000); } }
Que es lo que hago:

1.- Envió a la PC pic12f675
2.- Espero a recibir cualquier caracter para iniciar las conversiones
3.- Después de hacer una lectura y enviar el resultado a la PC prendo y apago un led

Necesito más práctica para abandonar el uso del ensamblador cuando use el sdcc.

lunes, 1 de junio de 2009

Mi intento de aprender sdcc para PICs

Con el Piklab en Linux me decidí a aprender a usar el sdcc, de lo cual resultó esta pequeña obra de arte (si como no)


/* ----------------------------------------------------------------------- */
/* Template source file generated by piklab */
#include

/* ----------------------------------------------------------------------- */
/* Bits de configuración: adapte los parámetros a su necesidad */
typedef unsigned int word;
word at 0x2007 CONFIG = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _BODEN_OFF & _CP_OFF & _CPD_OFF;


void initPIC()
{
/*Poner a Ceros el Puerto*/
_asm
BANKSEL GPIO
clrf GPIO
movlw 0x07
movwf CMCON
BANKSEL ANSEL
CLRF ANSEL
movlw 0x0c
movwf TRISIO
BANKSEL GPIO
_endasm;
}

/*Rutina de Retardo*/
void delay(int ret) {
int r;
for(r=0;r<=ret;r++) { } }

void main() {
initPIC();
while(1){
GP5=1;
delay(10000);
GP5=0;
delay(10000);
}
}


Lo que quería aprender hacerlo en C, pero le terminé metiendo ensamblador para la configuración de los puertos, no puedo negar mis origenes.

jueves, 28 de mayo de 2009

Aceleración ATI Xpress Radeon 200M Jaunty

A partir de Jaunty la versión propietaria de los drivers de ATI dejaron de soportar algunas tarjetas, para los que necesiten tener mejor rendimiento que los controladores que vienen por default en Jaunty lo que se debe de hacer es recompilar mesa con el parche para radeon tal y como se muestra acontinuación:


1.- Instalamos todas las dependecias para poder compilar mesa.

sudo apt-get install autoconf
sudo apt-get build-dep mesa
sudo apt-get install libxmu-dev libdrm-dev x11proto-dri2-dev libxi-dev

2.- Descargamos las fuentes de mesa con el radeo-rewrite:

git clone git://anongit.freedesktop.org/git/mesa/mesa
cd mesa
git branch radeon-rewrite origin/radeon-rewrite
git checkout radeon-rewrite

3.- Procedemos a ejecutar el siguiente comando:

./autogen.sh --prefix=/usr --with-dri-drivers=radeon,r200,r300

4.- Si no hubo ningún error, de dependencias, podemos hacer el conocido:

make
sudo make install

Y tendremos el rendimiento de los drivers propietarios en Ubuntu 9.04
semael@anaconda2:~/tmp/mesa$ glxinfo | grep render
direct rendering: Yes
OpenGL renderer string: Mesa DRI R300 20090101 NO-TCL
semael@anaconda2:~/tmp/mesa$ glx
glxdemo glxgears glxheads glxinfo
semael@anaconda2:~/tmp/mesa$ glxgears
5097 frames in 5.0 seconds = 1019.280 FPS
5789 frames in 5.0 seconds = 1157.639 FPS
5767 frames in 5.0 seconds = 1153.326 FPS
5794 frames in 5.0 seconds = 1158.684 FPS
5799 frames in 5.0 seconds = 1159.756 FPS
5750 frames in 5.0 seconds = 1149.966 FPS
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
after 107180 requests (65066 known processed) with 0 events remaining.
semael@anaconda2:~/tmp/mesa$

El rendimiento que me estaba dando antes de efectua este proceso:

semael@anaconda2:~/tmp/mesa$ glxgears
1057 frames in 5.0 seconds = 211.367 FPS
1084 frames in 5.0 seconds = 216.691 FPS
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
after 8927 requests (41 known processed) with 0 events remaining.
semael@anaconda2:~/tmp/mesa$

Visto en: http://www.phoronix.com/forums/showthread.php?t=16554

domingo, 17 de mayo de 2009

Nueva funcionalidad Termómetro

Al programa le he agregado la posibilidad de guardar las mediciones en una base de datos en mysql además de graficar el comportamiento de la temperatura a lo largo del día.

Para ver el resultado puedes visitar aarmagnac.no-ip.org:1540 .

El proximo paso será hacer una pequeña red de sensores.

lunes, 9 de marzo de 2009

Montar directorios Remotos vía ssh

Suponiendo que tenemos un servidor ssh en la máquina remota y un usario al cual conectarnos procedemos a instalar el programa sshfs

sudo apt-get install sshfs

Creamos el Directorio local donde montaremos el directorio remoto

mkdir DRemoto

Y lo montamos de la siguiente forma:

sshfs user@mipcdesktop:/home/user/ DRemoto

el user debe tener permisos sobre el directorio que deseamos montar

para desmontarlo

sudo umount DRemoto

lunes, 23 de febrero de 2009

Hola Mundo con octave y c++

Requisitos:
Tener instalado octave, octave-headers y build-essential

En nuestro editor de texto predilecto (vim) escribimos lo siguiente


#include <octave/oct.h>
DEFUN_DLD(miHolaMundo, args, ,
"Sirve para imprimir un N Holas Mundo " )
{
unsigned int N = args(0).int_value(); //El argumento 0 lo convertimos a entero y
//se lo almacenamos en N

for(int i = 0; i<N;i++)
octave_stdout<<"Hola Mundo"<<endl;

return octave_value(0);
}

En la primera línea incluimos las cabeceras de octave y el la segunda definimos que nombre tendrá nuestra función. Guardamos el archivo con el mismo nombre de la función (miHolaMundo.cc) y compilamos

mkoctfile miHolaMundo.cc

Esto nos va a generar dos archivos:

miHolaMundo.o miHolaMundo.oct

donde miHolaMundo.oct es la función que acabamos de hacer.

Inicamos el octave y probamos:

octave:1> help miHolaMundo
Sirve para imprimir un Hola Mundo /home/s/proyectos/c/octave/miHolaMundo.oct

Additional help for built-in functions and operators is
available in the on-line version of the manual. Use the command
`doc ' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
octave:2>
octave:2> miHolaMundo(1)
Hola Mundo
ans = 0
octave:3> miHolaMundo(4)
Hola Mundo
Hola Mundo
Hola Mundo
Hola Mundo
ans = 0
octave:4>


El que sigue es parte del código para probar una Memoria RAM que esta dentro de un FPGA, lo recorte sólo para mostrar, como se usan Complejos y como se retorna a octave una o más variables. Esta función tiene como parametros de entrada un Vector Complejo, tamaño de la palabra y tamaño de la parte fraccional para convertir a punto fijo los valores del vector comlejo.



#include <octave/oct.h>
#include <iostream>
#include <fstream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <oct-rand.h>
#include <oct-cmplx.h>

//inline void dec2bin(unsigned int a,unsigned int width_word,char * cadena);
inline int to_fixed(double data_in, unsigned int QW,unsigned int QF);
inline double f2d(int Dfixed,unsigned QF);

DEFUN_DLD (MemTest,args, ,
"Probar RAM FPGA via RS232\n")
{

ComplexColumnVector Data = args(0).complex_column_vector_value();
int len = Data.length();
ComplexColumnVector DataF=Data;
ComplexColumnVector DataR=Data;
unsigned int QW=args(1).int_value();
unsigned int QF=args(2).int_value();

for (int i = 0; i<len;i++) {
real(DataF(i))=f2d(to_fixed(real(Data(i)),QW,QF),QF);
imag(DataF(i))=f2d(to_fixed(imag(Data(i)),QW,QF),QF);
};

octave_value_list retval;

retval(0) = octave_value(DataF);
retval(1) = octave_value(DataR);
return retval;
}

inline int to_fixed(double data_in, unsigned int QW,unsigned int QF)
{
int x_0=0,j=1;
//we need to convert to double to QW and QF because oct.h only have pow(double,double)
if(data_in<0){ int x_0=pow(2.0,double(QW)); };
return int(x_0+pow(2.0,double(QF))*data_in);
}
inline double f2d(int Dfixed,unsigned QF)
{
return double(Dfixed)/(pow(2.0,double(QF)));
}

Compilamos con mkoctfile y probamos

octave:1> x=randn(4,1)+j*randn(4,1)
x =

-0.80972 + 3.54049i
-0.38686 - 0.35778i
-0.45699 + 0.05577i
-0.48280 + 1.01243i

octave:2> MemTest(x,13,10)
ans =

-0.80957 + 3.54004i
-0.38672 - 0.35742i
-0.45605 + 0.05566i
-0.48242 + 1.01172i

octave:3> [y z]=MemTest(x,13,10)
y =

-0.80957 + 3.54004i
-0.38672 - 0.35742i
-0.45605 + 0.05566i
-0.48242 + 1.01172i

z =

-0.80972 + 3.54049i
-0.38686 - 0.35778i
-0.45699 + 0.05577i
-0.48280 + 1.01243i



Como se puede ver, el primer resultado que nos regresa nuestra función es equivalente en punto fijo de 13 bits de los cuales 10 bits son para la parte fraccional y 1 para el signo.

lunes, 16 de febrero de 2009

Mi Escritorio Ubuntu en la Acer One

Por fin tengo este juguetito para divertirme un rato y este es mi ubuntu con el compiz


Acer One:
Intel(R) Atom(TM) N270 a 1.6 Ghz
RAM: 1Gb
HD: 120 Gb

En el fondo se ve el Firefox, el gimp y la terminal ejecutando el comando top