Producing an opposite signal from output compare...

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I want to drive a piezo and there are two ways.  Maximum volume comes alternating both signals at the same time like this:

 

 

  DDRD|=_BV(6) | _BV(7);

  TCCR2A=_BV(COM2A0) | _BV(COM2B0) | _BV(WGM21);

  TCCR2B=_BV(FOC2A) | _BV(CS22) | _BV(CS21);

  OCR2A=127;

  OCR2B=127;

 

If I want half volume I can set the OCR2B higher than OCR2A.

 

Does anyone see an issue with this method?  Could the two get out of sync with each other (as if the FOC2A) somehow?  Would it be better to do something that forces these directly?  Like set the COM2A1:0 bits to clear, set the COM2B1:0 bits to set, then write FOC2A and FOC2B to clear one and set the other, then change both the COM2A/COM2B bits to toggle again?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, the two halves will NOT get "out of sync" because both are tied to specific counter values. 

 

You do, however, need to make sure that the piezo element does not cause voltages or currents in excess of those allowed for regular port pins.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sun. Aug 18, 2019 - 05:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My Piezo's needed me to GND the output pins when idle , the DS said they didn't like to be left if an active state, as it would wear them down.

 

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good thought Bingo; I wondered about that.

 

Just a question - if I disable COM2B0 and run the timer for awhile and then restart COM2B0, depending on where it stops and starts, could it get out of alignment?

 

I think I'm probably going to shut it all down into a known state and reinitialize it to make sure it is right, but I wondered....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alan, does your project have any op-amps?

If you had a "spare" one, then you could easily configure it as an inverter, and let it drive one side of the piezo.

That costs you a small chip, (board space wise), but saves you an I/O pin, and any other hassle regarding synching them.

 

I'd think holding a voltage on a piezo might matter for high powered units, (sub sonar array, industrial washers, etc.).

It would be an interesting experiment to see if 3 or 5 V bias applied to one impacts its sound output if held in a charged state for a year, or two.

 

JC