element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
STEM Projects
  • Learn
  • Learning Center
  • STEM Academy
  • STEM Projects
  • More
  • Cancel
STEM Projects
Forum Creating square wave generators before buying a function generation/counter
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join STEM Projects to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 10 replies
  • Subscribers 23 subscribers
  • Views 2338 views
  • Users 0 members are here
  • raspberry pi educators design challenge
Related

Creating square wave generators before buying a function generation/counter

scsiraidguru
scsiraidguru over 3 years ago

I have been watching Karen's videos and find them interesting.   

My Siglent SDS1104X-E 100 Mhz 4 channel Oscilloscope came.  

1.) Using the built-in square wave to calibrate the 4 probes

This took a few days to get the probes as accurate as possible.   It took about 30-45 minutes per probe.


2.) Configuring a simple 1kHz square wave PWM with my Arduino

I connected up probe 1 of the scope to the output of the Arduino PWM pin to see how accurate the device was in a square wave PWM of 0, 64, 128, 192 and 255.   I wanted to see how much noise was on the Arduino using the 9V 1A power supply.   I need to dig in deeper to get the settings to get a PWM closer to 1kHz. 

https://mc.scsiraidguru.com/?page_id=2338
I posted the readouts here.   Frequency was 975 Hz.   I will recreate the test and add the measurements from the scope.

3.) Configuring a simple 1kHz square wave PWM with my Raspberry Pi 4B

The Pi 4B set to

mc.scsiraidguru.com/

pwm = GPIO.PWM(ledPin, 1000) # Set Frequency to 1 KHz    This was 886-888 Hz
pwm = GPIO.PWM(ledPin, 1149) # Set Frequency to 1 KHz    This was 997 Hz to 1.003 KHz.

4.) Purchase a 3 channel bench power supply

The next item I am looking at is the Siglent SPD3303X-E 3 channel power supply.  The frequency generator will have to wait.   I The test videos I saw on this power supply was very clean. 

5.)  Build square wave generators that are more accurate

I have been watching Karen's videos on 555 Timer and creating a 1 kHz, 10kHz, and 100 kHz square wave generator from scratch.   I have a nice selection of resistors, capacitors, and components to build with.    I thought this would be a great project to teach STEM with.    Any suggestions on getting a more accurate setup? 

5.) Create a triangle wave generator



  • Sign in to reply
  • Cancel

