Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Speedometer prescaler

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Thu Mar 27, 2014 12:14 am    Post subject: Speedometer prescaler Reply with quote

Hello. With my friend we made a "buggy car" based on Fiat Seicento parts. After installing bigger tyres the speed showed is incorrect.
I want to build a device to incrase pulses from speed sensor. Im thinking about idea how to due this from two weeks Very Happy
It must be something like "freq measure->prescale->freq generation". Prescale may be constant in code - non adjustable for simplicity.
It can be made with ~1s buffer For example if in 1s count 3 pulses i want to 4 pulses in next second on output but if car stopped i dont want any pulses.
If any one have somme idea please post. I need a "spark" Very Happy
Thanks for any reply.

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile Visit poster's website
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Thu Mar 27, 2014 12:31 am    Post subject: Reply with quote

Hi,

An "spark" , try use the forum search for Speedometer Idea

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Thu Mar 27, 2014 2:07 am    Post subject: Reply with quote

If you have access to a speed sensor signal, then I think I would either use input capture or count pulses for a given time, depending upon the pulse rate, calculate the speed, and display in on an LCD.

JC
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Thu Mar 27, 2014 2:35 pm    Post subject: Reply with quote

Thanks for reply. Its my fault and now I read them all, but I thing my problem is different.
I dont want to shoot for a fly with a cannon Very Happy so want use small Tinny2313.
I dont need to display any value. I want calculate new higher speed and send it to output for drive speedometer.
To the sensor goes 3 wire . Earth, supply and return signal. Device can by mounted betwen speedometer and sensor.

I have no idea how calculate pulses for output "in the fly" Eg. If counted value = 0 then I can stop the Timer1 for no pulses.
But how to configure it and load values for generate 3,4,5 and more pulses for next sec?



Code:
$regfile = "attiny2313.dat"
$crystal = 8000000

Config Portb = &B00000000 : Portb = &B11111111
Config Portd = &B00000000 : Portd = &B11111111
Config Porta = &B00000000 : Porta = &B11111111

Config Timer0 = Timer , Prescale = 1024                     ' I use TIMER0 for spare TIMER1 to generate
Enable Timer0 : On Timer0 Int_10ms                          'output pulse

Config Int0 = Falling
Enable Int0 : On Int0 Sensor                                'input for sensor pulses

Dim F_10ms As Bit , F_1s As Bit , Ms_counter As Byte        'for 1s timing
Dim S_pulses As Word , Counted As Word , O_pulses As Word   'for counting and calculating pulses

Enable Interrupts


Do
'--------------Setings flag for 1s procedure to spare Timer1--
If F_10ms = 1 Then
   F_10ms = 0
   Incr Ms_counter
   If Ms_counter = 100 Then
      Ms_counter = 0
      Set F_1s
      End If
End If
'-------------- Flag 1s is set -----------------------------
If F_1s = 1 Then
   F_1s = 0
 Counted = S_pulses
 S_pulses = 0
 O_pulses = Counted * 1.1                                   'O_pulses is desired pulse for output

End If
 'How to calculate values for pulsing on output for next second?
 '


Loop
End



Sensor:
Incr S_pulses
Return

Int_10ms:
Timer0 = 179
Set F_10ms
Return
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Thu Mar 27, 2014 3:27 pm    Post subject: Reply with quote

Okay..that code work. If any one can optimize this, will be great.
It use 95% of flash space.
Code:
$regfile = "attiny2313.dat"
$crystal = 8000000

Config Portb = &B00001000 : Portb = &B11111111
Config Portd = &B00000000 : Portd = &B11111111
Config Porta = &B00000000 : Porta = &B11111111

Config Timer0 = Timer , Prescale = 1024                     ' I use TIMER0 for spare TIMER1 to generate
Enable Timer0 : On Timer0 Int_10ms                          'output pulse

Config Timer1 = Timer , Prescale = 256
Enable Timer1 : On Timer1 Timer1_int

Config Int0 = Falling
Enable Int0 : On Int0 Sensor                                'input for sensor pulses

Output_pin Alias Portb.3

Dim F_10ms As Bit , F_1s As Bit , Ms_counter As Byte        'for 1s timing
Dim S_pulses As Word , Counted As Word , O_pulses As Single 'for counting and calculating pulses
Dim X As Word , Y As Single , Multiplier As Single
Dim Switch As Bit

Switch = 0
Readeeprom Multiplier , 2

Enable Interrupts
Do
'---Setings flag for 1s procedure to spare Timer1--
If F_10ms = 1 Then
   F_10ms = 0
   Incr Ms_counter
   If Ms_counter = 100 Then
      Ms_counter = 0
      Set F_1s
      End If
End If
'-------------- Flag 1s is set --------------------
If F_1s = 1 Then
   F_1s = 0

 Counted = S_pulses
 S_pulses = 0

 If Counted <> 0 Then                                       'for non divide by 0

 O_pulses = Counted * Multiplier
 O_pulses = O_pulses * 2
 Y = 34288 / O_pulses
 X = 35536 - Y
 End If

End If
'-------------------------------------------------
  If Pinb.5 = 0 And Switch = 0 Then
   Switch = 1
   Multiplier = Multiplier + 0.1
   Writeeeprom Multiplier , 2
  Else
   Switch = 0
  End If
  If Pinb.6 = 0 And Switch = 0 Then
   Switch = 1
   Multiplier = Multiplier - 0.1
   Writeeeprom Multiplier , 2
  Else
   Switch = 0
  End If

Loop
End

Sensor:
Incr S_pulses
Return

Int_10ms:
Timer0 = 179
Set F_10ms
Return

Timer1_int:
Timer1 = X
If Counted <> 0 Then Toggle Output_pin Else Output_pin = 1
Return



..any tips?
Back to top
View user's profile Visit poster's website
aphawk

Bascom Member



Joined: 23 Jan 2010
Posts: 168
Location: Brazil

brazil.gif
PostPosted: Fri Mar 28, 2014 5:44 am    Post subject: Reply with quote

Your problem is math with single variables.

If you can make the math using only byte and word type variables, the program will be small. I had one reduction from about 800 bytes in a program that i made some tricks to not use Single variables.

What is the maximum size that S_Pulses can be ?

Paulo
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Mar 28, 2014 9:07 am    Post subject: Reply with quote

S_pulses should contain a Byte..if not I can short the time for sampling to 500ms.
Differences in the displayed speed are visible at higher speeds. The max displayed speed is 140 Km/h at now..
This is what we talking about Very Happy HANDMAKE! Very Happy
http://bart-projects.cba.pl/beno.html
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum