Pages: [1] 2   Go Down
Author Topic: Zcd(500Hz) Sin(50Hz) change output Zcd to 50Hz  (Read 988 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Please help me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?????
« Last Edit: May 17, 2013, 06:39:20 pm by Sreenu » Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You want to read the output of the Arduino with your Arduino? Ignore 9 of 10 pulses.

I don't understand your question.

Cheers,
Kari
Logged


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

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Count the incoming signal changes. When the count reaches ten, change the outgoing signal and reset the count to zero.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13734
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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?
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Please help me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't understand your question.

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????

« Last Edit: May 17, 2013, 06:39:52 pm by Sreenu » Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Please help me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* Pwm_Zcd.jpg (79.78 KB, 706x440 - viewed 45 times.)
« Last Edit: May 17, 2013, 11:36:46 pm by Sreenu » Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Please help me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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???
Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

What you need is a timer that starts when a pulse arrives and generates an interrupt (or toggles a pin) when it times out - the timeout of that timer is set by the incoming ADC reading.  I don't know enough about the internal workings of the Atmel timers, but perusing the data sheet for the 328P it looks like you might be able to do it with one of the 16 bit timers in Input Capture mode.  When the pulse arrives the timestamp of the timer is recorded and an interrupt is generated.  In that interrupt you turn off your output pin and save the timestamp to a variable.  In your main loop you then examine the timer's current value, and if the difference between that and the recorded timestamp is sufficient compared to the ADC value read (probably mapped to a suitable range) then turn the output pin on.  The next pulse will trigger the interrupt again and the whole cycle repeats itself.  I guess there may be a way to use a second timer to do the turn-on portion for you - during the input capture interrupt you configure a second timer depending on the ADC value to trigger an interrupt at the right time - at that point you turn the pin on, and disable the second timer (you don't want it free running, now do you).  That then leaves your main routine free to deal with things like reading the ADC and mapping the values to the right range for the timers to use.

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

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Please help me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

please reply 


* ACWave.png (65.89 KB, 960x720 - viewed 30 times.)
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13734
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need a state variable and do something like this.

Code:
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?

 
Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 16
Please help me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: May 19, 2013, 06:03:58 pm by Sreenu » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34213
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In he code from the AC phase control, replace
Code:
OCR1A = i;     //set the compare register brightness desired.
if
With
Code:
OCR1A = temp;     //set the compare register brightness desired.
if
Where temp is derived from your temprature reading.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13734
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Rob Tillaart

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

Pages: [1] 2   Go Up
Jump to: