ATMEGA162 External Counter Pins

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,
I am working on a project where i need to display distance, speed and rpm of a vehicle.

I chose ATMEGA162 since it has four timer/counters
One Timer/Counter will be used to measure Speed
One Timer/Counter will be used to measure Distance
One Timer/Counter will be used to measure the RPM
and the last one to make a 1 second time window.

I was going through the datasheet but cant find any external pins for the counter, except for T0(PB0) and T1(PB1)

Where are the other timer/counter pins? :roll:

can someone please help me out regarding this :?:

_____________________ Love and Peace keeps PrOgraMmerS happy :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not all Timers have external counter pins.

You can probably do everything with a single 16-bit counter.

In practice, you might have a sensor on a road wheel and a sensor on the engine. If there is some slipping of the clutch, you can have different results. With no slippage, you will have a constant ratio (according to your gearbox).

You might have sensors on driven wheels and un-driven wheels. So you can detect wheel slippage. With agricultural tractors, this is a common feature. On the other hand, motor cars on a hard road tend to have virtually no wheelslip (unless driven by boy racers).

Also, in practice, nothing goes very fast. e.g. 10000 RPM is only 167 RPS or 6ms per revolution.

So you can easily use INT0 and INT1 pins as well as the T0 and T1 pins. The mega162 also has 16 PCINTn pins. And an Analog Comparator.

So you have plenty of methods for recording period or frequency.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
distance, speed and rpm

If your car has OBD2/CAN then that is available through diagnostic connection. And if that is an older car (>20 years) then most likely you have to mount some sensors in your car.
The distance sensor (wheel rotation) toggles really slowly (<15Hz) with subsonic velocities so as mentioned a regular INTx is more than adequate. For RPM (<100Hz) a timer could be used but still that is an overkill.

Quote:
I chose ATMEGA162 since it has four timer/counters

That is a very nice chip. It also has two UARTs. And works with JTAGICEMk1.

What I would suggest is to use one timer as a PWM generator to pretend a wheel sensor during development so that you didn't have to drive your car during testing. Just send speed via uart, generate PWM and then measure it back with INTx.

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
If your car has OBD2/CAN

Brutte, Yes it has a CAN interface but i wont be allowed to work with it.

Quote:
And if that is an older car (>20 years)

No its a modern vehicle (a truck)

Quote:
So you have plenty of methods for recording period or frequency.

David.

David,
This is my extension of my initial project where i was required to log distance and speed at a specified interval.

I used ATMEGA16 for this and used T0 and T1 to measure pulses for distance and speed.

Quote:
So you can easily use INT0 and INT1 pins as well as the T0 and T1 pins. The mega162 also has 16 PCINTn pins. And an Analog Comparator.

So you have plenty of methods for recording period or frequency.

I assume using INT0, INT1 pins might use some CPU resources as i have to manually update the registers.
Please correct me if I am wrong.
Do I really need to use ATMEGA162 or ATMEGA16 alone will do the job confused :(

_____________________ Love and Peace keeps PrOgraMmerS happy :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I assume using INT0, INT1 pins might use some CPU resources as i have to manually update the registers. Please correct me if I am wrong.

Yes, you are right. Considering the truck's diesel max rpm is 50 revs/sec (3000rpm) and the INTn IRQ takes 16 ticks then that uses about 1/200th of CPU time.

Quote:
Do I really need to use ATMEGA162 or ATMEGA16 alone will do the job

Measuring two frequencies of ~Hz range is an overkill. But for the convenience of development I would have used m162 simply because it has more timers.

I also think that measuring PWM frequency is too difficult for the DIY first project.

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suspect that you could do the whole project with a Tiny2313.

However, like Brutte says, use the mega162 which has plenty of flash, SRAM, pins, Timers, UARTs, JTAG, ... It even has an external memory bus.

Regarding timing granularity, latency etc.
You just measure several periods (or frequencies). Then take a running average of the results.

Good Luck.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I suspect that you could do the whole project with a Tiny2313.

Yes this can be done with TINY2313 but my instrument has a graphics LCD connected to it so 2K flash will not be sufficient.

Quote:
You just measure several periods (or frequencies). Then take a running average of the results.

Yes! that's what i am planning to do, take a series of readings and then make an average.

Thanks David, thanks Brutte :D

ill keep you guys posted on my progress.

_____________________ Love and Peace keeps PrOgraMmerS happy :)