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

Speed and RPM

 
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

Speed and RPM
PostPosted: Thu Apr 09, 2015 1:41 pm     Reply with quote

Hi, I am doing a project about motorcycle, I need different sensors to measure different things. I make two programs about fuel level and temperature. But I do not know how to do the speed and rpm. A matrix keypad 4x4 for the selection of the parameter to be measured, which will be shown on the LCD touch. I use a PIC 18F4550. If someone have any ideas, I would be very grateful.
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 2:18 pm     Reply with quote

Do a forum search on 'tacho'.
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 2:21 pm     Reply with quote

ad,
The RPM reading should be very easy, you can do it in so many way, the best and the most accurate is to read one of the sparkplug pulses. You can find a lot of good tutorial on Google.

The keyboard you have to; either multiplex it using 8 IOs or use one analog input with different value resisters!

Hope this help,
temtronic



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

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 2:32 pm     Reply with quote

Speed can be done with a sensor on the front wheel. Just use one from a bicycle 'unit' !
RPM an be done off the alternator output or 'points' if bike has them or loop a wire round a plug. Some math involved based on 2 or 4 stroke, # of cylinders,etc.
I'd build a 'test jig' of another PIC with appropriate outputs to 'simulate' the bikes sensors. A LOT safer than riding and calibrating at the same time !!

Jay
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 3:12 pm     Reply with quote

temtronic wrote:
Speed can be done with a sensor on the front wheel. Just use one from a bicycle 'unit' !
RPM an be done off the alternator output or 'points' if bike has them or loop a wire round a plug. Some math involved based on 2 or 4 stroke, # of cylinders,etc.
I'd build a 'test jig' of another PIC with appropriate outputs to 'simulate' the bikes sensors. A LOT safer than riding and calibrating at the same time !!

Jay


For the speed, I've used an inductive sensor to read the holes on the front disc rotors! That worked well!!

Also some bikes have now coil plugs (like mine) so you can't really measure the spark by induction.

But you can read easily by the coil wire (less than 100V normally).
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 3:15 pm     Reply with quote

temtronic wrote:
Speed can be done with a sensor on the front wheel. Just use one from a bicycle 'unit' !


IMO, it's not really a great idea to clip a magnet (bicycle sensor) or anything to the wheel this will off-balance the wheel and you will have some vibration noticeable over 100 kph.
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
ad



Joined: 24 Mar 2015
Posts: 14

View user's profile Send private message

PostPosted: Fri Apr 10, 2015 3:50 am     Reply with quote

I do this, I do not want to do it with PWM. I want you to tell me, is that the last part wrong, if I can help. All the while the LCD brand me 0. But the sensor detects.

Code:

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

int16 counter=0;

//*************** INT TIMER1*********************
#int_TIMER1
void TIMER1_isr(void) {
counter=get_timer0();         //Lectura contador TMR0
counter=counter*2*120;     //Conversión a rpm
  printf(lcd_putc,"%6lu rpm",counter);
  lcd_gotoxy(1,1);
set_timer0(0);                      //Reinicia cuenta
set_timer1(3036);                // Recarga a 0.5s
 }
//**********************************************
VOID MAIN()
{           
   //CHAR K,kant='0';
   //char PWMH=0,PWML=0;
   lcd_init();
   kbd_init();
   PORT_B_PULLUPS(TRUE);
   
   setup_timer_0(rtcc_ext_l_to_h|RTCC_DIV_2);   //Configuración TMR0
     setup_timer_1(T1_internal|T1_DIV_BY_8);     //Configuración TMR1
   set_timer0(0);                               //Borrado contador
   set_timer1(3036);                         //Carga a 0.5s
   enable_interrupts(int_timer1);
   enable_interrupts(global);           //Habilitación interrupciones
   
WHILE (1) {
      k=kbd_getc();
      if (k=='\0') k=kant;
      if ((k=='*') || (k=='#')) k='0';
      kant=k;
       k=k-48;
       PWMH=k*28;
       PWML=255-PWMH;
      for(PWMH;PWMH>0;PWMH--){
       OUTPUT_HIGH(PIN_A0);}
      for(PWML;PWML>0;PWML--){
      OUTPUT_LOW(PIN_A0);}
  }
}

ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Fri Apr 10, 2015 4:40 am     Reply with quote

Btw, what is the model of motorcycle you try to improve?

I might take a look to see what are the easy options.
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
ad



Joined: 24 Mar 2015
Posts: 14

View user's profile Send private message

PostPosted: Sat Apr 11, 2015 4:28 am     Reply with quote

I will improve any motorcycle 49cc. Yes ELCOUZ you can see differents options and tell me please. Thank you.
temtronic



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

View user's profile Send private message

PostPosted: Sat Apr 11, 2015 5:37 am     Reply with quote

DOH, if this is an ON rode ride it HAS to have a speedometer. If it's a 'cable' type, just add YOUR optical or hall encoder to that.

Jay
ad



Joined: 24 Mar 2015
Posts: 14

View user's profile Send private message

PostPosted: Sun Apr 12, 2015 1:42 pm     Reply with quote

I don't use a encoder, I want to do similar a bicycle, but I don't know how to do the program.
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Sun Apr 12, 2015 1:49 pm     Reply with quote

whatever else you think you need to do inside the timer ISR -
DONT DO THIS !!!
Code:

counter=counter*2*120;     //Conversión a rpm
  printf(lcd_putc,"%6lu rpm",counter);
  lcd_gotoxy(1,1);


I also have grave doubts about the concept you are pursuing....
as there is no schematic of what you are attempting.
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Apr 12, 2015 4:13 pm     Reply with quote

ad,
I do not know what motorcycle model you have, if you have one with a spark plug cable. It does not matter how many cylinders (you just have to pick one)! what you are looking for is called inductive pickup, you wind a wire around spark plug cable (you have to experience with how many winds), if you have a oscilloscope it will help. one end is free and not connected to the ground or anything, the other end of the wire connected to transistor or a timer chip such as 555 to produce a square pulse for every spark signal, then you use this signal as external interrupt input in your PIC. Now that was the hardware theory (similar to a timing light from the good old days Smile
or if you can pickup the motorcycle computer or the spark plug distributor circuit to generate the pulse.
For more detail on the circuit, just google "inductive pickup tachometer circuit "
You need to program the PIC to read and advance a counter for every interrupt received. then a simple math ad you can display the value as RPM on your LCD.

Build the circuit first so we may be able to help!
Good luck,
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Apr 12, 2015 4:26 pm     Reply with quote

another way you can pick a pulse is from the alternator before it regulated to DC. This will be more difficult for a motorcycle. The motorcycle that I used to have, they built the motorcycle around the alternator Smile
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Sun Apr 12, 2015 4:30 pm     Reply with quote

Sam_40 wrote:
another way you can pick a pulse is from the alternator before it regulated to DC. This will be more difficult for a motorcycle. The motorcycle that I used to have, they built the motorcycle around the alternator Smile


Easier than that... take the signal from the inductive pickup on the crankshaft

More precise Smile


_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
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