I am trying to give desired voltage input to motors so that I can implement a PID controller that can give voltage input based on the angular velocity from the encoder reading. I am currently using Arduino uno, L298N motor drive, and 6V DC geared motor (TT Motor with Encoder (6V 160RPM 120:1)-DFRobot) for my project. I have found that there is a PWM duty cycle we can use to find the linear relationship between voltages and PWM, and when I applied 100 pulses, 150 pulses, and 200 pulses, it looked as though the linear relationship is not consistent in the experiment that I conducted as I measured the voltage going to the motor on the motor drive using a DMM. If possible, I will greatly appreciate if it is possible to know how to control the voltage in a desired manner, or if there is an easier way to control the motor speed with PWM inputs.
For a voltage linear response you need to avoid decay modes and use synchronous rectification mode in the H-bridge,
otherwise the average voltage is at the vaguaries of the load current decaying to zero under the influence
of the mechanical load and inductance of the motor.
The L298N isn't really designed for synch-rect mode as it doesn't have a direction pin - for synch-rect
you assert enable and PWM the direction, with 50% duty cycle being the zero speed setting.
Synch-rect mode automatically gives 4-quadrant control too.
However for many applications you may not need such linearity at all - its useful for a servomotor
which needs a stable fast response to command inputs. For simple speed control it may not be needed.