Go Down

Topic: Ch-13: Design of a Taximeter using ATmega328 Microcontroller  (Read 93 times) previous topic - next topic

GolamMostafa

All kinds of comments in the form of criticisms, corrections, deletions, and appreciations are highly welcomed from the readers

13.1  Introduction
A Taximeter is an electronic instrument (Fig-1), which is fitted with a rented Taxicab to record (i) distance travelled, (ii) waiting time, and (iii) fare. These are the minimum features that a simplest Taximeter should have.    


Figure-1: Pictorial View of a Prototype 3-Window Taximeter

A Taximeter can have many other features of which the most important two are: a real time clock to know the time of the day and a printer to get the hard copy of the journey details. The meter may include other optional features like:

• Radio link for dispatching trip information to supervisor
• Interaction with GPS systems to receive security assistance during danger/accident
• Seat sensors that detect the presence of a passenger (s)
• Credit or prepaid card support
• Extra charge for luggage
• Speed of the Taxicab

13.2  First Taximeter


Figure-2: Pictorial View of the first Mechanical Taximeter

The 1st Taximeter was a mechanical one fitted with odometer type display. It was invented in 1891 by German inventor Friedrich Wilhelm Gustav Bruhn. The electronic versions of these meters were introduced in 1980s. At the present times, we have very sophisticated digital Taximeters based on microprocessor, microcontroller and DSP.

13.3  Duty Cycle of a Taximeter
During normal operation, a Taximeter repeats cyclically through the following stages:
(a)FREE: The Taxicab is empty and available for hire. The roof top blinking light is switched on.

(b)HIRED: The Taximeter enters in this stage at the beginning of a journey when the driver presses the HIRED button (Fig-1). The roof top blinking light is switched off. The meter immediately enters into waiting state and then into running. The fare meter shows the initial flat fare (Tk 40.00) and running fare (Tk 12.00/Km and Tk 2.00/minute of waiting time). The waiting meter keeps showing the elapsed waiting time.

(c)TO PAY: At the end of the trip, the Taximeter enters in this stage. The driver presses the 'TO PAY' switch. All processing activities of the meter are stopped. The meters show the fare, distance travelled and the elapse waiting time. The driver may optionally print a receipt. The exterior roof top light may also blink to alert potential passengers.

.....to be continued in the next post
Code: [Select]

GolamMostafa

13.4  Operational Features
Bangladesh Standards and Testing Institution in its draft specifications BDS xxx: 2004 has formulated that a Taximeter should include the following operational features of Table-1 in the form of front panel switches (Fig. 3).



Fig. 3 Conceptual View of a 3-Window Taximeter




13.5  Authorized Tariffs
Bangladesh Road Transport Authority (BRTA) in a gazette notification on 20th  Oct 2015 had fixed up the following tariffs of Table-2 for CNG-driven 3-wheeler Taxicabs. These are important data for the design of a Taximeter as we shall see later in this Chapter.



.....to be continued in the next post

GolamMostafa

13.6  Working Principle of a 3-Wheeler Taximeter
In this sub-section, we briefly describe the working mechanism of a typical Taximeter (Fig-1, 2), which is fitted with a 3-wheeler CNG powered Taxicab. This description would help a lot to understand the design principles of various electronic circuits and software routines of the Taximeter.

The journey of the Taxicab from a source point to a destination could be completed in one of the following ways:
(a)  By travelling only (no waiting) called 'Distance Drive or D-drive'

(b)  By spending waiting time (no travelling, the passenger cancels trip after waiting) called
'Time Drive or T-drive'

(c)  By travelling and waiting (a practical journey) called
'Combined Distance-time Drive or C-Drive'

13.6.1 Distance Drive
(a) An electronic transducer (Fig-1, 3) is attached with the gearbox of the engine of the Taxicab, which produces about 16 electric pulses (called Wheel Turning Pulse, WTP) as the vehicle moves for 10m distance. The distance meter (Fig. 3) updates the distance by 10m.  

