Pulse Generator Semantics

k1ng 1337

Joined Sep 11, 2020
1,038
That would be great!
I'm not sure what the designers meant in that document meant because they don't show a waveform.

In any case, here is an easy way to generate a square wave. The ATmega328p is a good chip but not so good for stuff like this unless you get crazy with the hardware timers. Modern processors are much faster which offer more reliability for your calibration. This code uses PWM which means the duty cycle is represented by up to 1024 quantization bits. The formula is:

For a 50% Duty Cycle at 10kHz:

QB = (1024) (On Time / Total Time)

QB = (1024) (50us / 100us) = 512

C-like:
#include <TimerOne.h>
//UNO only

void setup()
{
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);

Timer1.initialize(100);  // Frequency, 100us = 10khz
Timer1.pwm(9,512);       // 50% DC on pin 9

//Timer1.pwm(10,255);    // 25% DC on pin 10

// D.C.
// 10KHz
// You can use 2 to 1023
// 0 & 1 gives a constant LOW
// 1024 gives a constant HIGH
// 2 gives ~125ns HIGH pulses
// 1023 gives ~125ns low pulses
// 512 gives 50us
}

void loop()
{
}
This code works best at low frequencies and with duty cycles close to 50%. Not sure if it will be good enough for what you need because I calculated one of the duty cycles to be over 99%. This may distort the signal so much that your instrument wont be able to identify the transitions from high to low.

I've just realised that the scope agrees with my definition - the trigger is set to 'falling edge'.
How is the signal being generated? Can you take two photos of the same signal with trigger on rising vs falling edge?
 
Last edited:

Thread Starter

StevoKeano

Joined Jan 13, 2024
15
Neat, I've updated to 4.49hz and 100usec pulse. Will see it when if the DS1202Z-E arrives in my lifetime...

Code:
#include <TimerOne.h>

void setup() {
  pinMode(9, OUTPUT);

  // Set Timer1 to generate interrupts every 222,717 microseconds (4.49 Hz)
  Timer1.initialize(222717);

  // Configure PWM on pin 9 with a 100 microseconds pulse (duty cycle: 100/222,717)
  Timer1.pwm(9, 23);  // Adjust this value for the desired duty cycle
}

void loop() {
  // Your main code (if needed)
}
Thank you for getting me restarted!
 

boostbuck

Joined Oct 5, 2017
1,044
How is the signal being generated? Can you take two photos of the same signal with trigger on rising vs falling edge?
Hahah, my source is my ancient homebrew TCXO, all I have to hand as I have moved house and everything is packed away who-knows-where, so making do with a limited collection of stuff I have dug out. A simple decade divider to give me a range of frequencies. I've meant to update it for years, but it works....
20240116_072742.jpg

Trigger, no surprises:
20240116_073040.jpg 20240116_073047.jpg
 

k1ng 1337

Joined Sep 11, 2020
1,038
Hahah, my source is my ancient homebrew TCXO, all I have to hand as I have moved house and everything is packed away who-knows-where, so making do with a limited collection of stuff I have dug out. A simple decade divider to give me a range of frequencies. I've meant to update it for years, but it works....
View attachment 312789

Trigger, no surprises:
View attachment 312787 View attachment 312788
What is the min-max voltage? It looks like the signal is 0-5V with your scale offset +2.5V.

If this is the case, the rising edge is on the transition from 0-5V which is an increase in potential and the falling edge is on the transition from 5-0V which is a decrease in potential.

Going back to my simulation with the negative voltage, the same rules should apply.

Your signal in post 26 is in the same location on the screen in both photos with only the trigger indicator having shifted on the x axis. I asked because this is the same observation I made. This suggests to me my original assertion was correct. What do you think?
 
Last edited:

boostbuck

Joined Oct 5, 2017
1,044
Even using AC coupling, the rising edge is the one that transitions from bottom to top of the screen, so I maintain my assertion, unless you can show me a scope of true negative pulse (0V to -5V ) that demonstrates my error.
 
Top