Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

measuring powerline period/frequency

Status
Not open for further replies.

netotse

New Member
hi,
i need to measure powerline frequency for my final year project(a dynamic demand controller, <those in the uk might have heard of it>) from all i've managed to read period measurement seems to be generally better so i decided to use that. i've searched the web but the frequency measurement projects i found all have far out ranges (use 50hz to *Mhz) while here powerline is 50hz meaning i need something like 30hz - 100hz. i have very lil electronics experience and no uC experience...all the books am reading dont seem to shed light on how to measure the actual period of the signal and its like i have too much stuff to read in sooo little time so i'd appreciate whatever help i could get...thanks

p.s. a dynamic demand controller monitors powerline frequency and disconnects connected appliances when the frequency exceeds certain limits.

also i dont have a clue as per which programmer to use(would this PIC kit II that er'one is talking about be helpful? -i know someone in the UK that can get one for me)
 
hi,
One way would be to use a comparator and detect the zero crossing point of the mains waveform.

Use the crossing point to generate an interrupt within the PIC.
The interrupt would start/stop a PIC's internal timer.

Read the contents of the timer.

By choosing a matching crystal freq for the PIC clock, say, 3.2768MHz the internal timer count will be proportional to the mains period.
 
thanks for the reply...i'm already using a zero crosing detector(i think it was even u i got the idea from)
ok...in theory i get the bit about using the output of the zero crossing detector to drive an interrupt within the pic but could you(or anyone else for that matter) shed more light on the matching crystals bit-as in the frequency of the external clock should match the internal frequency for the pic clock? its still fuzzy!
 
You state you have little electronics and no microcontroller experience plus little time. What course are you in the final year of? Biology?
 
You state you have little electronics and no microcontroller experience plus little time. What course are you in the final year of? Biology?
ouchhhh!!!! if that wasn't below the belt i dont know what is...

i tend towards the power(electricity) side of things(hence the project-dynamic demand controller)...i'm not trying make excuses but the educational system in my country isn't anything to write home about...the little i know about practical electronics i taught myself all we ever did in class was the maths and physics bit...

so much for coming clean...fact is irregardless of my discipline i still need help!
 
thanks for the reply...i'm already using a zero crosing detector(i think it was even u i got the idea from)
ok...in theory i get the bit about using the output of the zero crossing detector to drive an interrupt within the pic but could you(or anyone else for that matter) shed more light on the matching crystals bit-as in the frequency of the external clock should match the internal frequency for the pic clock? its still fuzzy!

hi,
For measuring the mains 'period' I would choose a xtal frequency of 4MHz, whick gives a 1MHz internal cycle freq. [1uSec]

Use Timer1 with prescaler and internal clocking.

Clear/start the Timer1 on the first zero crossing, detect the cross with say PORTB.0 interrupt. Stop/read the timer1 on the next PORTB.0 interrupt.

The Timer1 count and an timer1 overflow counter will give the period count.

If you wished to measure frequency of the mains 50Hz I would use a 3.2768MHz xtal.

Do you follow OK.?
 
If you wished to measure frequency of the mains 50Hz I would use a 3.2768MHz xtal.

Hi ericgibbs

I have a problem here.

If we use 32.768Khz crystal then for one second it will be 8192 counts per second (32768/4 = 8192).Then how this will be the period?

For 50Hz the period will be 20mS.

Why using 32.768Khz crystal ?
 
Last edited:
Hi ericgibbs

I have a problem here.

If we use 32.768Khz crystal then for one second it will be 8192 counts per second (32768/4 = 8192).Then how this will be the period?

For 50Hz the period will be 20mS.

Why using 32.768Khz crystal ?

Morning Suraj,:)
My post says 4MHz for period, and a suggested 3.2768MHz for frequency.
 
yes i do thanks a mill...i'll see if i can work with that today...

hi,
This is the assembler routine I use for period measurement.
The output on a LCD.

Code:
Lcdout "Period"

period:
         bsf STATUS,RP0
         movlw %11000110  'pu off,+RB0,tmr0 1:128
         movwf OPTION_REG
         bcf STATUS,RP0

loop0:
         movlw %00000100  '1:1,intclk, tmr1 stop
         movwf T1CON  't1 ext clock input via RC0
         clrf tmr1_cnt
         clrf TMR1L  'zero timer1
         clrf TMR1H
         bcf INTCON,1  'RB0 intr
         bcf PIR1,0  'clr tmr1 INTF
         bsf INTCON,3  'enb RB0 intr

'cleared and waiting
loop1:  'await the +PB.0 intr
        btfss INTCON,1  'test for RB0 intr
       Goto loop1
        bcf INTCON,1  'clr the RB0 intf


'start tmr1
        bsf PIE1,0  'enb tmr1 intr
        bcf PIR1,0  'clr tmr1 INTF
        bsf T1CON,0  'enb tmr1

period1:
       btfss PIR1,0  'is tmr1 intr
Goto period2  'no

        incf tmr1_cnt,F  'yes inc tmr1 cntr
        bcf PIR1,0  'clr tmr1 INTF

period2:
        btfss INTCON,1  'is RB0 intr
Goto period1  'no

         bcf T1CON,0  'stop tmr1
         bcf INTCON,3  'stop all intr
         bcf PIE1,0  'enb tmr1 intr

;local registers
b2avall = TMR1L
b2avalm = TMR1H
b2avalh = tmr1_cnt
Gosub bin2asc; conversion binary to ascii

Lcdcmdout LcdLine1Home
Lcdout ascbfr7, ascbfr6, ascbfr5, ascbfr4, ascbfr3, ascbfr2, ascbfr1, ascbfr0

Goto loop0
 
periods arent measured in Hz (1/s), theyre just in s.

so your period with a 3.2MHz crystal would be about 30 microseconds...

hi,
I think you have misunderstood my post.:)

If the crystal is 3.2768MHz then the internal clock cycle is 819,200Hz, which has period of 1.221µSecs.

I would use Timer 1 in the PIC to count the internal clock cycles and the period of the mains frequency.
By setting the scaler values for Timer1, very accurate period measurements are possible.

Do you follow OK.?

EDIT:
The 4MHz and 3.2MHz in my post refer to the crystal frequency for the PIC when measuring Period or Frequency
 
Last edited:
LOL could happen.

I do recall the method used by Microchip in their X10 app note, they did not rectify the AC signal and instead compensated (the trigger level is different depending on which side of the AC signal was captured) in software.
 
hi,
I think you have misunderstood my post.:)

If the crystal is 3.2768MHz then the internal clock cycle is 819,200Hz, which has period of 1.221µSecs.

I would use Timer 1 in the PIC to count the internal clock cycles and the period of the mains frequency.
By setting the scaler values for Timer1, very accurate period measurements are possible.

Do you follow OK.?

EDIT:
The 4MHz and 3.2MHz in my post refer to the crystal frequency for the PIC when measuring Period or Frequency

quite possible...

so youve got an external crystal at 3.2768MHz, run that into the PIC with a divide by 4, so youve got .8192MHz


ohh, so youre saying pick something about 4MHz, and a 3.2MHz crystal will do fine, such that your internal clock is about 1MHz (.8192MHz), giving a period of about 1us, which will let you have accurate measurements.

sorry i misunderstood.
 
Depending on how much accuracy is required the internal 1% oscillator should be fine. Since the amount of measured pulses just has to remain constant does it matter what crystal you use?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top