Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWM on TX pin? #14

Open
chupocro opened this issue Dec 29, 2018 · 5 comments
Open

PWM on TX pin? #14

chupocro opened this issue Dec 29, 2018 · 5 comments

Comments

@chupocro
Copy link

In your example you are generating PWM signal on 20 channels and one of them is PD1 which is TX pin so I expected garbage in the terminal but there wasn't any although I tried various serial speeds in both the firmware setting and the terminal setting :-/ How is that possible and how can Serial.print() work in the same time (and without any interference) with software PWM on TX pin?

BTW, it would be great if you added the fade in/out parameters as in the other one SoftPWM library. Fade out is useful not only for driving LEDs but for driving DC motors as well.

@Palatis
Copy link
Owner

Palatis commented Jan 1, 2019

  1. fot the tx pin, i have no idea.......

  2. for the fade-in/out/in-out/out-in/whatever, no. this lib will and always will only do one thing.

@Palatis
Copy link
Owner

Palatis commented Jan 1, 2019

i think the animation ahould be done separately.

@chupocro
Copy link
Author

chupocro commented Jan 3, 2019

Yes, I agree the animation when using the library for LED strips should be done separately. However, the library could be very useful to drive small DC motors too (using the appropriate driver) where optional fade-out parameter could be used to run the motor with deceleration so it can stop nicely.

I'll further investigate why generating the PWM signal on TX pin doesn't break Serial.print() as I expected it would.

Thanks for the reply
Regards

@Palatis
Copy link
Owner

Palatis commented Jan 6, 2019

well for what I mean, this lib will focus on generating software PWM on pins, not altering PWM level values by itself.

the alternation of the PWM level (for whatever purpose) should be done separately in another lib.

codes inside the ISR should be as little as possible (both footprint-wise and time-wise), for those long-period and not-so-percise requirements, i'd rather leave them in loop().
ex. the "fade-out" for servo motors doesn't really break your application if it's 500ms or 501ms, similar for LEDs.

@chupocro
Copy link
Author

chupocro commented Jan 7, 2019

Yes, generally ISR should be as fast as possible but there are always exceptions. For example I've years ago made an electronic device based od ATmega8 where complete code runs inside ISR and where there are even occasions when ISR routine takes more time than there is time between interrupts - which is something that generally should be avoided but I made that on purpose and I was counting T-states (cycles) after disassembling the code generated by the compiler and used oscilloscope to check all the timings one more time.

As for the driving DC motors and changing the duty cycles in a loop - yes that is one of the ways but I have to drive 9 DC motors plus make some calculations, parse the I2C messages and read the data from lookup tables at the same time so I had to put the code for changing the duty cycle inside the ISR. I based the software PWM code on AVR136 - Application Note for implementing Low-jitter Multi-channel Software PWM for AVR series microcontroller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants