Pulse counting IC with i2c interface or similar - Page 1
Forum section: electronics / projects

author: whiskeyjack
author_rank: Contributor
timestamp: November 21, 2015, 12:21:12 pm
content: I am working on a project where I am using a microcontroller just for counting pulses on a digital pin. I am using Atmega328 with arduino bootloader. Is there a cheaper solution available for this? I particularly need an IC which counts rising pulses and increases a counter. I should be able to use other microcontroller (esp8266) to access that stored variable via i2c preferably and erase it once I have read that value.EDIT:Thanks all for the responses. I'd like to explain the use case. (Sorry I didn't do it earlier). I am using BL0921 real time energy measurement IC to monitor energy consumption by a device. This IC gives HIGH pulses at certain delay. Delay decreases as the power consumption increases. In worst case, I might be getting 10 counts or so per second. I am using arduino Esp on the esp side. I read that in the bootloader itself, there is an internal delay of 50 ms after each loop in order to keep the wifi stack running comfortably. So, I didn't want to destroy the communication anyhow by throwing too many interrupts at it. Also I was not sure how it'd behave when an interrupt is received during that internal 50ms delay period. To save myself from trouble, I chose to use atmega328 with UNO bootloader to do the job. It does the counting and every minute, it passes the count to esp via i2c and resets the count in it's memory. I was planning to save some money there.

author: dom0
author_rank: Super Contributor
timestamp: November 21, 2015, 12:25:54 pm
content: There are some older I2C RTCs which could probably be abused for this, e.g. PCF8583 and similar ICs.But they're generally more expensive than a cheap MCU.

author: nowlan
author_rank: Frequent Contributor
timestamp: November 21, 2015, 12:46:40 pm
content: Cmos counter?

author: mikerj
author_rank: Super Contributor
timestamp: November 21, 2015, 01:08:15 pm
content: Why not use the ESP8266 to do the counting? It has GPIO pins that can be configured as external interrupts.If it has to be external with an I2C interface, then one of the cheap 8 pin PICs or AVRs would do the job e.g. PIC12LF1552 or ATtiny25. The NXP PCF8593 calender IC can be configured as a 6 digit event counter, but not as cheap as a small micro.

author: technix
author_rank: Super Contributor
timestamp: November 21, 2015, 04:42:29 pm
content: You can use the one of the Timer/Counter module as a dedicated counter for this, at the cost of losing a few PWM outputs.You can even use two Timer/Counters to operate in fractional frequency counting (e.g. whatever input signal that chip generates, and a 32768Hz reference clock from a DS3231 DTCXO RTC chip) And if you step up from ATmega328P to something that can be operated that fast a reference clock, you can use a 10MHz reference signal and commence timenutting (e.g. Rubidium standards)

author: Berni
author_rank: Super Contributor
timestamp: November 21, 2015, 05:40:15 pm
content: Use the MCUs built in timer as a counter. You can set it up so that the timer counts up by 1 every time there is a pulse on a certain pin. That way you only need to check it before the timer overflows in value and that should take a pretty long time.If you don't want to step out of the arduino safe zone to actually touch a hardware register, then put a 74HC590 on there and have it count for you.

author: Fungus
author_rank: Super Contributor
timestamp: November 21, 2015, 07:10:24 pm
content: Quote from: whiskeyjack on November 21, 2015, 12:21:12 pmATTiny85? Atmel makes a lot of smaller chips, they can all work with the Arduino IDE. Bare chips are less than $1 or you can get "digispark" devices (which are easier to program).http://www.ebay.com/sch/i.html?_nkw=attiny85

author: edavid
author_rank: Super Contributor
timestamp: November 21, 2015, 07:22:20 pm
content: Quote from: Fungus on November 21, 2015, 07:10:24 pmWhat's the point, when an Atmega328 is only around $1.30?

author: Fungus
author_rank: Super Contributor
timestamp: November 21, 2015, 09:50:27 pm
content: Quote from: edavid on November 21, 2015, 07:22:20 pmDepends on the quantity.If you're buying so many Atmega328s that they're only costing you $1.30 then the Tiny85 will be a few cents.And if it's very small quantities then having it on a PCB is a big plus (but if it's very small then you can get Mega328s on PCBs for about $2.50).

author: edavid
author_rank: Super Contributor
timestamp: November 21, 2015, 10:01:40 pm
content: Quote from: Fungus on November 21, 2015, 09:50:27 pmQuantity 1, from AliExpress (vs about $0.70 for Attiny85s).

author: MarkF
author_rank: Super Contributor
timestamp: November 22, 2015, 05:05:33 am
content: I would use an eight pin PIC12F1840. The interrupt pin can trigger on a positive or negative edge. Use the Interrupt Service Routine to count the edges. The main loop can send the current count via the I2C interface and reset the count once sent. The through hole package is $1.42 from Mouser.