Generating Square Wave with with modulated carrier frequency

That waveform is either badly locked on, or there is something going on.


Dear sir
Have you check my you tube video link
Please check and suggest some sketch how I can generate the same
[Please go through following you tube link .There is Video of waveforms that I expect from Arduino UNO

Link Is As Below

// variable declarations
unsigned long currentTime;
unsigned long previousTime;
unsigned long elapsedTime;
unsigned long duration = 55UL;
int analogVal;
// etc.

void setup(){
pinMode (2, INPUT_PULLUP);
pinMode (3, OUTPUT);
digitalWrite (3, LOW); // just in case
void loop(){
//if ((PIND & 0b00000100) == 0){ // is button on D2 pressed (to GND) 
//analogVal = analogRead(A0)>>5; // result is 0 to 31 
analogVal = 18;
currentTime= micros();  // all time elements are unsigned long 
elapsedTime = currentTime - previousTime; 
if (elapsedTime >=duration){  // 55uS defined as 55UL 
previousTime = previousTime + duration; // set next rising edge 
PIND = 0b00001000; // toggle D3

while (micros() <= ((previousTime + 28) + analogVal)){ 
// hang out until half period of 18 KHz plus pot delay 
// end waiting for half period 
PIND = 0b00001000; // toggle D3, falling edge 
} // end time period check 
} // end loop\

Limitations of micros() prevents that fine a resolution.
I took out the pot reading and just used a hard value.
Looking at a scope in single-shot mode, you can see changes up to about 16 or 18, after I think the code runs out processing time and the waveform stops changing. micros() has a resolution of about 4uS, I think will prevent the smooth change like you are seeing with your other card.

screen shots

DS0003.BMP (1.37 MB)

DS0004.BMP (1.37 MB)

screen shots

DS0005.BMP (1.37 MB)

DS0006.BMP (1.37 MB)

I don't get the OP's video.

Dear Sir But as per your sketch and screenshots there is change in Pulse width as we change analog value.In my case I think pulse width remains constant and there is some brust mixing of carrier frequency .May be I am wrong.Expect some good idea to achive the same Thanks

One needs to be a better programmer than I to achieve the results you want with Arduino.

I am having a hard time understanding what it is you want.

Is that a square wave with a variable width portion on the falling edge that is modulated by some higher frequency? Because all I see are two bright lines.

Can you draw a sketch that clearly shows what you want this to do?

Yes, he's after 18 KHz square wave, 50/50 duty cycle minimum, that increases to nearly 100% from a pot adjustment. I don't believe you can get there blink without delay style. Maybe with discrete timers:

That isn't what it looks like in his Youtube video.

I don't know then.

We need more information. Turn down the brightness on your scope and zoom in.

Dear Sir
I have attached original board block diagram.They have used ATMEGA8 controller for it.Basically it is used for generating mechanical vibration in a PAN.
Another thing I have take a changing part of the waveform and zoom it by Increasing Timebase .I surprise by seeing the carrier pulses in it but due to limitation of my oscilloscope I can not zoom it further.

Waveforms that i have seen after zooming is attached here

So you're doing analog mixing of two digital timer signals.

Dear Sir How this can achive using arduno uno I think that is the mixing of two timer waveforms

Start by reading about the timers and setting them up here

Hard to say from your scope shot how often the 2nd timer is delay past the 1st to make the jittery looking output.

Dear Sir According to there board scheme I think they have used timer 1 to generating the waveform guaging it due to used of pin PB2 and PB3 .But I am unable to understand how they will toggle the same pin of timer to generate the jeters.Any idea to do it Thanks

We need a clear definition of the signal needed.