Go Down

### Topic: Zcd(500Hz) Sin(50Hz) change output Zcd to 50Hz (Read 3059 times)previous topic - next topic

#### Sreenu

##### May 14, 2013, 01:16 amLast Edit: May 18, 2013, 01:39 am by Sreenu Reason: 1
Please suggest me methods for the conversion 500hz output to 50hz output using arduino

How do i read output in the 10th cycle if thats the only answer??

#### GaryP

#1
##### May 16, 2013, 10:05 am
You want to read the output of the Arduino with your Arduino? Ignore 9 of 10 pulses.

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

#### PeterH

#2
##### May 16, 2013, 02:45 pm
Count the incoming signal changes. When the count reaches ten, change the outgoing signal and reset the count to zero.

#### robtillaart

#3
##### May 16, 2013, 07:54 pm

is the original a square wave or a sinus or otherwise wave?

Can the incomcing signal have other frequencies, e.g. is it varying with a top of 500Hz?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Sreenu

#4
##### May 18, 2013, 01:19 amLast Edit: May 18, 2013, 01:39 am by Sreenu Reason: 1

The Zcd wave is at 500Hz, 10 times faster than the sin wave which is at 50Hz. I want the Zcd to be triggered with every raise and run till the fall of the sin wave.
But that is not possible without me changing the 500Hz to 50.

Any solution???

is the original a square wave or a sinus or otherwise wave?
Can the incomcing signal have other frequencies, e.g. is it varying with a top of 500Hz?

50Hz sin wave which is full rectified. Zcd output is a square wave which varies with the temperature at 500Hz.

There is a function called "attachInterrupt()" . It has the parameters attachInterrupt(interrupt, function, mode) where
interrupt: the number of the interrupt (int).
function: the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an interrupt service routine.
mode: rise, fall, high, low

Can I put the Zcd function in the "function" mode as "rise"  to get my desired output?

#### Retroplayer

#5
##### May 18, 2013, 04:58 am
You are trying to create a zero crossing detector? Check this out:

http://e2e.ti.com/support/amplifiers/precision_amplifiers/f/14/t/184352.aspx

You can use a decade counter to reduce the 500hz to 50Hz. It should work with a sine wave, but the output will be an integrated squarewave.

When you say ZCD, you are talking about a Zero Crossing Detector, and this is what is confusing. The Zero Crossing Detector is a function, not an input. Please post a detailed explanation of what you are trying to do from beginning to what you want as a result. That will better help people to help you.

#### Sreenu

#6
##### May 18, 2013, 06:30 amLast Edit: May 18, 2013, 06:36 am by Sreenu Reason: 1
I need my pwm waveform which is in 500Hz to sync with ZCD which is in 50Hz

Please find the attachment which shows the required wave form.

The PWM varies with temperature.

Thank you

When you say ZCD, you are talking about a Zero Crossing Detector, and this is what is confusing. The Zero Crossing Detector is a function, not an input. Please post a detailed explanation of what you are trying to do from beginning to what you want as a result. That will better help people to help you.

#### majenko

#7
##### May 18, 2013, 12:00 pm
Let me get this straight...

You have 2 signals - a rectified sine wave for zero crossing detection, and a PWM square wave where the duty cycle gives you the temperature from a sensor?

Ok, you could, as has been mentioned, pass the ZCD detection signal through an integrator of some form to give you a digital signal - a threshold level would be set to give a low pulse at a suitable width when the waveform drops below that level (a simple comparator [op-amp] can do this).  That can be used as your timing base.

Then you could take the PWM signal and low-pass filter it to give a varying voltage between 0 and Vmax (peak voltage of waveform, or 5V if higher - read up on voltage dividers for that clipping), which you can then read with an ADC input.  That ADC value can then be used to set the duty cycle of an output PWM signal which uses the incoming integrated ZCD signal as a timebase.

You won't be able to generate that PWM using just analogWrite() as the timing will be off.  There may be a way to do it using the facilities of the timer in the Atmel chip to sync the PWM to that ZCD pulse, but easier would be to just write your own soft-pwm system that watches for that pulse, turns off an output, and starts counting - turns it on again at the right time depending on the ADC reading.

#### Sreenu

#8
##### May 19, 2013, 07:04 am

You have 2 signals - a rectified sine wave for zero crossing detection, and a PWM square wave where the duty cycle gives you the temperature from a sensor?

"Yes, I have these two signals."

Pass the ZCD detection signal through an integrator of some form to give you a digital signal - a threshold level would be set to give a low pulse at a suitable width when the waveform drops below that level (a simple comparator [op-amp] can do this).  That can be used as your timing base.

Here the comparator is the integrator you mentioned???

Then you could take the PWM signal and low-pass filter it to give a varying voltage between 0 and Vmax (peak voltage of waveform, or 5V if higher - read up on voltage dividers for that clipping), which you can then read with an ADC input.  That ADC value can then be used to set the duty cycle of an output PWM signal which uses the incoming integrated ZCD signal as a timebase.

