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 support@ccsinfo.com

speedometer

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



Joined: 24 Mar 2015
Posts: 14

View user's profile Send private message

speedometer
PostPosted: Wed Apr 22, 2015 4:23 am     Reply with quote

Hi all, I probably did not explain what I wanted to do and not intended that you should do me the program, sorry if it seemed that.
I have connected to the pin 6 (RA4 / T0CK1) of PIC18F4550 inductive sensor. What I intend to do is the following. It is through a small wheel about 8 cm in diameter, it will give impetus by hand, so that it takes speed to simulate what would in the wheel of a motorcycle on a small scale. I'm trying to make the program through the TIMER0 count pulses (applying the formula for speed), but can not get it right and I'm rolling, if you could advise me. Thank you.

Code:

#include <18F4550.h>
#fuses NOWDT,XT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include "C:\Users\xx\Desktop\VELOCIDAD\flex_lcd420.c"

int16 counter;
float Velocidad=0;

#int_TIMER0
void TIMER0_isr(){
counter=get_timer0();    //lee contador TMR0
Velocidad= Counter * 25.13 * 0.036;
 printf(lcd_putc,"%61u vel", Velocidad);
lcd_gotoxy(1,1);
counter=0;
Velocidad=0;
set_timer0(0);                      //Reinicia cuenta

}

void main(){
lcd_init();

   setup_timer_0(rtcc_ext_l_to_h|RTCC_DIV_2);   //ConfiguraciĆ³n TMR0
   
   set_timer0(0);                               //Borrado contador
   
   enable_interrupts(global);
}
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 5:05 am     Reply with quote

hmm..
inductive sensor ...

Have you got an oscilloscope to see the output of the sensor ? The PIC needs a good ,clean squarewave NOT a lazy, AC waveform as the input.
Most inductive sensors I've used need 'signal conditioning' to get a proper,clean input to the PIC.

You should post a 'link' of the inductive sensor datasheet.

Also, it's a good idea to use a second PIC as a 'frequency generator' to use as a known signal source. AN 8 pin PIC can easily give you low, mid, high 'speed signals' for testing and calibrations.


Jay
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Apr 22, 2015 9:12 am     Reply with quote

Code:

Velocidad= Counter * 25.13 * 0.036;
 printf(lcd_putc,"%61u vel", Velocidad);
lcd_gotoxy(1,1);


GET THIS OUT OF THE ISR !!!!!!!!!!

and when you do - reduce this to a single operation.

25.13 * 0.036;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 9:50 am     Reply with quote

Quote:
and when you do - reduce this to a single operation.

25.13 * 0.036;

If you put the two numbers in parentheses like this,
Code:
Velocidad= Counter * (25.13 * 0.036);

the compiler will do the math at compile-time, instead of
creating code to do it at run-time. In other words, it
will pre-calculate the result of 0.905 so the PIC doesn't
have to do it.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 10:31 am     Reply with quote

You also need to look at the sensor output over the full range of expected speeds.

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 22, 2015 10:52 am     Reply with quote

Put a while(TRUE) statement at the end of main(). The compiler puts
a hidden Sleep instruction there, and you don't want to execute that
instruction. A while(TRUE) statement will prevent this.
Quote:
void main()
{
lcd_init();

setup_timer_0(rtcc_ext_l_to_h|RTCC_DIV_2); //ConfiguraciĆ³n TMR0

set_timer0(0); //Borrado contador

enable_interrupts(global);

while(TRUE);
}


And then of course, this:
Quote:
#include <18F4550.h>
#fuses NOWDT,XT,NOPROTECT,NOLVP
#use delay(clock=20000000)

Which means you're running this in Proteus.
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