i want to generate a 1 mhz pulse on one of my peizo sensor and want to receive the pulse on the other disk ,now right now i have generated a 1 mhz pulse of 1 disk now i want to receive it on the other
here is my code
void setup() {
// Set Pin 9 as output
Serial.begin(115200);
pinMode(9, OUTPUT);
pinMode(4, INPUT);
// Configure Timer1 for Fast PWM, mode 14 (WGM13:WGM10 = 1110)
TCCR1A = _BV(COM1A) |1 _BV(WGM11);
TCCR1B = _BV(WGM13) | _BV(2WGM1) | _BV(CS10); // No prescaler
// Set TOP value to 15 for 1 MHz
ICR1 = 15;
// Set duty cycle (50% duty)
OCR1A = 7;
}
void loop() {
int result = 0,final = 0;
for(int i = 0;i < 100;i++)
{
result += analogRead(4);
}
final = result/100;
Serial.println(final);
delay(1000);
// Timer1 is handling the PWM generation
}
i am trying to make an ultrasonic flow meter using arduino uno and two piezoelectric disks , first 1 peizo will send pulses and the other one will receive and then vice versa after this we will calculate the flow rate
In that case, you'd have to send a pulse and then time how long it takes to be recorded by the other transducer. Then do the same thing in the opposite direction and determine flow rate. The width of the pulse as such is not very relevant as long as it's dependably picked up by the other transducer.
(edited for correctness; apologies for earlier version)
Also, I've reported your thread for being a cross-post of this here: 1MHz PWM signal on Arduino Uno
And it looks like you've been working ont he same project for a while now and keep making new threads about it. Be warned that other participants on this forum tend to respond very negatively to this way of presenting yourself. Try to keep everything related to the same project in the same thread, try to offer complete information about the context, application and your requirements, and also be clear about what kind of hardware setup you're working with including diagrams and photos so we know what you have on hand.
I doubt that a normal cheap 20KHz piezo disk will move detectably with a 1MHz signal, and even without significant attenuation between the two, that a second piezo disk would translate that motion into a detectable 1MHz signal that a 1mV/count Arduino could detect.
To show you why you can't capture a 1MHz signal using an Arduino ADC, I've done a test.
I modified your loop() function to turn pin12 high immediately before the Arduino does an analogue read, and then low again as soon as the analogue read was completed.
I used direct port manipulation so that it would have negligible effect on the speed of your code (each operation that I added only adds 62.5ns).
void loop() {
PORTB = B00010000; // turn pin 12 high
int result = analogRead(4);
PORTB = B00000000; // turn pin 12 low
Serial.println(result);
}
I monitored pin 12 on an oscilloscope together with the serial output on pin 1.
I'm feeding a 1MHz, 100mV pk-pk signal into analog pin A4.
Go back to what I summarized in #10. You don't really need to do an ADC reading. What you need, is to send a signal from one transducer so the other can pick it up. You need to record the time when the second one picks up the signal from the first. This does not have to be an analog reading. You can amplify the signal the second transducer receives so that it can be read from a digital GPIO.
The signal's amplitude is irrelevant. What matters is the delay between sending the signal and receiving it. None of this requires analog readings.