Milometer For My bike

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
odessa
I practically live here!
I practically live here!
Posts: 102
Joined: Thu Sep 09, 2010 6:06 am
Location: London
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Milometer For My bike

Post by odessa » Wed Nov 03, 2010 4:38 am

Hi Guys :)

Right.

I have been working on little project for my bike. Its a 16 x 2 LCD that counts in miles. I made the board myself ( getting good at these :D )


Image

Image

Image


This is the code I'm using ( proton )

What I'm thinking is it would be cool to show the speed in MPH too. What I am considering is to count the time between the pulses sent from the counter ( which is reed switch/ magnet setup )

Can anyone give me some rough pointers to coding this ?

Code: Select all

'****************************************************************
'*  Name    : Milometer                                         *
'*  Author  : ME!!!!                                            *
'*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 02/11/2010                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
 Device 16F628A
Config INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_OFF, MCLRE_OFF, BODEN_ON, CP_OFF, LVP_OFF
LCD_DTPin = PORTB.4
LCD_RSPin = PORTB.2
LCD_ENPin = PORTB.3
LCD_Interface = 4
LCD_Lines = 2
LCD_Type = 0
All_Digital = True

DelayMS 150
Cls


Dim btnvar As Byte
Dim countm As Byte
Dim miles As Float
miles=0
countm=0
PORTA.1=0

Print At 1,1, "Miles ", Dec1 miles
Print At 2,1, "Rotation ", Dec3 countm

loop:
Button PORTA.1,0,255,255,btnvar,0,nopress
Print At 1,1, "Miles ", Dec1 miles
Print At 2,1, "Rotation ", Dec3 countm
If countm=77 Then GoTo milesadd
countm=countm+1
GoTo loop

nopress:
GoTo loop

milesadd:

miles=miles+0.1
countm=0
GoTo loop
Thanks for reading

Jay :D
(\_/)
(='.')
(")-(")
This is a bunny, copy bunny into your signature to help him achieve world domination.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Milometer For My bike

Post by brad » Wed Nov 03, 2010 5:20 am

Now this is a very cool and very practical project!

As for your Mph, lets think about the variables involved.

You have already got your distance worked out so you must already know how far it is per rotation. lets say we have just jumped on the bike and started riding, the first pass of the sensor we would start a timer (would probably have to be interrupt controlled) we would count for maybe a few seconds (a little bit of trial and error here would be good) during the count, we would also be counting how many passes of the sensor we have made.

So let's say the counter is set to five seconds. and in that five seconds we manage to complete 30 rotations and (ill work with metre's here) lets say the rotation distance is 1metre.


We would do a little maths: 30 * 1m = 30 metres. so if you covered 30 metres in 5 seconds, what distance would you cover in 60 seconds?

30 * 12 = 360 metres

and in an hour

360 * 60 = 21,600 or approx 21Kph

I think that sort of thing may work!

User avatar
odessa
I practically live here!
I practically live here!
Posts: 102
Joined: Thu Sep 09, 2010 6:06 am
Location: London
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Milometer For My bike

Post by odessa » Wed Nov 03, 2010 5:34 am

Cool :) I see what you are saying and it makes sense but ....

I'm back to interupts again :( ....

Is there a good tutorial about explaining timers/interupts etc ?

I am finding Basic very easy tbh but the whole timer/interupt thing is a little baffling at the moment,

Thanks for your help

Jay :D
(\_/)
(='.')
(")-(")
This is a bunny, copy bunny into your signature to help him achieve world domination.

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Milometer For My bike

Post by bitfogav » Wed Nov 03, 2010 6:38 am

Hi Jay

Very cool project :D

Has for Interrupts, check out this tutorial by Graham at digital-diy, the best way to learn is to play with the code :)

http://digital-diy.com/Swordfish-Code-E ... sking.html

How did you make your board? have you got a PCB making kit of some kind?

User avatar
odessa
I practically live here!
I practically live here!
Posts: 102
Joined: Thu Sep 09, 2010 6:06 am
Location: London
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Milometer For My bike

Post by odessa » Wed Nov 03, 2010 6:30 pm

Hi Gav,

To make the boards I first draw out the schematic in Eagle. Then use the board tool to place and route the components. After that I print onto some transparency laser paper.

I use photoresist so have a UV box, developer and etchant ( ferric chloride )

It only took 30 mins from printing to having a fully etched board, then all I have to do is drill it.

The most expensive bit is the UV box which was about £100 from rapid electronics.

Theres a really helpful guide including a list of everything you need here :

http://picprojects.org.uk/projects/makepcb/index.htm

One thing I would add to that is DONT use carbide drills .. they are rubbish, way too brittle and VERY expensive...All you are drilling is pcb board. I use 1mm HSS drills which you can get from ebay, 10 for £1 rather than nearly £20 for carbide.... I have been using the same HSS bit for about a month now and its still razor sharp... HSS bits also allow for a small amount of flex...carbide dont..they snap way too easily

I looked at the tutorial on timers last night and did get a simple timer running ...

The timer code below was copied and modifed from Digital DIY to run on my 16f628a

I used the code for Timer1 and it seems to run perfectly :D

Code: Select all

'****************************************************************
'*  Name    : Milometer                                         *
'*  Author  : ME!!!!                                            *
'*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 02/11/2010                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
Device 16F628A
Config INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_OFF, MCLRE_OFF, BODEN_ON, CP_OFF, LVP_OFF
LCD_DTPin = PORTB.4
LCD_RSPin = PORTB.2
LCD_ENPin = PORTB.3
LCD_Interface = 4
LCD_Lines = 2
LCD_Type = 0
All_Digital = True

