you are so smart that explaining things simply just comes natural to you
@craighollinger9972 Жыл бұрын
Thanks!
@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 Жыл бұрын
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.
@satviksharma11465 жыл бұрын
Very helpful video . Thank you
@craighollinger99725 жыл бұрын
Thanks for watching!
@ahmedladhibi68933 жыл бұрын
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 ?
@craighollinger99723 жыл бұрын
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.
@newsairobot15133 жыл бұрын
Thank you for this video,! I'm thinking of using the MCU to directly control the stepper motor?
@craighollinger99723 жыл бұрын
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.
@MilanKarakas8 жыл бұрын
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.
@craighollinger99728 жыл бұрын
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.
@MilanKarakas8 жыл бұрын
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.
@MilanKarakas8 жыл бұрын
Or, voice over digital... similar like truncated radio...
@craighollinger99728 жыл бұрын
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-qc2ti6 жыл бұрын
Nice explanation!
@andysar115 жыл бұрын
Hi...is it possible to generate two short pulses of 1microsec and another two pulses of 40 microseconds with variable prf?
@craighollinger99725 жыл бұрын
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.
@mojojomo67507 жыл бұрын
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,
@craighollinger99727 жыл бұрын
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.
@KJ7JHN5 жыл бұрын
Does the output compare register use a switch statement with a set duty cycle per case?
@craighollinger99725 жыл бұрын
The PWM is all done in the ATMEGA328 hardware.
@TheMafyta8 жыл бұрын
Nice video, keep going
@craighollinger99728 жыл бұрын
Thanks!
@messaoudiabderrahim64476 жыл бұрын
hi i am a student and i have a project "solar inverter on grid using arduino " can you help me please ? thanks
@craighollinger99724 жыл бұрын
Your question is lacking details. Start with doing a search on the internet, you'll find lots of information there that can help you.
@mskogmo3 жыл бұрын
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?
@craighollinger99723 жыл бұрын
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.
@victoreng52347 жыл бұрын
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
@craighollinger99727 жыл бұрын
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.
@victoreng52347 жыл бұрын
Thanks for your reply, Graig, I will let you know after watch other tutorial that you posted.