CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problems with ccs software about a digital tachometer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lucas



Joined: 17 May 2011
Posts: 5

View user's profile Send private message

problems with ccs software about a digital tachometer
PostPosted: Wed Jun 08, 2011 6:58 am     Reply with quote

hi all!
My project consist of a digital tachometer where on the display LCD 16x2 I can see the rpm And based on the number of rpm, PIC light up 8 LEDs for ex: 1000 rpm: led1=ON; 2000 rpm: led2=ON; ......
and on the display: Round for min: . . . . . .
So the motor is simulated by an electric motor of 1000-20.000 rpm (rpm depends on astable multivibrator duty cycle varies from 0-50% with a potentiometer 10k).
The motor drives an encoder and using a photo interrupter 0-5v, that each round sends to PIC impulse 0-5v. When the speed increases the period change. Signals enters in RB0 of the PIC (I use a PIC16F628A).
The end of everything I have some problems with program: I see on display the variable rpm, but it hasn't a correct value, it change everytime high value and low value. I don't know. Can someone help me? Why the program work bad?
Thank you Smile

ps: 366211 is the result of some calculations and i think that is good.
Code:

//DIGITAL TACHOMETER WITH PIC 16F628A SEPE-SCAPARRA project

#include "D:\Contagiri_\main.h"
#include "D:\Contagiri_\flex_lcd.c"
unsigned int8  tempo=0;    //time=0
         
float numero_giri_min=0;   //rpm=0

#int_TIMER0
void  TIMERO_isr(void)
{

}

#int_EXT
void  EXT_isr(void)
{

tempo = get_timer0();   //the signal enters in RB0 and i get the number of   timer0

if (tempo != 0) numero_giri_min = 366211/tempo; //if (time!=0)  rpm=366211/time

else numero_giri_min =999999;                   //condition which never     occurs

set_timer0(0);

}
void main()
{

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64); //prescaler of 64
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_EXT);               
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
 
   set_tris_a(0);
   set_tris_b(1);
   output_a(0);
   output_low(PIN_B1);
   output_low(PIN_B2);
   output_low(PIN_B3);
   output_low(PIN_B4);
   output_low(PIN_B5);
   output_low(PIN_B6);
   output_low(PIN_B7);

      lcd_init();             //initialization display
      delay_ms (100);
     
      delay_ms (70);          //initial play of lights
      output_bit(PIN_B2,1);   //led ON1,2,3,4,5,6,7,8
      delay_ms (70);
      output_bit(PIN_B1,1);
      delay_ms (70);
      output_bit(PIN_B3,1);
      delay_ms (70);
      output_bit(PIN_A0,1);
      delay_ms (70);
      output_bit(PIN_A4,1);
      delay_ms (70);
      output_bit(PIN_A3,1);
      delay_ms (70);
      output_bit(PIN_A2,1);
      delay_ms (70);
      output_bit(PIN_A1,1); //the last led are flashing * 3times
      delay_ms (70);
      output_bit(PIN_A1,0);
      delay_ms (70);
      output_bit(PIN_A1,1);
      delay_ms (70);
      output_bit(PIN_A1,0);
      delay_ms (70);
      output_bit(PIN_A1,1);
      delay_ms (70);
      output_bit(PIN_A1,0);
      delay_ms (70);
      output_bit(PIN_A2,0);
      delay_ms (70);
      output_bit(PIN_A3,0);
      delay_ms (70);
      output_bit(PIN_A4,0);
      delay_ms (70);
      output_bit(PIN_A0,0);
      delay_ms (70);
      output_bit(PIN_B3,0);
      delay_ms (70);
      output_bit(PIN_B1,0);
      delay_ms (70);
      output_bit(PIN_B2,0);   //then all led OFF 8,7,6,5,4,3,2,1
      delay_ms (70);
   
while (1)
{
     
      printf(lcd_putc,"\fNumero \ndi Giri:%5.0frpm",numero_giri_min);    //show on display rpm (numero_giri_min means rpm)
      delay_ms (250);

if (numero_giri_min>1000)     //if rpm are > 1000
      {
      output_bit(PIN_B2,1);   // so led on portB,2 ON
     
      }
      else           
      {
      output_bit(PIN_B2,0);   // otherwise portB,2 OFF
      }

if (numero_giri_min>2000)
      {
      output_bit(PIN_B1,1);
     
      }
      else
      {
      output_bit(PIN_B1,0);
      }
if (numero_giri_min>3000)
      {
      output_bit(PIN_B3,1);
     
      }
      else
      {
      output_bit(PIN_B3,0);
      }
}

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group