27.11.2012 Views

Diseño y construcción de tricicleta solar - GEA - Universidad ...

Diseño y construcción de tricicleta solar - GEA - Universidad ...

Diseño y construcción de tricicleta solar - GEA - Universidad ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ANEXO A.1: Algoritmo <strong>de</strong>l programa principal<br />

<strong>de</strong>fine F_CPU 16000000UL<br />

#inclu<strong>de</strong> <br />

#inclu<strong>de</strong> <br />

#inclu<strong>de</strong> <br />

#inclu<strong>de</strong> <br />

#inclu<strong>de</strong> <br />

#inclu<strong>de</strong> "enco<strong>de</strong>r.h"<br />

#inclu<strong>de</strong> "pid.h"<br />

#inclu<strong>de</strong> "motorDC.h"<br />

#inclu<strong>de</strong> "adc.h"<br />

#inclu<strong>de</strong> "uart.h"<br />

int cont1=0;<br />

int cont2=0;<br />

int aa;<br />

float Pmotor;<br />

float Pmotor_ant=0;<br />

float Pmax=1;<br />

float Vpanel;<br />

float Vpanel_ant=0;<br />

float Thum;<br />

int flag1=0;<br />

int flag2=0;<br />

float cambio1=1.2;<br />

float cambio2=2;<br />

float cambio3=2.8;<br />

void initEnco<strong>de</strong>r(){ (){<br />

}<br />

enco<strong>de</strong>rCount=0;<br />

enco<strong>de</strong>rCountDist=0;<br />

pwmSelect=1;<br />

// Quadrature Read (PE4 and PE6) and Int.(PE5 and PE7) Pins as input.<br />

DDR_ENCODER &= ~(ENCIN);<br />

//ENCODER<br />

//INT0 - triggered on rising edge<br />

MCUCR |= |= (_BV(ISC01) | _BV(ISC00)); ));<br />

// Enable External interrupts on INT0.<br />

GICR |= |= (_BV(INT0)); )); ));<br />

// Seteo <strong>de</strong> timer para medir velocidad<br />

// timer2 en modo CTC<br />

TCCR2 |= |= _BV(WGM21); ); );<br />

// CS22=1, CS21=1, CS20=0 clkIO/256 (From prescaler) f=clkIO/(256*510)=122.54Hz<br />

TCCR2 |= |= (_BV(CS22) | _BV(CS21)); ));<br />

//Valor <strong>de</strong> OCR2 que genera interrupcion para<br />

OCR2=255;<br />

// interrupcion por compare match<br />

TIMSK |= |= (_BV(OCIE2)); ));<br />

//INTERRUPCION DEL ENCODER<br />

SIGNAL(INT0_vect){ ){ ){<br />

enco<strong>de</strong>rCount++; ++;<br />

enco<strong>de</strong>rCountDist++; ++;<br />

}<br />

void initLed() ()<br />

{<br />

//Inicializa pines <strong>de</strong>l puertoC como salida<br />

DDRC|= _BV(DDC0);<br />

DDRC|= _BV(DDC1);<br />

DDRC|= _BV(DDC2);<br />

DDRC|= _BV(DDC3);<br />

DDRC|= _BV(DDC4);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!