Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
PORTD |= (1<<7);
DDRD |= _BV(PD7);
// Make PC6 an output PORTC.DIR = (1 << 6); // Set that output to high PORTC.OUT = (1 << 6);
find the traces and touch probes/wires?
The sound of static implies that this is a piezo transducer and not a piezo buzzer. Read a bit about them here http://www.kpsec.freeuk.com/components/other.htm#piezo. So it looks like you need a square wave with a frequency of about 4khz, which is probably what you were doing before lol....
unsigned int cycles = 30; unsigned int freq = 4000; PORTC.DIR |= 1<<6; //make PC6 an output long i; while (cycles > 0) { PORTC.OUT |= 1<<6; // buzzer pin high for(i=0;i<freq;i++); PORTC.OUT &= !(1<<6); // buzzer pin low for(i=0;i<freq;i++); cycles--; }
Ok. So logic check me please.Wouldn't this cause a 4000 Hz square wave?Code: [Select]unsigned int cycles = 30; unsigned int freq = 4000; PORTC.DIR |= 1<<6; //make PC6 an output long i; while (cycles > 0) { PORTC.OUT |= 1<<6; // buzzer pin high for(i=0;i<freq;i++); PORTC.OUT &= !(1<<6); // buzzer pin low for(i=0;i<freq;i++); cycles--; }if yes, how would I control the duty cycle?
unsigned int cycles = 20000; //make noise for 20000 * 250 microseconds = 5 seconds PORTC.DIR |= _BV(PC6); //make PC6 an output while (cycles > 0) { PORTC.OUT |= _BV(PC6); // buzzer pin high //wait for 125 micro seconds PORTC.OUT &= ~_BV(PC6); // buzzer pin low //wait for 125 micro seconds cycles--; }
hmm... what compiler are you using? my compiler does not like the PC6 or _BV function.Either way, when I just changed _BV( PC6) to (1<<6) and used delay_us(125) from WinAVR util\delay.hI didn't get this working. I'm still working on it and will report back.