Going Beyond Arduino # 8: PWM as a Digital to Analog Converter

  Рет қаралды 37,810

Craig Hollinger

Craig Hollinger

Күн бұрын

Пікірлер: 31
@flywittzbeats4008
@flywittzbeats4008 Жыл бұрын
you are so smart that explaining things simply just comes natural to you
@craighollinger9972
@craighollinger9972 Жыл бұрын
Thanks!
@vex123
@vex123 Жыл бұрын
Nice video. Can you help explain why you need a triangular/sawtooth signal compared against an actual sine wave to compute the duty cycle?
@craighollinger9972
@craighollinger9972 Жыл бұрын
The sawtooth waveform and the sine waveform were both produced in the same manner - varying the duty cycle of each pulse by changing how long the timer/counter had to reach the count. The difference between the two waveforms is the number the counter counts up to (the value in the output compare register). With the sawtooth, the number put into the output compare register started at 255 and counted down by one for each pulse, a simple linear change. The values that produced the sinewave came out of a table and the change between successive values changed in a sinusoidal manner. In the two videos linked below, I go into more detail on how to setup a timer/counter. kzbin.info/www/bejne/pGGwf6WXhbyEj9E kzbin.info/www/bejne/haezYmCwhZaMY80 I hope this answered your question.
@satviksharma1146
@satviksharma1146 5 жыл бұрын
Very helpful video . Thank you
@craighollinger9972
@craighollinger9972 5 жыл бұрын
Thanks for watching!
@ahmedladhibi6893
@ahmedladhibi6893 3 жыл бұрын
hello Mr.Hollinger , i have a question. When is the intterupt set? OCR0A take every time a new value , does that mean that the interrupt time is different each time ?
@craighollinger9972
@craighollinger9972 3 жыл бұрын
The Timer 0 interrupt is enabled in the first part of main(), and remains enabled. The interrupt is generated when Timer 0 counter reaches the value in OCR0A. The time the interrupt occurs changes each time as set by the value read from SINE_TABLE. The code is available on my gitHub site. Link in the description.
@newsairobot1513
@newsairobot1513 3 жыл бұрын
Thank you for this video,! I'm thinking of using the MCU to directly control the stepper motor?
@craighollinger9972
@craighollinger9972 3 жыл бұрын
You can, provided the MCU has enough drive capability (current) for the motor you choose. With a very small, low-power motor it is possible.
@MilanKarakas
@MilanKarakas 8 жыл бұрын
Excellent video. Is there way to do analog to digital conversion by sampling one analog input, then feed this values to the register to get audio (for example) out? I know that analog input has 10 bits, but this can be divided by 4 (or making twice right shifting, or "PWMstuff=AnalogValue>>2"). I will need it once getting work on 433 MHz digital radio communication with Si4432. So far I managed to understand how it works, just need little bit more practice. Thank you again for really good video.
@craighollinger9972
@craighollinger9972 8 жыл бұрын
The ATMEGA328 is not a very powerful device, it's working hard enough to produce the sine wave. A way more powerful ARM chip might be able to do what you want. Either way, no microcontroller will have the guts to DDS 433MHz. I have another video in the works that demonstrates proper DDS. Stay tuned and thanks for watching.
@MilanKarakas
@MilanKarakas 8 жыл бұрын
No DDS. I have Si4432, RF chip, which can run from 240 MHz to 960 MHz. Just need analog to digital in this chip, and digital to analog from this chip to speakers. Thanks anyway.
@MilanKarakas
@MilanKarakas 8 жыл бұрын
Or, voice over digital... similar like truncated radio...
@craighollinger9972
@craighollinger9972 8 жыл бұрын
Oh, I think I see what you are up to. My next video shows a much more efficient way to generate DDS than what I demonstrated in this video. I should be posting it in a day or so. In it, I demonstrate a DDS system that uses an interrupt service routine running at 50kHz to update the PWM. I had a quick perusal of the ATMEG328 datasheet. The fastest the AD converter can do a conversion in is 13us, so you may be able to digitize audio at the same 50kHz rate as the DDS (slightly better quality than a CD player). Add some code to the same interrupt service routine to start and read a conversion. You can set up the ADC so that it left shifts the converted data in its two data registers, then you can read just the high register to get the upper 8-bits. No need to do a right shift in software. I don't know how you are going to handle all that ADC data though, 50,000 bytes per second have to be put somewhere. A lower sample rate, say 8kHz, would reduce the amount of data, but still produce good enough audio quality to be intelligible. Good luck with your project.
@Rov-qc2ti
@Rov-qc2ti 6 жыл бұрын
Nice explanation!
@andysar11
@andysar11 5 жыл бұрын
Hi...is it possible to generate two short pulses of 1microsec and another two pulses of 40 microseconds with variable prf?
@craighollinger9972
@craighollinger9972 5 жыл бұрын
It is, but you may have to write some of the code in assembly to make it fast enough. Even with the ATMEGA328 running at 16MHz, code generated by a C compiler may not be efficient enough to give you a 1usec pulse. Good luck.
@mojojomo6750
@mojojomo6750 7 жыл бұрын
I remember doing the sine-table thing almost 30 years ago while in college and was surprised then at the low max-frequency I could achieve - just over 400Hz if memory serves. So I'm even more surprised that the Arduino's 328 chip can only manage 240Hz - that must have 4-5 times the clock rate of the 4Mhz Z80 CPU I was using,
@craighollinger9972
@craighollinger9972 7 жыл бұрын
The method I presented in this video is very inefficient at producing a sine wave (or any other repetitive waveform for that matter). The microcontroller updates the waveform 256 times every cycle. Therefore the update rate has to be 256 times faster than the frequency of the output. Check out the next video in my series (if you haven't already done so) where I present a different and more efficient method of generating repetitive waveforms. Link: kzbin.info/www/bejne/bIK7nZqNhJWnqZI Thanks for watching.
@KJ7JHN
@KJ7JHN 5 жыл бұрын
Does the output compare register use a switch statement with a set duty cycle per case?
@craighollinger9972
@craighollinger9972 5 жыл бұрын
The PWM is all done in the ATMEGA328 hardware.
@TheMafyta
@TheMafyta 8 жыл бұрын
Nice video, keep going
@craighollinger9972
@craighollinger9972 8 жыл бұрын
Thanks!
@messaoudiabderrahim6447
@messaoudiabderrahim6447 6 жыл бұрын
hi i am a student and i have a project "solar inverter on grid using arduino " can you help me please ? thanks
@craighollinger9972
@craighollinger9972 4 жыл бұрын
Your question is lacking details. Start with doing a search on the internet, you'll find lots of information there that can help you.
@mskogmo
@mskogmo 3 жыл бұрын
One question: we learn a lot of C functions in your turtorials, but is there a reference manual where all this is published? Maybe an official C manual or something? Or do we just have to learn more or less systematic through different turtorials on the web?
@craighollinger9972
@craighollinger9972 3 жыл бұрын
Kerningham and Ritchie 'The C Programming Language', second edition. Dennis Ritchie designed the C language. I have the paper-back book, but I understand it is also available as a PDF. Good luck with your studies.
@victoreng5234
@victoreng5234 7 жыл бұрын
Graig, I did copy the CODE, it did not work for my vision "UNO". Here is the message : "compilation terminated. exit status 1 Error compiling for board Arduino/Genuino Uno." Can you help ? Sorry, I am a beginner. Thank you so much Veng
@craighollinger9972
@craighollinger9972 7 жыл бұрын
Unfortunately that code was not written for the Arduino system, hence the error. This is true for all of the code I have written for my 'Going Beyond Arduino' series. If you watch the first couple of videos in the series, you'll see where I explain how to write, compile and program code into an Arduino board without using the Arduino system. This is the theme of the video series - getting out of the Arduino world so you have more control over the microcontroller. Good luck with programming. Don't be discouraged when you run into problems and have to spend some time solving them. You will learn so much more than if everything works the first time.
@victoreng5234
@victoreng5234 7 жыл бұрын
Thanks for your reply, Graig, I will let you know after watch other tutorial that you posted.
Going Beyond Arduino # 9: PWM as Direct Digital Synthesis
23:13
Craig Hollinger
Рет қаралды 10 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 15 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 110 МЛН
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 15 МЛН
Using the MCP4725 12 Bit DAC with Arduino
14:06
Gadget Reboot
Рет қаралды 38 М.
Digital to Analog Converter using PWM
10:57
bitluni
Рет қаралды 115 М.
Best 10 Items I Tested in 2024!
20:12
Project Farm
Рет қаралды 497 М.
16-Bit DAC / PWM on Arduino UNO - Ec-Projects
21:06
EcProjects
Рет қаралды 74 М.
Converting an Arduino PWM Output to a DAC Output
18:48
ForceTronics
Рет қаралды 111 М.
Analog output from PWM and a low-pass filter
14:13
nLab
Рет қаралды 11 М.
PWM DAC - Ripple Cancelation
12:31
All Electronics Channel
Рет қаралды 2,8 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 15 МЛН