Equivalent to "tone()" function #426
-
Hello there :) I'm new to arduino and I wanted to start learning it by using Rust since I have extensive experience with the language, but not really in electronics. That is a new world to me. I'm learning how to use a "passive buzzer" and how to adjust the tone by changing the frequency of the output Pin. I'm honestly having a hard time understanding how to do this using I see that in Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Coming to the basic formula But I'm afraid its not that simple since there are "timers" involved and stuff like "Prescalers" (About which I don't have much idea how they work, only the basics but its quite confusing) Would the following code produce 500hz~ ??
Is there a more sofisticated way I can go with by using PWM pins and tweaking the timers? The way the timers work and all the prescale stuff is super confusing to me, if someone wants to share some resources or explain to me as if I was 5 years old I would appreciate it <3 |
Beta Was this translation helpful? Give feedback.
-
The pwm-trait in embedded-hal 0.2.x s a bit under-specified. That's why it was discarded in the current alpha versions and is under rework. Understanding how Timer / PWM hardware peripherals work is essential if you want to work with embedded-mcu. Try to study around it but here is a short rundown.
This is just the rough idea with details missing. The best place to learn is directly interacting with the registers itself, witch you can do here. First you should know how the peripheral is build. To do that the best way is to read the datasheet of the processor itself. If you are using an arduino i assume something like an arduino uno that has an Atmega328p processor. Read this https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf chapter 14-17 are the different Timer/Pwm peripherals on that board |
Beta Was this translation helpful? Give feedback.
The pwm-trait in embedded-hal 0.2.x s a bit under-specified. That's why it was discarded in the current alpha versions and is under rework.
Understanding how Timer / PWM hardware peripherals work is essential if you want to work with embedded-mcu. Try to study around it but here is a short rundown.