Go Down

Topic: Modulating 2 waves using arduino DUE (Read 740 times) previous topic - next topic


Hello everyone, I need a little help in this program i'm working on. I'm trying to create a gated square wave for ultrassonic equipments. I've used the arduino DUE and the code below to generate 2 square waves on pins 7 and 8 respectively.
I was using the 74LS132 logic gate to make the gating but this chip is messing my signal so bad that I cant drive the ultrassonic device.

Is there a way to make the gating in the DUE code and output the already gated signal without all this distortion?

Im generating 2 precise signals from due clock, see the program below, and it works great, I just need the gating, any help would be appreciated:

Code: [Select]
#include <Arduino.h>

const unsigned long serialPeriodMillis = 2000;
unsigned long previousMillis = 0;

void setup()
  int32_t mask_PWM_pin = digitalPinToBitMask(7);
  REG_PMC_PCER1 = 1 << 4;                         
  REG_PIOC_PDR |= mask_PWM_pin;                   
  REG_PIOC_ABSR |= mask_PWM_pin;             
  REG_PWM_CLK = 0;                               
  REG_PWM_CMR6 = 0 << 9;                         
  REG_PWM_CPRD6 = 1300;                         
  REG_PWM_CDTY6 = 650;                           
  REG_PWM_ENA = 1 << 6;                           

  int32_t mask_PWM_pin1 = digitalPinToBitMask(8);
  REG_PMC_PCER0 = 1 << 4;                       
  REG_PIOC_PDR |= mask_PWM_pin1;                   
  REG_PIOC_ABSR |= mask_PWM_pin1;                 
  REG_PWM_CLK = 16;                               
  REG_PWM_CMR5 = 0 << 9;                       
  REG_PWM_CPRD5 = 30000;                       
  REG_PWM_CDTY5 = 9000;                         
  REG_PWM_ENA = 1 << 5;                         

  Serial.println("Serial on");

void loop()
  if (millis() - previousMillis > serialPeriodMillis) {
    previousMillis = millis();



What do you mean by " without all that distorsion"  and " I need the gating" ?


What do you mean by " without all that distorsion"  and " I need the gating" ?

The gating is the signal beign gated by another signal, like a pulse train with an interval between pulses. To do this, Im getting both signals and feeding them in an AND gate, which outputs a signal with an interval between pulses, this is the gating in the signal.

But, although both signals are crystal clocked without any distortion (no spur harmonics or noise in the frequency domain), when I fed both to the 74LS132 AND gate chip, the output signal gets all noisy and jittering...

I was wondering if its possible to output this gated signal directly from arduino to avoid all this problem that the logic gate is causing.


Is it something like this that you want to emulate an AND gate:

digitalWrite(output_pin, digitalRead(inputA_pin) && digitalRead(inputB_pin));

Where inputA_pin is the output of a first PWM signal, inputB_pin the output of a second PWM signal and output_pin the logic result ?

Of course you can replace digitalWrite / digitalRead with direct register manipulation and perform this logic AND at the pace you need with a Timer Counter.


I was wondering if its possible to output this gated signal directly from arduino to avoid all this problem that the logic gate is causing.
The hardware solution should work, but you still have to be careful with the analog properties of digital signals.

I think what you are trying to do is create a burst of 64kHz of duration 100us about every 350 us? If that is the case, I would use a timer interrupt to generate the low frequency "gating" signal, and use that interrupt to turn the 64 kHz on and off.

Please ask questions in the forum so everyone can benefit. PM me for paid work.

Go Up