Top Replies

  • scsiraidguru
    scsiraidguru over 3 years ago in reply to shabaz +1
    I upgraded the scope firmware and also found the LED lights in the basement were throwing off noise that was causing the probe calibration to jump. I put the scope into alternative mode so the end was…
  • dougw
    dougw over 3 years ago in reply to scsiraidguru +1
    You can lookup several ways to make a 555 circuit that will get very close to 50% duty cycle. One simple way is to use a CMOS 555 and connect the output to the timing cap with a resistor.
  • scsiraidguru
    scsiraidguru over 3 years ago in reply to dougw +1
    The kit I bought has NE555 chips to start out with. TLC555CPWR from Digikey are $0.95. Maybe I will get some next time.
  • shabaz
    shabaz over 3 years ago

    Hi,

    I had a few miscellaneous comments:

    (1)  There's something unusual in the code, there is a loop containing analogWrite, and it will repeatedly try to execute it forever. 

    This may or may not be benign, and may even contribute to measured discrepancy or even jitter. It is down to the implementation of that analogWrite function, I have not checked, but it would be good to either check it before doing this, or (better) just do it in the setup() function, because that will be a more normal use of it. Often, functions can misbehave if used beyond what they were likely designed and tested for.

    image

    (2) The measurements from 'scopes are not necessarily accurate always. Despite it being (say) a 100 MHz 'scope, doesn't mean it is sampling with that granularity always, and it will also have it's own clock error too.

    (3) The probe compensation should take less than a minute per probe and per channel, even if doing it manually. If it's not automated, then the probe should have a trimming tool adjustment.

    (4) Not sure what you mean by a more accurate square wave, because the '555 output will almost certainly be less accurate than from the 'scope; the frequency will drift with temperature, and it's not a square wave anyway... I think from memory the 555 cannot generate a 50% duty cycle precisely due to the charge or discharge cycle having to use the same resistor (along with another), I have not checked in ages. One workaround for that is to do a divide-by-2 using logic gates, from the output of the 555 or whatever.

    (5) STEM with 555 is a great idea.. for instance using it to generate sound effects and so on. Combining more than one 555 allows you to do siren-type effects, etc. There's a very good website with 50 projects entirely related to 555: http://talkingelectronics.com/projects/50%20-%20555%20Circuits/50%20-%20555%20Circuits.html?iframe=true&width=100%&height=100% 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • scsiraidguru
    scsiraidguru over 3 years ago in reply to shabaz

    I upgraded the scope firmware and also found the LED lights in the basement were throwing off noise that was causing the probe calibration to jump.   I put the scope into alternative mode so the end was on left side and beginning of the square wave was on the right side and was able to match them up more accurately.    I am considering a Tripp Lite Line Conditioner and put in 20A circuits to isolate the Siglent hardware from the soldering iron and other noisy components.   I worked with a Siglent engineer on getting it smoother.   The scope has some error too.   On one channel I should get 1 gigasample per second.  I think with the 1 kHz frequency, that won't be much error.   It will be interesting once I get to 100 kHz frequency.   I think a lot of the scope issue was not being familiar with how to use it.  

    Arduino code loop was to keep it constantly running and not one time run.  I am planning on revisiting the Arduino and Pi solutions for PWM.  

    I will have to check into your divider by 2 logic gate solution.  It would be interesting to build.   The next purchase is the Siglent 3 channel power supply.   The Siglent frequency generator is month down the line.   My son's tuition for preschool is coming up in a few months.   So my EE budget is the least priority.  

    555 timer won't give a perfect 50% square wave.   I worked out the math for a 1 kHz frequency but the time high is 512 ms and time low is 488 ms.   This isn't that bad considering the error of 12 ms.   I played around with the common components that I have in capacitors and resistors.   Building it will be the test.   I will use my multimeter to get accurate readings on the components and redo the math.   I was hoping for 505 ms and 495 ms with 1 kHz frequency.    The new components are the sizes in between I was missing in caps and resistors.  So can use the multimeter to get the components closer to the actual math values. 

    Scope is accurate.  The resistors and capacitors are 5%-10% variance.  So a 220 ohm resistor is usually 214-222 ohm.   So what is accurate on paper in the math isn't what the component is in reality. 

    I was looking for a book on all the 555 projects I can build.   I have a good selection of op-amps and components from this months purchase to play with.   I wanted a decent scope to start out with.  All the reviews said this was a good choice. 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • dougw
    dougw over 3 years ago in reply to scsiraidguru

    You can lookup several ways to make a 555 circuit that will get very close to 50% duty cycle. One simple way is to use a CMOS 555 and connect the output to the timing cap with a resistor.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • scsiraidguru
    scsiraidguru over 3 years ago in reply to dougw

    The kit I bought has NE555 chips to start out with.  TLC555CPWR from Digikey are $0.95.   Maybe I will get some next time. 

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • scsiraidguru
    scsiraidguru over 3 years ago

    A side project is getting LT Spice to simulate the 555 timer and my circuit accurately.   During my B.EE, we put the circuit on page.  Solved it with math.   Then, we put it into Spice and compared the results.   Last thing was acutally build it measing each component with a multimeter and recalculating everything with real values.   How can I get LT Spice to better simulate a NE555?  

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 3 years ago in reply to scsiraidguru

    I was looking for a book on all the 555 projects I can build

    There's several used 555 projects books on Amazon etc., I don't think there are any new, since the 555 is quite a mature product. However the used books are sometimes pricey because they are out-of-print. The web link to the 555 projects mentioned earlier, is very good.

    I have a paperback 555 project book by E.A. Parr, it is (was) great, but the web link content is (from my perspective) better.

     Many electronics books will have a section on the 555, sometimes focussed on how to use the 555, rather than projects, depending on the book. There's a thread on good electronics books here, and most will refer to the 555 for at least a few paragraphs if not more:

    /members-area/personalblogs/b/john-wiltrout-s-blog/posts/i-want-to-do-electronics-where-do-i-start

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 3 years ago in reply to scsiraidguru

    Hi, I missed responding to this:

    Arduino code loop was to keep it constantly running and not one time run

    Sure, I understand that, however the approach to do that can be different, and it may improve the timing (can't guarantee that, since I don't know the Arduino function in detail, I've not checked the source code nor the microcontroller datasheet). In any case it's not normal to set the PWM configuration repeatedly, if the configuration has not changed.

    This would be a 'normal' approach (in slightly pseudocode):

    setup()
    {
      analogWrite(PWM_IO, 64);
    }
    
    loop()
    {
      delay(1000);
    }
    

    That code will simply do nothing in the loop() function, and do it forever. Meanwhile, the PWM hardware inside the chip will keep doing its thing (unless later instructed otherwise), based on the configuration that was done in the setup function.

    I don't use Arduino often enough to be sure if this code structure will work once the syntax is sorted, but I'm fairly sure (95%).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • scsiraidguru
    scsiraidguru over 3 years ago in reply to scsiraidguru

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • scsiraidguru
    scsiraidguru over 3 years ago in reply to scsiraidguru

    #include <Wire.h>
    
    void setup() {
      Serial.begin(9600);
      Wire.begin(0x4);                // join i2c bus with address #4
        pinMode(6, OUTPUT);
    }
    
    void loop() {
      analogWrite(6, 128);
     
    }


    set timer 0 divisor to    64 for PWM frequency of   976.56 Hz (The DEFAULT)

    The measurements of the scope matches. 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • scsiraidguru
    scsiraidguru over 3 years ago

    10 kHz square wave.   I think this is fairly good specs.

    Pin 5 : 10nF capacitor

    Capacitor: 10nF
    R2: 4.7k ohm + 2.2k ohm+ 100 ohm= 7k ohm
    R1: 330 ohm

    Frequency: 9.99kHz
    Period: 100.141us

    + width: 49.4us
    + duty cycle: 49.34%

    – width: 50.74us
    – duty cycle: 50.66%


    Still working on getting Eagle up and running with a 555 timer.

    image

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube