AVR Counter

Thread Starter

Chillian

Joined Mar 24, 2023
8
I need to make a program using the atmega164A that counts during the day and night. Does anyone have any suggestions? Like do I make it counts for 24 hours straight? And if so, how exactly?
 

Papabravo

Joined Feb 24, 2006
21,225
You can make a counter do whatever you want it to do. You use the hardware to count some interval like 1 second. Then in the software you make a larger counter that will count seconds. If you use enough bits, the software counter will not overflow any time soon. Check out the following article on a time counter that began on Jan 1 1970.

https://en.wikipedia.org/wiki/Unix_time
 

bidrohini

Joined Jul 29, 2022
190
You can configure the timers of the Atmega164 microcontroller to make a clock and keep count of day and night. However, I think it will be better if you interface a DS1307 or any other RTC with the microcontroller. The task will be easier.
 

Papabravo

Joined Feb 24, 2006
21,225
You can configure the timers of the Atmega164 microcontroller to make a clock and keep count of day and night. However, I think it will be better if you interface a DS1307 or any other RTC with the microcontroller. The task will be easier.
I don't necessarily agree with this proposition. It depends on what else the AVR needs to do. If timekeeping is it, adding a second chip doesn't really do anything for you.
 

Thread Starter

Chillian

Joined Mar 24, 2023
8
I don't necessarily agree with this proposition. It depends on what else the AVR needs to do. If timekeeping is it, adding a second chip doesn't really do anything for you.
In my last post I wrote exactly what it needs to do, you can check that if you have the time. But thank you both for your replies, I’ll look more into it.
 

Thread Starter

Chillian

Joined Mar 24, 2023
8
What does day and night have to do with counting?
What are you counting?
I’m counting the positive pulses received from a DSP and then convert them into the equivalent power consumed. So I have to keep track of the power consumption during the day and the night.
 

DickCappels

Joined Aug 21, 2008
10,171
How do the pulses relate to equivalent power? Are you taking the output of some power metering chip?

If you can, give us enough detail to help you toward your goal.
 

Papabravo

Joined Feb 24, 2006
21,225
I’m counting the positive pulses received from a DSP and then convert them into the equivalent power consumed. So I have to keep track of the power consumption during the day and the night.
I hear what you are saying, but it makes little sense to me. You may need to find an alternative way of communicating what is going on because your words are failing you.
 

djsfantasi

Joined Apr 11, 2010
9,163
Do you want your program to count the number of pulses over a 24 hour period?

If so, all you need to do is use the millis() function to see if the number of milliseconds since the program started is 86,400,000 more than when it began. Use the coding technique as described in this article (click on the link).

This technique is often used when you need to time something while the program performs other tasks. Such as count pulses! And the same technique can be used to count events in an hour, 12 hour, 24 hour or whatever increments you need.
 

Thread Starter

Chillian

Joined Mar 24, 2023
8
How do the pulses relate to equivalent power? Are you taking the output of some power metering chip?

If you can, give us enough detail to help you toward your goal.
The system measures and displays electricity consumption and is composed of two subsystems (AVR and DSP).
The DSP subsystem measures the voltage and intensity, calculates the energy consumed and generates a number P of pulses for 1kWh.
The generated pulses will be transmitted on a pin of the PF port. The value of the intensity of the consumed current is also transmitted on the same port. It will establish a working mode of energy metering (with or without hourly consumption intervals). Voltage sampling interval and intensity and the number of pulses P per kWh, will be established from SW7-SW0. The maximum power of 10kW is considered.
The AVR subsystem counts the pulses, calculates and displays the consumed energy according to the mode indicated by the DSP subsystem. Both subsystems display their own status (on LED3-LED0, respectively on a 7-segment display – Display). AVR subsystem uses an ATMega164 microcontroller. The DSP subsystem includes the EZ-Kit LITE ADSP2181 evaluation board and a
input output interface (IO DSP).
 

Thread Starter

Chillian

Joined Mar 24, 2023
8
I hear what you are saying, but it makes little sense to me. You may need to find an alternative way of communicating what is going on because your words are failing you.
I know, I’m sorry. I replied to the message above with the whole requirement. It is fairly complex for me and that’s why I am trying to make a very simplified version which only counts the positive edges of the waveform it receives and not bother with the power conversion just yet. The DSP code is already written so that’s not a problem. Thank you very much for your interest!
 
Top