You won't be able to generate that PWM using just analogWrite() as the timing will be off.  There may be a way to do it using the facilities of the timer in the Atmel chip to sync the PWM to that ZCD pulse, but easier would be to just write your own soft-pwm system that watches for that pulse, turns off an output, and starts counting - turns it on again at the right time depending on the ADC reading.

Is there any simple coding methods to achieve this???

#### majenko

#9
##### May 19, 2013, 01:33 pm

You have 2 signals - a rectified sine wave for zero crossing detection, and a PWM square wave where the duty cycle gives you the temperature from a sensor?

"Yes, I have these two signals."
Quote

Pass the ZCD detection signal through an integrator of some form to give you a digital signal - a threshold level would be set to give a pulse at a suitable width when the waveform drops below that level (a simple comparator [op-amp] can do this).  That can be used as your timing base.

Here the comparator is the integrator you mentioned???

A comparator is basically a saturated op-amp (infinite gain) where the output is on or off depending on the relative levels of the two inputs.

Yes.  Compare the incoming voltage to a threshold voltage - the threshold defines the width and accuracy of the pulse generated - a lower voltage gives more accurate results but a narrower pulse.  An ideal pulse would last zero time, which would give you the exact moment of zero crossing, but that's not possible.  On top of that the voltage drop of the rectifier circuit will give a small trough at the zero crossing which will give an absolute minimum time for the pulse width.

Try this little demo circuit out for size: Falstad - Requires Java

The potentiometer sets the threshold voltage - the higher the voltage the wider the pulse generated, but also the further from the crossing point the pulse covers.
Quote

Quote

Then you could take the PWM signal and low-pass filter it to give a varying voltage between 0 and Vmax (peak voltage of waveform, or 5V if higher - read up on voltage dividers for that clipping), which you can then read with an ADC input.  That ADC value can then be used to set the duty cycle of an output PWM signal which uses the incoming integrated ZCD signal as a timebase.

You won't be able to generate that PWM using just analogWrite() as the timing will be off.  There may be a way to do it using the facilities of the timer in the Atmel chip to sync the PWM to that ZCD pulse, but easier would be to just write your own soft-pwm system that watches for that pulse, turns off an output, and starts counting - turns it on again at the right time depending on the ADC reading.

Is there any simple coding methods to achieve this???

Well, at a 50Hz signal rectified you'll be getting 100Hz pulses.  That's 10ms between pulses - not very long really, so using millis() is not really going to cut it - also you can't guarantee that a pulse will arrive at the start of a millisecond - it's more likely to arrive partway through.

Unless there's a better way of configuring the timers? (Atmel experts please chip in here...)

#### Sreenu

#10
##### May 19, 2013, 04:31 pm
http://playground.arduino.cc/Main/ACPhaseControl

This link says about phase control ... this is very close to the result I need BUT....

The trigger i need varies with the temperature ->duty cycle

that is the t1(in fig) depends on the duty cycle which is achieved by the varying temperature which is in the t3 range.

Can any one suggest a variation in the code from the link. Assuming that there exists a function temp() which returns a value that is the duty cycle.

#### robtillaart

#11
##### May 19, 2013, 07:17 pm
You need a state variable and do something like this.

Code: [Select]
`bool signalOut = false;void loop(){  float value = 10 * sin( millis() *2PI / 1000UL);  if (pulseDetect() == true) signalOn = true;  if (abs(value) < 0.00001) signalOn = false;  // zero detect // comparing floats should never be done with an ==  if (signalOn)   {    serial.print(value, DEC);  }  else  {    serial.println(0, DEC);  }}`
BTW is this a school assignment?

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Sreenu

#12
##### May 20, 2013, 01:02 amLast Edit: May 20, 2013, 01:03 am by Sreenu Reason: 1

You need a state variable and do something like this.
BTW is this a school assignment?

Its my college project and I am trying to implement phase control instead of voltage control.
State variable as in??

You need a state variable and do something like this.
Code: [Select]
`bool signalOut = false;void loop(){  float value = 10 * sin( millis() *2PI / 1000UL);  if (pulseDetect() == true) signalOn = true;  if (abs(value) < 0.00001) signalOn = false;  // zero detect // comparing floats should never be done with an ==  if (signalOn)   {    serial.print(value, DEC);  }  else  {    serial.println(0, DEC);  }}`

Again this gives a constant pulse at the zero cross but I needs its position change according to the varying temperature which gives a duty cycle.

#### Grumpy_Mike

#13
##### May 20, 2013, 07:21 am
In he code from the AC phase control, replace
Code: [Select]
`OCR1A = i;     //set the compare register brightness desired.if `
With
Code: [Select]
`OCR1A = temp;     //set the compare register brightness desired.if `

#### robtillaart

#14
##### May 20, 2013, 09:58 am
Quote
State variable as in??

signalOn is the state variable that holds the visibility of the sinus signal.

imagine you have a constant sinusoidal signal and only when signalOn is true it shows its value on the output, otherwise it shows the zero level.
in the loop this signalOn var is constantly updated

Code: [Select]
`if (abs(value) < 0.00001) signalOn = false;  // zero detect // comparing floats should never be done with an ==`
This line can fail,
it is better to check the value against its previous value. If it passes a certain value (typically 0) ==> act.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up