Go Down

Topic: Generating Square Wave with with modulated carrier frequency (Read 14212 times) previous topic - next topic

CrossRoads

Looks like it's working to me.
Frequency is not changing, and width of the positive portion is varying.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nehe_bhimaji

Dear Sir
I Have tried your modified  sketch result is like that
1. When Switch D2 Pressed I get  Square wave roughly 18 KHZ  but nothing change while POT  varies from 0 to 100%
   its  image is attached
2.When Switch D2 Open I get some Notches  in wave its image is attached

I have also check the Pot input at A0 input it seems from 0 to 5V varying while POT turns from 0 to 100%
Please suggest necessary changes in sketch.If possible explain sketch in details so that I will think on it
Thanks

nehe_bhimaji


Dear Sir
I Have tried your modified  sketch result is like that
1. When Switch D2 Pressed I get  Square wave roughly 18 KHZ  but nothing change while POT  varies from 0 to 100%
   its  image is attached
2.When Switch D2 Open I get some Notches  in wave its image is attached

I have also check the Pot input at A0 input it seems from 0 to 5V varying while POT turns from 0 to 100%
Please suggest necessary changes in sketch.If possible explain sketch in details so that I will think on it
Thanks

Please go through following you tube link .There is Video of waveforms that I expect from Arduino UNO
http://youtu.be/fcaQiYgS3Ts
Thanks

polymorph

I can see space-time in your images. 3200x2400....
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

nehe_bhimaji

Dear sir
Have you check my you tube video link
Please check and suggest some sketch how I can generate the same
Thanks

polymorph

That waveform is either badly locked on, or there is something going on.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

nehe_bhimaji




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

Link Is As Below
http://www.youtube.com/watch?v=fcaQiYgS3Ts&feature=youtu.be

CrossRoads

Code: [Select]

// 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;
//}
while(1){
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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

screen shots
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

screen shots
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

polymorph

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

nehe_bhimaji

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

CrossRoads

One needs to be a better programmer than I to achieve the results you want with Arduino.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

polymorph

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?
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

CrossRoads

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:
http://www.gammon.com.au/forum/?id=11504
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up