Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] External clock as an input to MCU

Status
Not open for further replies.

youngsinatra

Newbie level 4
Joined
Jul 9, 2018
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
53
I'm using an AD7751 energy metering IC and ATMega32. I connect the PIN22 (CF) from AD7751 to PIN1 ((T0/XCK)PB0) from ATMega32. I want to calculate the energy by calculating the frequency from CF, how do I make this happen? I've set the operation mode to synchronous but I'm confused how to continue the program.. Please help.


Thanks
 

Hi,

I want to calculate the energy by calculating the frequency
Frequency has nothing to do with energy. Each single pulse represents a certain amount of "energy".
If you want to calculate "total energy" you just need to count (integrate) the pulses and multiply the value with the "singke pulse energy".

**************
You need to measure frequency only, if you want to calculate "active power".

If you want this, then the first thing you need to decide:
* what range of frequency do you expect?

Then decide "frequency measurement method" you want/need to use.
* time measurement between pulses (for low frequencies)
* or "counting pulses for a known period of time" (for high frequencies)
--> there are a lot of "frequency measurement" threads in this forum, with code and discussions.

Then multiply the frequency with the "single pulse energy" to get active power.

Klaus
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <avr/io.h>
#include <inttypes.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include "LCD4bit.h"
#define F_CPU 1000000UL
 
volatile unsigned int Pulses, N;
 
 
ISR(TIMER0_OVF_vect);
ISR(TIMER1_OVF_vect);
 
int main(void)
{
    PORTB = 0;
    DDRB = 0xFC;
    DDRC = 0xFF;
    
    int i, j;
    float energy;
    char result[20] = "";
 
 
 
    MCUCR |= ((1 << ISC11) | (1 << ISC10)); //to count the pulse
    GICR |= (1 << INT0); 
    
    uint32_t elapse_time; // to count the time
    TCCR1A = 0;
    TCCR1B = 0x01;
    TIMSK = 0x04;
    
    N=0;
    TCNT1 = 0;
    
    sei();               
    for(i = 0; i<100 ; i++)
        for(j=0; j<1000; j++){;}
    elapse_time = N * 65536 + (uint32_t) TCNT1;
    cli();
    
    while(1)
    {
        energy = (3000 * Pulses * elapse_time) /3600000;
        dtostrf(energy, 3, 1, result);
        LCD_setCursor(4,0);
        LCD_Disp("Energy Meter");
        LCD_setCursor(0,1);
        LCD_Disp("Energy =");
        LCD_Disp(result);
        LCD_Disp("KWh");
    }
 
    
    return 0;
}
 
 
ISR(TIMER0_OVF_vect)
{
    // keep a track of number of overflows
    Pulses++;
}
 
 
ISR(TIMER1_OVF_vect)
{
    // keep a track of number of overflows
    N++;
}


Here is my progress so far, are there any mistakes or my program is totally wrong?
 
Last edited by a moderator:

Hi,

Seems you neither did read post #2, nor the datasheet.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top