Math problem causing glitch

Hey there,

Im looking for someones help that really understands data types. Especially for math equations. This code I'm working on is dual pots that control frequency and duty cycle. I modified this code online i found called NANOPWMac, its originally a PWM two pots that allow u to cycle from 1Hz-1MHz with adjustable duty. I have used this in many many applications but it always had a glitch when changing duty cycle, I can see my analog input is very clean very steady as it adjusts on my scope but when i get close to 0 duty, say 4-0% i get a scattered glitch. Doesnt change width just glitchs freq. I have modified this a ton of times but all my changes have helped so far.

This I used at first for my cnc machine, this is for a tesla coil modulation handheld driver connecting to a fiber optic cable.

I did fixed this once, I just had to change some variable assignment from int to float maybe float to unsigned long not sure but I know for a fact it was that simple of a fix, problem is I cant find where i saved the damn file so one of u can see where this could originate from that would be awesome!!!

Thanks

NanoPWMac.cpp (1.61 KB)

NanoPWMac.h (2.55 KB)

Tesla_Modulation_Driver_8_6_19.ino (2.27 KB)

Okay did some tweaking, I got this now smooth no glitch but if UNSIGNEND LONG DUTY goes bellow 1 on serial mon, I even tried float and tried .99 it starts to glitch still. Now I got it to what 99.90 duty, thats cool with me but is there a simple line of coding i can change this added statement so I just can shut off pin 9 and 10.. im using 10 i know there just opposites. but I tried digital write(10,LOW); didnt do crap, Tried using { NanoPWMac_off(); return; } does turn off but glitches still. So this should be easy, I would think. How can I turn pin 10 off full low(have a 10k pull down already) once my "DutyOut" is <= 0.1? and then back to its normal operation once above say 0.2-0.3?

Thanks for even reading

NanoPWMac.cpp (1.61 KB)

NanoPWMac.h (2.55 KB)

Tesla_Modulation_Driver_8_6_19.ino (2.37 KB)