ATTiny85; order of magnitude loss of speed when enabling map AnalogRead function

Jiggy-Ninja:
But don't do that yet. That will be for your final validation checks after we think everything is working. You have an issue where changing the pwmmax value does not change your waveform like it should. Focus on that first.

I suspect the problem is that, because you are setting Dir to +2 immediately before incrementing Pwm every loop cycle, your code is ignoring Pwmmax and blowing past it, overflowing past the top of a uint8_t and going back to 0. It stops for the delay when it goes back up (not down) to Pwmmin.

To test this, fix INTERVAL and rampLength to some sensible values, them screenshot a scope trace with PWMmin set to 0 and mx set to 50. Take another trace with min set to 200 and max set to 255. Optionally, take third scope trace with min = 100 and max = 150. Since I'm suspecting overflow, the point of these debug tests is to get the pwm limits as far away from the limits of the integer type as possible, so if the value is straying outside that limit in some way, it becomes blindingly obvious.

For all the shots you post, be precise about how what you are seeing is different from what should be created. Use numbers that you expect to measure. Mathematical expressions of the relationships of the measurements are fine too, as long as you are precise about it. For the second one of the tests, it might be like "Ramp from pwmmin (about 4V) to pwmmax (5V) in x microseconds, then ramp down from max to min in the same amount of time. Hold the min voltage for INTERVAL milliseconds, then repeat the cycle." That is a properly precise description.

Good day Jiggy-Ninja

Please see attached scope shots of the requested info. regarding pwmMin & pwmMax.
They are BOTH working and the values look to scale.

Thanks for the suggestion on that! :slight_smile:

take care, peace
lost_bro