speed meter with 18f452

General discussion on mikroC.
Post Reply
Author
Message
Kishar
Posts: 14
Joined: 29 Sep 2008 15:40
Location: Italy

speed meter with 18f452

#1 Post by Kishar » 06 Oct 2008 19:12

Hi to all! 8)
:D
i'm going to realize a speed meter with an 18f452...
i spent all the day reading datasheet! :?

but i don't know if the registers configuration is right for my idea.

here's the code:

Code: Select all

void boot(){

INTCON  = 0b10110000;
INTCON2 = 0b11000000;
INTCON3 = 0b11000000;
T0CON   = 0b10001000;

ADCON1 = 0x07;                       // configure VDD as Vref, PORTA pins as analog, PORTB pins as digital
TRISA  = 0xFF;                       // designate PORTA as input
TRISD  = 0x00;                       // designate PORTA as output
TRISB  = 0xFF;                       // designate PORTB as input

//debug
TRISE  = 0b00000000;



LCD_Init(&PORTD);
Lcd_Cmd(Lcd_CURSOR_OFF);             // Turn cursor off
Ps2_Init(&PORTC);
Delay_ms(100);                       // attesa inizializzazione tastiera
}

/*********************************/
unsigned speed(){


                while(overflow < 23437) ;         // wait 1 second : 23437 = 24 000 000 / 4 / 256, rounded up
                speed_value = (((diameter / 1000) * (628 / 100))* wheel_counter); // /2 if 2 reed are used m/s    and *3.6 for Km/h
                longtostr(overflow, text);
                LCD_Out(1,1, text );
                wheel_counter = 0 ;              // clear counters
                overflow = 0 ;
                longtostr(overflow, text);
                LCD_Out(1,1, text );
               //comment line ->debug speed_value = 8 ;
return speed_value;
}
/******************************************/

void    interrupt(void)
        {
        if(INTCON.INT0IF)
                {
                /*
                 * RB0 interrupt
                 */
                wheel_counter++ ;                // inc. transition counter
                INTCON.INT0IF = 0 ;       // clear interrupt flag to enable next call
                }
        else if(INTCON.TMR0IF)
                {
                /*
                 * TIMER 0 overflow
                 */
                overflow = 0;              // inc. overflow counter
                INTCON.TMR0IF = 0;       // clear interrupt flag to enable next call on overflow
                }
        }

/*******************************************/
void main(){
      //speed code
      Lcd_Cmd(LCD_CLEAR);
      Lcd_Out(1,1,"#Speed value:  #" );
      while(exit_loop==0){

              if((Ps2_Key_read(&key,&special,&down)) && down && (key==34)) { exit_loop=1;exit_add=1;}

              InttoStr(speed(), text_speed);
              LCD_Out(2,14,"m/s");
              Delay_ms(150);

              } //fine loop principale
        }//end if key 50
}//end loop exit_add
}

as seen in boot() i use an adc, a lcd and a ps2 keyb...
this code is only an extract of whole program that works fine!
only i need to say if this registers configuration is ok because it seems to freeze! :(

thank to all!
Women and cats do what they want ... men and dogs should relax and get used to this idea!

dariush_abbasi
Posts: 120
Joined: 11 May 2008 18:47

#2 Post by dariush_abbasi » 06 Oct 2008 20:28

Again freezing????????

idakota
Posts: 334
Joined: 27 Sep 2006 08:07
Location: Pretoria/South Africa
Contact:

#3 Post by idakota » 06 Oct 2008 20:32

Your not calling your boot function anywhere....

Kishar
Posts: 14
Joined: 29 Sep 2008 15:40
Location: Italy

#4 Post by Kishar » 06 Oct 2008 21:21

this code is only an extract of whole program that works fine!
It's only an extract! :D
Women and cats do what they want ... men and dogs should relax and get used to this idea!

sobiakulasekaran
Posts: 2
Joined: 24 Jan 2011 09:56
Location: Hosur
Contact:

Re: speed meter with 18f452

#5 Post by sobiakulasekaran » 24 Jan 2011 10:09

Hi Frnd .... I need a help .. I'm doing a project for finding slope of a surface using adxl335 a three axis accelerometer.. In tat i need a formula to convert voltage to degree.. Can u Pls help me wit tis.. :?: :?:
(¨`•.•´¨)
`•.¸(¨`•.•´¨)
(¨`•.•´¨)¸.•´
`•.¸.•´SOBIA.K

Post Reply

Return to “mikroC General”