I began to think about the things necessary to build a table tennis robot. Next to the construction itself a lot of motors are needed!
I found a motor including a mounted wheel for accelerating the ball - it consumes 500mA at 3V. A second motor is needed for applying the spin. I need a lot of servos for different tasks, some are weak (consuming 150mA at 5V) others strong (consuming 1A at 5V). The RaspberryPi itself will need approximately 1A at 5V. The last part is a stepper which will drive the push mechanism to move the balls to the accelerating wheel. That stepper will consume about 1A at 12V. So I will need a lot of current at 3V (1A), at 5V (~5A) and at 12V (1A).
But wait a minute: aren't those voltages provided by a regular ATX power supply? Yes they are. Except 3V but 3.3V will work as well.
There are some projects out there providing an ATX power supply for driving a RaspberryPi. But wouldn't it be boring simply ordering another part? It is much more interesting to build a circuit on my own. And this is what I did:
On GitHub you can find all information how to build it on your own:
https://github.com/RasPelikan/raspberrypi-atx
On our company's Christmas celebration (December 2013) all employees got a small present: A Raspberry Pi. This was the initial event for me to investigate what (internet of) things can be done driven by this tiny computer.
This blog is to document my findings and to share what others shared with me.
Mittwoch, 19. April 2017
Sonntag, 26. Februar 2017
Table tennis robot
Unfortunately it is a long time ago that I wrote a blog post. I was on the way to build a mowing robot.
On the way I had to invent a lot of things. Some of them are:
On the way I had to invent a lot of things. Some of them are:
- For Pi4J:
- Pull request - Added MCP44xx, MCP45xx and MCP46xx families to pi4j-i2c-devices
- Pull request - New Concurrency in I2CDeviceImpl and I2CBusImpl
- AVR-projects:
- Eclipse-Plugin - Use usbasp programmer to show up UART in Eclipse
- Gadget - A silver screen remote controller
So what now?
In the last fall my sun started playing table tennis. Due the fact that this is some sort of "farther and son"-thing I also learn table tennis. And after the first lessons I recognized that it would be fantastic the use a table tennis robot for the training. A robot would be able to place every ball to the same spot, with the same speed and the same spin. So you can focus on refining your technique. As always you can buy a cheap model which won't make you happy on the long run or you take a lot of money and buy a good model. Or, you DIY :-) ... which not necessarily means that you will be happy on the long run :-)=)
In the very beginning a saw a lot of Youtube videos showing DIY table tennis robots. But I also looked videos of professional robots to get inspired. And after a couple of days I knew that I want to build a robot which one day might be better than professionals. But step by step:
- The first "version" should be similar to those cheap models: They sit in the middle of the table and shoot the balls to the left, to the middle or to the right. The cheap robots only know top-spin oder under-spin. My robot should be able to create every spin (top, under, left, right, combinations). Additionally it should also be able to shoot faster or slower in combination with up- and down-directions. And, of course, a ball recycler: A net which collects all the balls I return during practicing and brings them back to the robot to shoot them again.
- Once this works I want to build a rail on which the robots moves. This should enable an advanced training mode and generates shoots like a human player would do. Additionally the ball-cannon should be able to move up and down. Especially for this version I can reuse a lot of things I already bought for building the mowing robot.
- And in the end I want to add a RaspberryPi camera module to track the ball and move the robot not only in predefined ways. It should move along the returning ball to shoot the next ball from the place the returned ball hits the collector net. This should give a feeling as playing with a person.
In the last three months I tried some of this features to see whether I could make it. And yes, it seems to be makable. So I will report about the progress, the problems and the solutions in the upcoming posts.
Samstag, 10. Januar 2015
LPS - Sending radio signals
A lot of things have to be considered if you want to send and receive a signal. I want to list those and my conclusion about them.
1. Radio-traffic
I intend to send a signal to a reference-location and the reference-location should return the signal. Doing so brings up two problems:
-
The frequencies which can be used for general-purpose transmissions are limited. For example within the EU 433Mhz or 868Mhz may be used. So every garage-door-opener or weather station uses one of this frequencies which means you will receive a lot of noise made by other people's gadgets.
To filter signals sent by the mowing robot to a reference-location I have to encode the data in a certain way which can only be decoded by the reference-location. To do so dedicated ICs can be used. I prefer HT12E as encoder and HT12D as decoder. But there are also other products available like PT2272 (Encoder) and PT2262 (Decoder). Those ICs encode a couple of bits into a stream signed by an "address". The decoder-ICs are listening for a certain "address" and spit out the bits set to the encoder once the address matches. In short: You don't have to be concerned about other people's signal-noise by using those ICs.
- Another issue is about bidirectional communication. Every communicator needs a sending- and a receiving-modul. So if the the mowing robot sends out a the signal its own receiving-modul will pick up the signal, too. In the same way the reference-location's receiving-modul will pick up the response.
Sending any signals occupies the receiver. This means that the mowing robot cannot receive the response during transmission. At a first look this does not seem to be a problem, but for longer distances the duration of the sending has to be increased to guarantee a successful transmission. In this situation it might be that the success is already there in the very first milliseconds of sending. If the reference-location starts responding immediately the mowing robot's receiver will no see the signal because its own sender is transmitting a signal much stronger.
This situation can be avoided in two ways: The easier one is to use another frequency for sending the response. Unfortunally I could not find an easy-to-use sending-modul available in both frequencies. So I have to use the second way which is by responding to the robot's signal after a certain amount of time, when the reference-location can be sure that the robot's transmission is complete. The downside of this way is that a lot of time is wasted. At the moment I cannot tell for sure but I guess using two frequencies is about 2-10 times faster. At a distance of 25 meters this means the robot will be able to contact only 3-4 reference-locations instead of 6-8 per second.
2. Sender-/Receiver modules
I was looking for cheap modules and found this:
- Sender = FS1000A
- Receiver = XY-MK-5V
They are pretty cheap and use very little current in standby mode (available at DX or Semaf). The amount of energy needed to run a reference-location is a critical issue. I will write about this later. For the moment: less is better.
Above, I mentioned that I could not find those modules at 868Mhz. There were other modules which do 868Mhz but they has to be connected by I2C or SPI. A pair of the modules introduced here can conceptionally be used in the same way as a cable. This is pretty easy and can be used in any electronic circuit without the need for a microcontroller.
The most websites reporting about the FS1000A-module tell that the range of transmission is from 2 to 200m. The actual value depends on several attributes:
- The module can be run at different voltages (3V to 12V). A higher voltage means bigger range.
- For the receiver-module a 5V supply is required so it would be easiest to apply 5V to the sender-module, too. Due to the noise at the frequency of 433Mhz I cannot tell how far the signal reaches, but something above 50m.
- The modules itself may send only a couple of centimeters. They have to be extended by antennas (both sender and receiver) to gain more than 1m. I soldered a 1/4-antenna (simple cable in a 17.3cm length) at the proper pins.
- At the outer ranges the signal is weak. So even if the range is 100m I won't be able to read any data or identify those data as mine at 100m.
- I was able to build a stable communication at a distance of 30m using a 5V-supply. For that I have chosen to stretch the signal as much as possible (lowest oscillation frequency - see datasheet of HT12E and HT12D). Additionally I set the enabled-pin of HT12E to active for 90ms. In this time the stream generated is repeated again and again. Usually one or two of those sequences could be read by the receiver at a distance of 30m. If the noise was low it worked up to 50m.
- Noise: I've mentioned it already above. The noise influences the quality of transmission and therefore the distance of possible communication. This has to be kept in mind for processing the ranges for position triangulation: The circuit will measure different values for the same distance in dependence to the current environment conditions.
3. Transmission attributes
I already mentioned that it is necessary to increase the time of sending for longer distances. The greater the distance between receiver and sender the more other radio-traffic of the same signal strength (of other people's gadgets) will disturb the transmission.
In addition to this effect the speed of transmitting has to be reduced for longer distances. This does not mean to modify the frequency. The HT12E-IC encodes the information I want to transmit into a stream of 0 and 1 digits. If I have longer distances the whole transmission has to be stretched not repeated more often. So for short distances a 1-digit might be successfully read if it is 0.1ms but for longer distances the noise scrambles the 1-digit so it has to be 1ms to be detected as a 1.
In the first try I will use constant duration and constant speed of transmission. Each value is selected so that it works at the longest distance I want to reach. To optimize the number of reference-stations to track per second I will try to decrease the duration and increase the speed of transmission in dependence of the distance. I intend to do this by transmitting the distance to the reference-station because the strategy I want to use for measuring the distance does not require transmitting a specific value - it only requires transmitting anything. So why not sending a value which can be used for optimization?
What's next? Let's take a breadboard and build a reference-location. Oh, wait. All my breadboards are in use. It seems I have to get them free. Stay tuned to what this means ;-)
Montag, 5. Januar 2015
LPS - The idea
For the mowing robot it is vital to know at every point in time at which location within a certain area (the garden) it is. Most robots that are available in the stores need cables put into the ground to define this area. Thoses cables are detected by the robot so that it knows when it reaches the border and has to turn around. The robot never knows its exact location and drives around at random. To find the base-station a special tracking-cable has to be placed which is passed by the robot from time to time. My garden is pretty big and it would be difficult (but not impossible) to place those cables. Additionally robots waste a lot of time and energy driving at random since they pass a lot of locations several times.
I want my robot to drive a certain path so that it passes every specific location only one time. For that reason I need some sort of ranging. The borders of the area should be known by the robot. If there is some sort of ranging the borders can be honored by it. How does the robot know about the borders? There will be a special administration-mode in which I will steer the robot by remote-control along the borders and it will record those positions.
So the requirements for location-tracking/ranging are:
One possiblity is to use sonic. An example for a ready-to-use module is HC-SR04. But there are limits prohibiting sonic for local positioning:
So what's left? Radio! But radio-signal cannot be used in the same way as sonic is used to measure distances. HC-SR04 is measuring the time-gap between sending and receiving the signal. This works because sonic is a slow signal. Radio works at the speed of light so a distance of 10cm is passed in the time of the 2,997,924,580th part of a second. This is too short to be measured.
So this is the idea:
I build reference-locations which receive radio signals sent by the mowing robot and return those signals immediatally. The robot will listen for the response. The mowing robot's signal can only be returned, if it is strong enough to reach the reference-location. So I increase the signal strength in a loop by a very small amount starting at zero. Once I get an answer I know the signal strength which is in any correlation to the real distance. If I do this for at least three reference-locations and I know about the correlation between the signal strength and the distance I am able to calculate the local position. So far so good.
To proof this, three things have to be done:
I want my robot to drive a certain path so that it passes every specific location only one time. For that reason I need some sort of ranging. The borders of the area should be known by the robot. If there is some sort of ranging the borders can be honored by it. How does the robot know about the borders? There will be a special administration-mode in which I will steer the robot by remote-control along the borders and it will record those positions.
So the requirements for location-tracking/ranging are:
- The resolution has to be close to 10cm.
- Power consumption has to be low.
- Most of measuring-work should be done by a circuit to relieve Rasperry Pi's CPU.
- Standalone-GPS resolution yields about 2.5-1m (depending on the number and kind of satelite-signals receiving). I was wondering about this since geometers use GPS to place landmarks up to a resolution of 1cm. Searching the web gave me the answer: They use differential GPS. D-GPS uses a second GPS-receiver at a reference-location. The raw-signals of both locations can be used to get more precision relative to each other. Geometers use public reference-stations which provide their raw-signal through a special internet-protocol. But those services are not free and building my own reference station is too complicated.
- GPS-receivers consume a lot of energy (at least 100mA at 3.3V - this is not very much, but less would be nice).
One possiblity is to use sonic. An example for a ready-to-use module is HC-SR04. But there are limits prohibiting sonic for local positioning:
- The signal has to be directional, but usually the direction of those reference-locations are unknown.
- The maximum range is 3m - the distances in my garden is bigger than 3m ;-)
- Objects between the reference-locations (f.e. children's toys) disturb the signal.
So what's left? Radio! But radio-signal cannot be used in the same way as sonic is used to measure distances. HC-SR04 is measuring the time-gap between sending and receiving the signal. This works because sonic is a slow signal. Radio works at the speed of light so a distance of 10cm is passed in the time of the 2,997,924,580th part of a second. This is too short to be measured.
So this is the idea:
I build reference-locations which receive radio signals sent by the mowing robot and return those signals immediatally. The robot will listen for the response. The mowing robot's signal can only be returned, if it is strong enough to reach the reference-location. So I increase the signal strength in a loop by a very small amount starting at zero. Once I get an answer I know the signal strength which is in any correlation to the real distance. If I do this for at least three reference-locations and I know about the correlation between the signal strength and the distance I am able to calculate the local position. So far so good.
To proof this, three things have to be done:
- Build the robot's sending-unit and a reference-location-unit.
- Test whether increasing signal-strength for measuring the distance is reliable/reproduceable.
- Learn about the correlation between signal-strength and distance.
Dienstag, 13. Mai 2014
Building PCBs - Part 2: Two sided PCBs
In my last post I used the toner transfer method to build a PCB. Sometimes the arrangement of nets of a layout get pretty complicated or impossible to figure out. Even auto-routing fails or results in arrangements hard to work with.
In this case it might be better to use a two sided layout: Whenever a net cannot reach its target you can use vias to switch to the other side and go on easily. For the H-bridge IC I use to run motors (see Control motors - Part 4: H-Bridge) I need a two sided PCB so let's see how this can be done using the toner transfer method.
![]() |
Two sided PCB |
First of all you need PDF-files of the mirrored layout of the top and bottom layer. They have to be printed to toner transfer paper. Afterwards I punched the 3mm holes at the edges of the layout which are needed to screw the board into a box. Now I put one layout on the copper and used a permanent marker to amplify the holes made before. After this you can remove the layout and you will see the positions for drilling those holes. The next step is to drill the holes.
Now you have two layouts printed to toner transfer paper and the board - all parts with holes at the same position. After cleaning the board the next step is to iron the layouts onto the board. Now I arrange the first paper using the holes: they have to match exactly. Next I put the iron on the stack for some seconds to make the paper stick on the copper. After this the board can be flipped to repeat the procedure for the second side using the remaining print. If both papers stick well you can flip the board several times to ensure each side is ironed as explained in my last post. The rest of the story is the same as for single sided PCBs: Peel off the media, etch the board and remove the residing toner.
![]() |
The upper side of the board after toner transfer... |
![]() |
...and the lower side. (the dark areas are minor defects I fixed using permanent marker) |
After etching the board you can drill the holes needed for common elements or vias. Do not drill through the board. Sometimes the position of the layout is not as exact as it should be and drilling through could break nets of the second side. I drill from both sides to the middle of the board - similar to digging a tunnel. If the hole does not match exactly it does not matter. The elements can be soldered even if the hole is displaced a little bit.
![]() |
After etching and drilling you can see how exact your work was. I'm satisfied :-) |
First note: If you prefer transparent film you can orientate the layout as shown in this post: http://www.instructables.com/id/Two-sided-PCB-using-toner-method/.
Second note: You might asked yourself which kind of vias I use. None! I build vias by soldering strand on both sides of the board. Before doing this I put the board on two stencils. This builds a distance which helps to ensure that both sides can be soldered well. After soldering the excrescent strand can be cut off.
Dienstag, 6. Mai 2014
Building PCBs
A lot of things happened since my last post! I got a lot of new modules needed by my mowing robot (RF, distance sensors, 3-axis compass, charging IC, and so on). I have to investigate them before I can use them. This will be very interesting and a lot of fun ;-)
Unfortunately my breadboards are full and I have to bring all the stuff to circuit boards. So the next step is to learn how to produce those boards.
First of all you have to design your board. There is a lot of free software available. I tested Fritzing and Eagle and both do a good job. The disadvantage of Fritzing is it's limited elements-library and the disadvantage of Eagle is it's complexity since this is a professional tool. So I will use Fritzing for simply boards and Eagle for complex ones.
Both programs offer to order boards for professional production. This is pretty expensive although the boards offered by Fritzing and Eagle are low-cost-boards. So what is the solution? DIY!
Usually the nets of circuit boards form by etching copper of non-conducting areas. But how to "tell" where copper has to be removed and where not? Professional boards are created by using light exposition: the copper is hidden by a layer of light sensitive paint, the inverted board will be printed on a transparent film used to expose the board and acid will remove those exposed areas (and the nets resist).
This also can be done at home but at home it is not that easy:
This also can be done at home but at home it is not that easy:
- The exposition can get blurred due to shadows if the film is not fully plain.
- You see errors and mistakes not until the board is etched. So erroneous boards only can be trashed.
- Boards coated with light sensitive paint are much more expensive then boards without that layer.
So DIY guys figured out another way: The toner transfer method. This technique is taken from bringing images to T-shirts or cups. The layout is printed to some sort of media using a laser printer and afterwards pressed under heat onto the target. The toner melts and goes to the target. This works best if the target's surface binds the toner better then the transfer media does. For T-shirts and cups special transfer paper is available.
For copper boards it is a little bit more complicated but not much. Most guys out there use any sort of glossy advertising media. After printing (mirrored) it has to be ironed onto the board. Afterwards it has to be put into water (for about 10 minutes) so the media can be rubbed off. There is no instruction which media works best - it depends on your laser printer. Some media is too thin and will not work. Some media binds the toner too much and paper cannot be removed completely. Additionally you put paper into your printer that isn't meant to be used in a laser printer and may damage the printer.
Instead of advertising paper transparent film for overhead projectors can be used. This works good but not reliable good. So at the end I managed to get this special toner transfer paper (used for cups) which works best for me.
Anyway: you have to find out what works best for you. This may be a little bit frustrating but you can be sure that there is a way for every laser printer.
How it works:
Instead of advertising paper transparent film for overhead projectors can be used. This works good but not reliable good. So at the end I managed to get this special toner transfer paper (used for cups) which works best for me.
Anyway: you have to find out what works best for you. This may be a little bit frustrating but you can be sure that there is a way for every laser printer.
How it works:
- Clean your board
This is essentially for the binding of the toner. Any bit of dust will lift the paper and the toner won't bind! Any fingerprint brings tiny bits of oil onto the board and the toner won't bind! So clean the board precisely and keep it clean.
I do a three-step cleaning. First, I use stove cleaner and scrub the copper in small circles. After this the board has to be washed and dried. Second, I use steel wool to polish the copper. Third, I use Acetone to remove any oil. It seems to be essentially to use a clean board otherwise the toner does not bind well.
- Prepare the transfer media
I use that special transfer paper. In my case there are four things to take care of:
First, print the layout mirrored and tell your printer to use as much toner as possible. Second, toner transfer paper is very soft. I can see patterns of the laser printer's transport-wheels on the paper after printing. These patterns decrease the quality of the printed layout in this regions so you should avoid printing in this regions by choosing a proper position. If the layout is too big to avoid this then try to reduce the number of SMD-elements or other small things in this regions. Third, the paper cannot be reused so print the layout as many times as possible on one sheet. Maybe your first try fails and you need another print for the second take. And fourth, avoid touching the transfer media to reduce oil of your fingerprints.
- Iron the layout onto the board
Put the transfer media on the board with the layout down to the copper. Put some sort of cloth on it. Preheat your iron. The toner starts to melt at approximately 180°C. This is usually the setting between cotton and linen. Which temperature is properly also depends on the thickness of the transfer media and the cloth. Put your iron onto the stack and wait 5 seconds. Now the layout sticks at the current position and you can start to move around. The bottom of the iron is not hot equally so you also have to turn the iron around. Put some pressure on the stack. How much depends on the thickness of the transfer media and the cloth. Thicker means more pressure. The whole layout should contact the copper equally over the time of ironing. You should stop ironing if all regions of the layout are at 200°C. You might ask when this is achieved and I have no answer for you. You will see whether it was too hot, too long or too much pressure if you remove the transfer media. If so the toner has melt to blobs, especially at bigger areas of toner, and the borders are not clear.
One trick I use is to vary only one aspect: I always use a timer to count the time of ironing and stop always at the same time. On different tries I only change heat or the pressure. This should help to figure out what your personal best settings are.
- Remove the transfer media
Wait for cooling down the board and peel off the transfer media. If your media is transparent film you can use some ice because the toner and the media decreases differently on cooling down rapidly and the toner will lift off from the film almost completely.
Review your board carefully! Some failures can be corrected by using a permanent marker. Take care that all nets are separated to avoid shortens. If there are nets together (for example near SMD-sockets) you can scrub the toner away by using the spot of a sharp knife.
If the result isn't satisfying then try again. Remove the toner using Aceton and start at step 1. It is better to repeat the process then trashing a board after etching it. It took me several approaches the get a useful result! So don't be inpatient.
- Etching the board
This is quite easy. I use Natrium-Persulfat. It is easy to handle and easy to store. Some acids are gassing so you cannot close the canister completely which means you have to store it outdoor since the gas is poisonous. Natrium-Persulfat can be stored in a bottle made of glass or plastic. But keep it away from children - it is an acid!
The only disadvantage of Natrium-Persulfat is that it works best at 50°C. So I put the liquid into microwave oven for some seconds and put it on a towel afterwards to keep it warm as long as possible. If it cools down too fast you can but the tank into hot water until temperature is properly again.
After about 10 minutes the board is ready. Take a closer look a nets which are close to each other to be sure that all copper is gone. I use my cell phone's camera which takes nice pictures much more detailed than I'm able to see without any optical support.
- Remove the resisting toner
The last step is quite easy. Use Aceton to remove the toner. And after this the board is ready for further steps (for example drilling the holes).
Here some pictures I've taken:
![]() |
My first try using a transparent film as transfer media |
![]() |
Another try: You can see light spots where dust was between the transparent film and the copper |
![]() |
Sometimes toner resists on the transparent film. |
![]() |
Special toner transfer media. Click to enlarge to see the patterns of the laser printers transport wheels. |
![]() |
A layout on copper using toner transfer media. Good and reproducible quality. |
![]() |
Etching the board - after 5 minutes. |
![]() |
Etching the board - after 8 minutes. Watch the bubbles! |
![]() |
Etching the board - after 10 minutes. It is nearly done - there is some copper left (click to enlarge). |
![]() |
Waiting for etching the last bits of copper. |
![]() |
The final result after remove the toner - pretty nice! |
![]() |
Another try using toner transfer paper: I wanted to know how good it is using bigger layouts. |
Samstag, 8. März 2014
Control motors - Part 3: Digital PWM - Part 2
When I wrote "Control motors - Part 3: Digital PWM" I thought everything would work fine but time told me different (in German we say: theory is gray but practice is colored).
The first thing I built was the clock. To make development easier I used a slow clock and put a LED at the output to visualize the signal:
The next step was to install the counter. One thing I had to change was to count down instead of up because presetting to 1 by using the cascading output did not work: the signal is high from the beginning of 0 until the end of 14, becomes low in the middle of 15 and high again at the end of 15 (which is equal to the beginning of 0). I had to invert the signal since the preset-pin is low in inactive state but this means that the rising from low to high used to preset a value is in the middle of 15 - not at the end! This shortcuts the last unit.
A possible solution could be preseting the value asynchronously (which means to tell the IC within a clock-cycle to use the presetted value at the beginning of the next clock-cycle) but unfortunately the ICs I bought did not support this feature. Another solution is to delay the signal for the half of a clock-cycle by inserting a capacitor. This didn't work either. Additionally this way seems unstable to me. I always prefer to use things in the way they ment and if an IC does not support a feature I have to find another which does.
At the end I had to count from 15 to 0 and preset the value to 15 once 0 (= minimum-pin active) is reached:
In the last step I added the comparator IC. I simulated the input-values (the percent of the PWMs duty-cycle) which will be given by Raspberry Pi's GPIO-pins by using four microswitches - each for one bit. Let me show you the possible input and output-values:
The LEDs from right to left: Bit 4, bit 3, bit 2, bit 1 and the clock-signal. The IC counts from 15 to 1 and then starts at 15 again.
In the last step I added the comparator IC. I simulated the input-values (the percent of the PWMs duty-cycle) which will be given by Raspberry Pi's GPIO-pins by using four microswitches - each for one bit. Let me show you the possible input and output-values:
Signal sent by GPIO-pins | Condition | Output-signal | |
---|---|---|---|
0-0-0-0 = 0 | > or = to counter | always 0 (= 0%) | |
0-0-0-1 = 1 | > or = to counter | 1 if counter is 1 otherwise 0 (= 6.67%) | |
.... | |||
1-1-1-0 = 14 | > or = to counter | 1 except counter is 15 (= 93.33%) | |
1-1-1-1 = 15 | > or = to counter | always 1 (= 100%) |
As you can see this is a clean PWM-signal from 0% to 100%. And here is the video showing the signal:
In the middle of the breadboard is a blue LED showing the PWM-signal. At the beginning there is no light because no microswitches are pressed which means input 0-0-0-0 (= decimal 0 = 0%). Then I pressed the switch for bit 1 which means 0-0-0-1 (= decimal 1 = 6,67%). Next I pressed the switch for bit 2 which means 0-0-1-0 (= decimal 2 = 13,33%). Afterwards I pressed the switch for bit 3 which means 0-1-0-0 (= decimal 4 = 26,67%). And finally I pressed the switch for bit 4 which means 1-0-0-0 (= decimal 8 = 53,33%). To complete the row I pressed all switches additionally which means 1-1-1-1 (= decimal 15 = 100%). In every state the output-LED shows the proper duty-cycle.
At the end I replaced the big capacitor of the clock by a smaller one and the LED switched from blinking in the rhythm of the PWM to lighten more or less brighter - as expected. But suddenly the 0% stage was not "no light" instead it was slightly lightening even hard to see. Where is this current coming from?
Before I tell you, I have to admit that I had an error in reasoning: For the motors I want to use I have to apply a 2kHz PWM-signal. So I bought a capacitor for the clock-IC (NE555) to produce this frequency. But in fact if the desired PWM-frequency is 2kHz and we divide each cycle into 16 steps the clock for driving the counter-IC has to run at 2*16 = 32kHz.
Finally I could figure out that what I saw was the result of something called glitch. It occurs if the rising from low to high is to slow and the IC is to slow or clock signals delay due to long distances. So rising from 2kHz to 32kHz made glitches visible. As suggested by Stefan (see "Control motors - Part 3: Digital PWM") I replaced all ICs by pendants of the 74LS series. This didn't solve but cleared out the problem as these ICs switch faster:
But what is the solution? Generally it seems (as Google says) that a buffer should remove glitches. A buffer is a combination of two NOT-operations in serial. The resulting signal is the same as the original input-signal. Glitches should be removed because usually logical IC accept voltages below 1/3 as low and above of 2/3 as high. If the glitch is lower than 1.67V (5V * 1/3) than the buffer should clear out the correct signal. But this did not work for me. I assume that my glitch is near to 1/3. So I had to find another solution.
This short video shows the breadboard in the dark. The clock-LED turns on and off so fast that it seems to be turned on continuously. The blue-LED which shows the PWM-signal is slightly lightened although the input-signal is 0-0-0-0 (no microswitches pressed).
Before I tell you, I have to admit that I had an error in reasoning: For the motors I want to use I have to apply a 2kHz PWM-signal. So I bought a capacitor for the clock-IC (NE555) to produce this frequency. But in fact if the desired PWM-frequency is 2kHz and we divide each cycle into 16 steps the clock for driving the counter-IC has to run at 2*16 = 32kHz.
Finally I could figure out that what I saw was the result of something called glitch. It occurs if the rising from low to high is to slow and the IC is to slow or clock signals delay due to long distances. So rising from 2kHz to 32kHz made glitches visible. As suggested by Stefan (see "Control motors - Part 3: Digital PWM") I replaced all ICs by pendants of the 74LS series. This didn't solve but cleared out the problem as these ICs switch faster:
Every time a cycle completed (counter has reached 0 and will be presetted to 15) the glitch is visible by a short blink of the output-visualizing LED.
But what is the solution? Generally it seems (as Google says) that a buffer should remove glitches. A buffer is a combination of two NOT-operations in serial. The resulting signal is the same as the original input-signal. Glitches should be removed because usually logical IC accept voltages below 1/3 as low and above of 2/3 as high. If the glitch is lower than 1.67V (5V * 1/3) than the buffer should clear out the correct signal. But this did not work for me. I assume that my glitch is near to 1/3. So I had to find another solution.
Finally I figured out that this also can be achieved by using a flip-flop. A flip-flop is the mechanism which enables a computer's memory to store binary stages (true or false => 1 or 0 => high or low). They work in this way: You have to provide an input-signal and tell the flip-flop to store that input. From now on, even if the input changes, the stored signal is provided at the output. There are several types of flip-flops but I used the D-type which depends on a clock signal. So the solution is to ignore values (also glitches) within clock-cycles and use the value at the beginning of a cycle (doing a snapshot by using the flip-flop) during the whole cycle. And indeed it works like a charm.
This was the first problem in electronics which I solved on my own. No Google - just thinking. I was very proud at this moment :-)
This was the first problem in electronics which I solved on my own. No Google - just thinking. I was very proud at this moment :-)
The ICs from the left to the right: flip-flop (SN74LS74AN), or (SN74LS32N), comparator (SN74LS85N), counter (SN74LS191N) and time (TLC555). In this version I replaced the microswitches by pull-up-resistors.
In the next weeks I will build a lead frame and a circuit diagram for this. I will update the post by adding these two things as soon as this is done.
Abonnieren
Posts (Atom)