(b) At power up reset, the Taximeter shows 00s on the Digital Distance Meter (DDM), Digital Fare Meter (DFM), and Digital Waiting Meter (DWM).

(c) After the Taxicab is hired by a passenger, the driver presses the HIRED button. The distance meter shows 0.00 Km, fare meter shows 40.00 Tk, and the waiting meter shows 00.00 Mn (00min 00sec = 00m00s = 00.00Mn).

(d) From the very start of the trip, Digital Fare Meter (DFM) shows Tk 40.00 as a flat fare for the 1st 2Km of distance. At the crossing of 1st 2Km, fare meter augments the fare by Tk 2.40 (Point-A, Fig-4) - an advance payment for the fare of 200m at the fare rate of Tk 12.00/Km.

(e) After the 1st 2Km zone, the fare meter keeps adding Tk 2.40 for each 200m distance travelled by the Taxicab.

(g) At the end of journey, the Taxicab arrives at the destination. The driver pushes the TO PAY button. All activities of the meter are stopped. The DFM keeps showing the fare (Point-B, Fig-4,  44.80), Digital Distance Meter (DDM) shows distance covered (2.20) and Digital Waiting Meter (DWM) shows elapse waiting time (00.00). The passenger makes the payment and leaves the Taxicab. The Taxicab is ready for the next hire.

(h) We may draw a Line Diagram of Fig-4 for the above typical D-drive journey.



Figure-4: Line Diagram of a Typical D-drive Journey

.....to be continued in the next post
[

GolamMostafa

13.6.2  Time Drive
(a) Just after hiring, the driver pushes the HIRED (Fig-1) button; the Taximeter enters into waiting state. The driver may be asked to wait until the other passengers come down from the house. The DWM updates waiting time by 1-sec. Assume that the passengers would take about 21 minutes time to come down. The Taximeter will be on an exclusive T-drive for this 21 minutes. What reading would we see in DFM, DDM, and DWM? It is important that we know and understand the answers to these questions as they will be very much used while developing Control Program (The Software) for the Taximeter. Let us note that the basis of our all calculations will be:

** 10 m as the DDM will be advancing by 10 m (Table-1).
** 200 m as the passenger has already paid an advance fare for this 200 m : Tk 2.40 (Table-2).
** Waiting Time equivalency with Distance within 1st 2 km : 10 m = 6 sec = 6000 ms(see calculation below)
** Waiting Time equivalency with Distance outside 1st 2 km zone: 10 m = 3.6 sec = 3600 ms
** Tk 2.40 is the amount that the passenger has paid as advance fare for 200 m distance (Table-2).


(b) As the Taximeter is in waiting state, the DDM will show: 0.00 km.

(c) What reading we expect to see in DFM?
/------------------------------------------------------------------------------------------------------------------
** Within the first 2 km, the fare is flat Tk 40.00 (4000 Ps).  //Ps = Paisa
** For 1-min (60 sec) Waiting Time (outside and inside first 2 km), the cost is always: Tk 2.00 (200 Ps)

** 10 m distance will cost: (Tk 40/2 km) x 10             = 20 Ps
** 20 Ps will be charged for the waiting period of: (60 sec/Tk 2.00) x 20 = 6 sec = 6000 ms

** Within 1st 2 km zone, the virtual equivalency between Waiting Time and Distance: 10 m = 6 sec = 6000 ms.
** 200 m would demand the virtual equivalency between Waiting Time and Distance: 200 m = 120 sec = 120000 ms.
** 2000 m (2 km) would demand equivalent Waiting time of: (6 sec/10 m)x2000 m=1200 sec=20.00 (M:S)

** At the elapse of just 20:00 (M:S = Minute:Second), the DFM will show: Tk 40.00 + Tk 2.40 = Tk 42.40 (Fig-5)
//----------------------------------------------------------------------------------------------------------------

** What's about the remaining 1 (60 sec) minute time which is outside 2 km zone?
Ans: To affect a fare change by Tk 2.40, the elapsed waiting time outside 2 km should be 72 sec (see calculation below)

Because only 60 sec has elapsed, the DFM will register Tk 40.00 + Tk 2..40 = Tk 42.40

//----------------------------------------------------------------------------------------------------------------
** Outside first 2 km zone, the fare cost:             Tk 12.00/ km
** 10 m distance will cost:                          (1200/1000)x10 = 12 Ps
** 12 Ps will be charged for the Waiting Time of: (60 sec/ Tk 2.00)x 12 Ps = 3.6 sec = 3600 ms.

** Outside 1st 2 km zone, the virtual equivalency between Waiting Time and Distance: 10 m = 3.6 sec = 3600 ms.
** 200 m would demand the virtual equivalency between Waiting Time and Distance: 200 m = 72 sec = 72000 ms.
//----------------------------------------------------------------------------------------------------------------

(d) The DWM will show: 21.00 (M:S)

(e) We may draw a Line Diagram of Fig-5 for the above typical T-drive journey.



Figure-5:  Line Diagram of a Typical T-drive Journey


.....to be continued in the next post

GolamMostafa

13.6.3  Combined Distance-time Drive
(a) Within first 2 km zone, the Taxicab may wait for a while, then running (Fig-6)
and then waiting and so on depending on the traffic condition of the road.

(b) Outside first 2 km zone, the tour of the Taxicab may also be a combinations of running
and waiting states (Fig-6) or running and waiting states (Fig-6).

(c) Eventually, the Taxicab arrives at the destination (Point-G, Fig-6) with
the DDM showing 2.17 km, DFM showing Tk ??.?? (to be calculated manually in Section-13.6.5),
and DWM showing 11.45 (Fig-6).

(d) We may draw a Line Diagram of Fig-6 for the above typical C-drive journey. 




Figure-6 Line Diagram of a Typical C-drive Journey

.....to be continued in the next post

GolamMostafa

13.6.4  Algorithm for Computing Fare for DFM Meter of Fig-6 of Section-13.5.3
In reality, a Taxicab makes a C-drive tour and it is composed of many numbers of running and waiting states. Let us observe the following statements before computing the total fare (distance and waiting time):

(a) TQ1(Time Quanta-1) is the Waiting Time Quanta 'within first 2 km zone'; it is defined to be virtually equivalent to 10 m distance (let us call it DQ for Distance Quanta). 1 TQ1 = 6 sec= 6000 ms; 1 DQ = 10 m (Section-13.5.2).

(b) TQ2 (Time Quanta-2) is the Waiting Time Quanta 'outside first 2 km zone'; it is defined to virtually equivalent to 10 m distance (1 DQ). 1 TQ2 = 3.6 s = 3600 ms; 1 DQ = 10 m (Section-13.5.2).
 
(c) The Control Program (CP) accumulates TQ1s and TQ2s when the Taxicab is in waiting within first 2 km zone and outside first 2 km zone. The CP accumulates DQs when the Taxicab is in running.

(d) 'within first 2 km zone', the CP continuously adds TQ1s and DQs to see that the sum is 200 (200*10 = 2000 m = 2 km) and if so, it clears the TQ1 and DQ counters (Fig-7); it marks the crossing of 2 km (real or virtual or combined) point by a flag. The DFM, DDM and DWM are updated accordingly.



Figure-7: Processing of TQ1 and DQ within 2  km Zone

(e) 'Outside 2 km zone', the CP continuously adds TQ2s and DQs to see that the sum is 20 (20*10 = 200 m) and if so, it clears the TQ2 and DQ counters (Fig-8); it (CP) marks the coverage of 200 m (real, virtual or combined). The DFM, DDM, and DWM are updated accordingly.



Figure-8: Processing of TQ2 and DQ outside 2  km Zone

.....to be continued in the next post

GolamMostafa

13.6.5  Manual Computation of Fare for the DFM for C-drive of Fig-6 of Section-13.6.3
(a) Line Diagram for C-drive Journey (Repeated in Fig-9)



Figure-9: Line Digarm of C-drive Journey(repeated)

(b) Manual Computation
(1) TQ1 (A - B) : 15 min 3 sec = (15x60)/6 + 3000 ms = 150 TQ1 + 3000 ms
(2) DQ (B - C)  :  900/10                                          = 90 DQ
//----------------------------------------------------------------------------------------------
                                                          TQ1 + DQ          = 200 + 40 DQ + 3000 ms

** 2 km point is detected at: Point-B' (400 m from Point-B). 40 DQ + 3000 ms are taken to next zone
** DQ counter now contains 40; 3000 ms (300 x 10 ms) is in TQ1PartialCounter as 300TU (Time Unit).
** DFM shows: 40.00 + 2.40 = 42.40
//-----------------------------------------------------------------------------------------------                         
(3) DQ (B' - C)                                                        = 40 DQ = 20 DQ x 2

**At Point-C, DFM will show: 42.40 + 2.40 + 2.40 = 47.20
//-----------------------------------------------------------------------------------------------
(4) TQ2 (C - D) : 1 min 17 sec + (300)
            = 60000/3600 + 2400ms + 1700 ms +(300TU)
            = 16 TQ2 + 2400 ms + 1700 ms + (300TU)
            = 16 TQ2 + 7100 ms
            = 16 TQ2 + 1 TQ2 + 3500 ms                               = 17 TQ2 + 350TU

(5) DQ (D - E)  : 730/10                                            = 73 DQ
----------------------------------------------------------------------------------------------
                                                      TQ2 + DQ)               = 20 x 4 + 10 DQ + 350TU

**At Point-E, DFM will show: 47.20 + 2.40x4 = 56.80             (Residue: 10 DQ + 350TU)
//--------------------------------------------------------------------------------------------
(6) TQ2 (E - F) = 25 sec = 2500 ms +(350TU) + 10 DQ   //TU = Time Unit = 10 ms
                            = 6000 ms + 10 DQ
                            = 1 TQ2 + 10 DQ + 2400 ms

(7) DQ (F - G)  = 540/10 +1 TQ2 + 10 DQ + 2400 ms
                            = 54 DQ + 10 DQ + 1 TQ2 + 2400 ms
                            = 65CU + 2400 ms
                            = (20 x 3)CU + 5CU + 2400 ms   //CU = combined unit = TQ + DQ

**AT Point-G, the DFM will show: 56.80 + 2.40x3 = 64.00
//------------------------------------------------------------------------
** Known inaccuracies/imprecision in the Computation****
Accumulated Waiting Time of first 2 km zone are brought to next zone without normalization.
The Waiting Time precision is 10 ms.
The distance precision is 10 m
//---------------------------------------------------------------------------

(8) The Revised C-drive Line Diagram with DFM Readings


Figure-10: Revised C-drive Line Diagram with DFM's Reaadings


.....to be continued in the next post



 

GolamMostafa

13.7 Summary
(1)  The electronic transducer(Fig-1, 3) produces 16 discrete pulses as the Taxicab travels over 10 m distance which bears the symbolic name DQ (distance quanta). Each of these pulses is known as WTP (Wheel Turning Pulse). The WTPs are accumulated by the Counter-0 (C0) of the ATmega328 Microcontroller (MCU). When the C0 has finished accumulating 10-WTP, it raises a flag (the symbolic name is TOV0); the MCU keeps polling the TOV0-bit and when it becomes active, the MCU advances DDM (Digital Distance Meter) by 10 m.

The Flat Fare for the first 2 km Tk 40.00. After that the fare is Tk 12.00/km.

The Fare for each 1-min waiting time (both within first 2 km and outside 2 km) is Tk 2.00.  

(2)  Waiting Time is taken care of by Timer-2 (T2) of the MCU. The basic Time Tick is 10 ms. Within first 2 km, the 10 m distance has virtual equivalency of 6000 ms = 60 x 10 ms. By designating 6000 ms as TQ1 (Time Quanta1) and 10 ms as TT (Time Tick), we have 1 TQ1 = 60TU within first 2 km zone. And, 1 DQ = 1 60TU.

(3) Outside 2 km zone, 10 m distance demands a virtual equivalency of 3600 ms = 36 x 10 ms.  By designating 3600 ms as TQ2 (Time Quanta2) and 10 ms as TT (Time Tick), we have 1 TQ2 = 36TU outside 2 km zone. And, 1 DQ = 1 36 TU.

(4)  DWM is updated after the elapse of 1 sec = 1000 ms = 100TU within 2 km zone and outside 2 km zone.

(5)  Fare for the First 2 km is Tk 40.00. It comes from both DQ and TQ1.

(6) For each 200 m distance after 2 km zone is Tk 2.40. It comes from both DQ and TQ2.

(7) After hiring the Taxicab and at the crossing point of the first 2 km (DDM = 2.00), the passenger pays an advance fare for 200 m distance (Tk 2.40); the DFM shows 42.40 (40.00 + 2.40).

(8) After hiring the Taxicab and at the crossing point of the waiting time which is virtually equivalent to 2 km (2000 m = n TQ1]), the passenger pays an advance fare for 200 m distance (Tk 2.40); the DFM shows 42.40 (40.00 + 2.40).  

