I’m designing a code for the Attiny10. Since I’m new in microcontrollers, the past few weeks I’ve been learning about them from the amazing information on this forum, from the basics, practicing with simple examples and dealing with interrupts, timers, etc. Now I feel confident to start programming the project that I wanted to do, but I’d like to share with you how I’m going to do it and hear your opinions that will make me learn for sure.
First, let me explain the project. It’s simple but challenging also (at least for me, hehe). The micro receives a PWM signal on pin 3 (it’s ICP0 so it’s possible to set up interrupts for changes in the input signal). The PWM input signal is a RC signal, i. e. duty cycle between 1000 and 2000 microseconds and frequency about 50Hz. Depending on the duty cycle of the input, a LED (on Pin 1 – OC0B) will be on/off with different patterns.
The tricky part is that the LED patterns will use PWM modes in order to fade in/out the LED, so we have one timer and 2 PWM signals to deal with. As far as I know, the Attiny10 can’t be reading the PWM input signal and producing a PWM output at the same time (there is only one timer!), so I have three options:
1 - Use timer for reading the PWM input and generate the PWM output signal by software
2 - Use timer for generating the PWM output and read the PWM input by software
3 - Alternate the use of the timer for reading and generating the PWM input/output
Option 3 is possible because I don’t need an immediate response on the output, a delay of 1s it’s not a problem, and the LED pattern will be repeated every second, so I can set up the timer to read the input -> read the input -> set up the timer to generate the PWM output -> generate one pattern (1 seccond) -> set up the timer to read the input -> LOOP
From my point of view, all three options are possible and are good, but I’d like option 3 the most since It’ll be reducing software and use more hardware. What do you think? Any other option?
Thank you in advance!