DelayMS 150
Cls


Dim btnvar As Byte
Dim countm As Byte
Dim miles As Float
Dim uS As Word
Dim mS As Word
Dim S As Word
Dim mphd As Word
Dim mph As Word
Dim countd As Word
PORTA.1=0


Symbol GIE = INTCON.7				' Global Interrupt Enable Bit
 
Symbol TMR1_Val = 64536		  		' Set the initial value of TMR1
 Symbol TMR1_mS = 1			  	' Time period of TMR1					
Symbol Timer1 = TMR1L.Word			' A special way of addressing both TMR1L and TMR1H with one register
Symbol TMR1_Enable = PIE1.0			' TMR1 interrupt enable
Symbol TMR1_Overflow = PIR1.0			' TMR1 overflow flag
Symbol TMR1_On = T1CON.0			' Enables TMR1 to start incrementing
			
On_Interrupt Int_Sub
 
GoTo Initialization			
 
Int_Sub:
 
	GIE = 0			
 
	If TMR1_Overflow = 1 And TMR1_Enable = 1 Then
	   TMR1_Enable = 0
	   Timer1 = Timer1 + TMR1_Val
	   TMR1_Enable = 1
	   TMR1_Overflow = 0
	   mS = mS + TMR1_mS
	   If mS >= 1000 Then
	   	  mS = mS - 1000
		  S = S + 1
	   EndIf
	EndIf	
 
	GIE = 1
 
	Context Restore
 
Initialization:	
 
	TMR1_Enable = 0
 
	INTCON.6 = 1   	  	' Peripheral Interrupts

	T1CON.1 = 0		' 1 = External clock from pin RC0/T1OSO/T1CKI (on the rising edge)
			   	' 0 = Internal clock (FOSC/4)
	'TRISC.0 = 1	  	' If External clock, then set clock as an input
	'HPWM 1,128,32000   	' Set TMR1's External Source	
	T1CON.2 = 1		' 1 = Do not synchronize external clock input
			   	' 0 = Synchronize external clock input
				' When T1CON.1 = 0;
				'   this bit is ignored. Timer1 uses the internal clock when TMR1CS = 0.
					  	
	T1CON.4 = 0		' 11 = 1:8 prescale value
	T1CON.5 = 0		' 10 = 1:4 prescale value
				' 01 = 1:2 prescale value
				' 00 = 1:1 prescale value
	Timer1 = TMR1_Val
 
	TMR1_Enable = 1						  
	TMR1_On = 1		
 
	GIE = 1


countm=0
countd=0
mphd=0
miles=0

main:

Repeat

Print At 1,1,"    ", "Miles ", Dec1 miles
Print At 2,1,"     ",Dec2, countm,  " MPH"                                 ' display mph using * .05682
Button PORTA.1,0,0,255,btnvar,0,nopress                              'check for pulse from reed switch
countm=countm+1                                                        'add to miles counter
countd=countd+1                                                       ' add to mph counter
If countm=77 Then GoTo milesadd                                       ' add 0.1 to miles covered
nopress:
Until S = 3
mphd=countd*77 /3
mphd=mphd *0.05682                                            ' find inches per second  
S=0                            
countd=0                                                    ' reset counter used for mph

GoTo main

milesadd:

miles=miles+0.1
countm=0
GoTo main

Image
(\_/)
(='.')
(")-(")
This is a bunny, copy bunny into your signature to help him achieve world domination.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Milometer For My bike

Post by brad » Sat Nov 06, 2010 7:12 am

So is it working okay?

Is it quite accurate?

User avatar
odessa
I practically live here!
I practically live here!
Posts: 102
Joined: Thu Sep 09, 2010 6:06 am
Location: London
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Milometer For My bike

Post by odessa » Sat Nov 06, 2010 7:28 am

I will find out for sure on Sunday when i actually use it on my bike, but the maths is right so should be fine .... will report back :D
(\_/)
(='.')
(")-(")
This is a bunny, copy bunny into your signature to help him achieve world domination.

Digg
decided to stick around...
decided to stick around...
Posts: 27
Joined: Sun Mar 28, 2010 1:27 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Milometer For My bike

Post by Digg » Sat Nov 06, 2010 9:08 am

Just wanted to say this is an awesome project that I have been wanting to try. Great job and let us know how accurate it is.

User avatar
odessa
I practically live here!
I practically live here!
Posts: 102
Joined: Thu Sep 09, 2010 6:06 am
Location: London
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Milometer For My bike

Post by odessa » Mon Nov 15, 2010 5:35 am

Hi Guys,

Update:

Tested and is running fine, the update, as its set to 3 seconds means the speedo is a little laggy but seems to be spot on.
I have now added a clock to the display ... which means I had to add another 'daughter board' with buttons to allow me
to change the time, I also added a miles reset button too.
Next step is to house it in a project box ... I'm very pleased with it all :D

Image

Image

Image

Image
(\_/)
(='.')
(")-(")
This is a bunny, copy bunny into your signature to help him achieve world domination.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Milometer For My bike

Post by brad » Mon Nov 15, 2010 5:03 pm

This project just keeps getting better and better!

How do you think you will make the case for it?

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 12 guests