(9) After hiring the Taxicab and at the crossing point of the (waiting time + distance traveled or distance traveled + waiting time) which is virtually equivalent to 2 km (2000 m = n DQ + m TQ1), the passenger pays an advance fare for 200 m distance (Tk 2.40); the DFM shows 42.40 (40.00 + 2.40).  
//------------------------------------------------------------------------------------------------------------

(10) After 2 km zone and at the crossing point of 200 m ( 200 m = 20 DQ), the passenger again pays an advance fare for 200 m distance (Tk 2.40); the DFM shows 44.80 (42.40 + 2.40).  

(11) After 2 km zone and at the crossing point of waiting time which is virtually equivalent to 200 m (20 DQ = n TQ2 ), the passenger again pays an advance fare for 200 m distance (Tk 2.40); the DFM shows 44.80 (42.40 + 2.40).  

(12) After 2 km zone and at the crossing point of the (waiting time + distance traveled or distance traveled + waiting time) which is virtually equivalent to 200 m (200 m = n DQ + m TQ2), the passenger again pays an advance fare for 200 m distance (Tk 2.40); the DFM
shows 44.80 (42.40 + 2.40).  
//--------------------------------------------------------------------------------------------------------------

(13) Nearing the destination point, the following situation is expected to happen:
(a) If the Taxicab arrives at the destination and it is just at the 200 m crossing point (due to distance or waiting or both), the passenger pays another Tk 2.40 advance. There could be at best
1 TQ2 and 1 DQ ( 2 Q costs 2x12 Ps = 24 Ps) at the Driver's credit; but, he has got 240 Ps as advance; so, the total gain of the driver is 240-24 = 216 Ps.

(b) If the Taxicab arrives at the destination and it is just a little bit behind the 200 m
crossing point (due to distance or waiting or both), the passenger will not pay another Tk 2.40 advance. There could be still at best 1 TQ2 and 1 DQ ( 2 Q costs 2x12 Ps = 24 Ps) at the Driver's credit; but, he has missed the advance payment; so, he is going to lose at least the cost of 1 DQ
or 1 TQ2 whic is 12 Ps.
//-------------------------------------------------------------------------------------------------------------

(14) If we remain strict to the point that the Driver should always gain, we must resolve the issue of Step-13(b). How? Or, we would think that the Driver is randomly gaining 216 Ps and losing 12 Ps; so, the average gain is always 216 - 12 = 204 Ps.

Go Up