@Mauro:
What kind of motor do you intend to control?
A (little or big) stepper motor, a 3 phase motor, a (little or big) brush DC motor, a brushless motor?
Each type of motor can be drived using different metods and drivers.
As example, you can drive a 3 phase motor (using grid power) through a variable frequency driver (VFD), and control the speed modifying its output frequency.
This is achievable by converting the PWM output signal generated by the microcontroller in an analog output 0-10V or 0(4)-20mA, using an interface (dedicated hardware), and connecting this analog output to the analog input of VFD, sharing all grounds as reference.
The analog output will vary its value according the duty cycle variable in LDmicro's PWM instruction.
You can also control the start/stop of motor, movement direction, and perhaps a third function offered by a particular VFD (i.e. fast braking), using digital outputs of the microcontroller connected to digital inputs of VFD, through an appropiated interface.
I've developed the OVF module for my OSIMPLC (Open Hardware + Free Software PLC for Technical Schools and Professional Training Centers) to control different FVDs, using theirs three digital input and their analog input...
All the digital outputs of the microcontroller are isolated by optocouplers, the analog output can be configured as 0-10V or 0(4)-20mA using jumpers in OVF module.
You can freely download the schematics for the microcontroller unit and the OVF module from
https://osimplc.com/docs/es/downloads/Schematics/mcu.pdf and
https://osimplc.com/docs/es/downloads/Schematics/ovf.pdf
, and adapt this schematics for your own project; all of them are under Creative Commons BY - Share Alike license (CC BY-SA).
I've tested the analog output of OVF module using different base frequencies for PWM, reaching 1.25 MHz using a PIC16F887 with 20 MHz crystal oscillator...
Of course, if you intend to use an ATmega micrcontroller, the base frequency is established by the formula Fosc = F(I/O) / (N * 256), being N = 1, 8, 64, 256 or 1024 factor, and
F(I/O) the microcontroller operating frequency (cystal, RC circuit, internal oscillator).
Of course, yo can measure the distance already traveled using different metods, as example installing various magnets in the circumference of the pulley and read them through an Hall effect transistor, or a reed switch; or by marking notchs or installing protuding objects in the pulley, and read them using an inductive (if metal) or capacitive (not metal) sensor.
NOTE: You can NOT read the quantity of pulses generated by PWM output in a digita input, using LDmicro.
Another alternative, if you intend to control the pulley using a strong stepper motor and a driver, is to implement the PULSER instruction in LDmicro. Of course, you also must measure the distance already traveled, because stepper motors can suffer of "slippering" due high acceleration rates driving heavy loads...
Good luck!
Best regards,
DanielH