24V PWM to 5V inverted PWM
Your PWM generator is the key for understanding.
Its output needs to go to 0V and to the PWM high level (maybe some 24V?) in an alternating fashion. That's its functionality.
Your microprocessor is a logic device with an input and an output - with both using logic levels of 0V and 5V. Attaching the input is simple if you want it non-inverted, then just a resistive 5 to 1 divider can do the job. If you want it inverted, then a transistor will do the job. Mine prefers the NPN, if possible, as it is ground attached and circuits often share grounds much easier than the supply voltage. For the output a transistor is also nice, but applied the other way around.
What you (and me up to now in this response) have ignored, is the fact that the PWM might drive its output with dual transistor logic, or it might use single transistor logic with either a pull up or a pull down logic in an internal or external form. The most common form is probably the so-called &quot;open collector&quot; concept. This is used on various bus systems where multiple participants are allowed to pull down the voltage on the bus to zero. It works like OR logic: if none pulls it down, then the bus wire is high. If one or more or even all will pull the level down, then its low.
So it's up to you to find out how the output of your PWM is designed, in order to know if you can have a &quot;feedback&quot; or &quot;error terminate&quot; second operator on that wire. The precondition for this &quot;open collector&quot; design is a single external or internal pull-up resistor to high level - and the PWM only having a pull-down transistor - and the processor participant on the bus also only adds a pull-down transistor for its feedback output.
And now to your other question:

How to determine a current? (in your case: of the PWM)

Let the current flow through a measurement resistor and then determine the voltage across it. Ohm's law for resistors has a linear relationship between current and voltage.
For example, if you want to read 100mA of current and it goes via a 100 ohm resistor, then a voltage of 1V will appear across its terminals. As you are doing something with a microprocessor, you might have an analog-to-digital-conversion (ADC) feature built in. For ease of use, measuring current via a resistor and a processor works best if the resistor is in the return path towards ground of your application current. Typically currents might be high and thus resistors are of a low ohm value. So please be aware that in the real world, this also means there will be noticeable power dissipation of maybe more than 1 Watt - matching &quot;shunt&quot; resistors are out there. Other methods are measuring coil transformers (for that the transformer and coils are in shortcut alike operation mode, doing current transformation rather than voltage transformation).
Other options for measurement of small to big signals are differential operation amplifiers. They have many advantages, e.g. up and downscaling at large selectable factors, filtering, ground problem elimination and many more.
Let's hope that's something you could pick up and apply to your particular scenario.
Regarding resistors in your diagram:

R1 is controlling the base current for the transistor nearby. (It also has a coupling effect to make it more stable in amplification - but that's a typical audio amplification case, but we have logic, so I doubt it's the case here. It might move to the base input of the transistor - unless it's meant to be sort of a voltage protection, to decouple the 5V and 24V even a bit more).
R2 is the pull-up resistor for your bus wire (and your PWM should never have such a pull-up component as well, neither a resistor nor a transistor).
R3 is the &quot;load&quot; resistor for the logic - as logic does not need much current, it's a high value.
R4 is limiting the base input current of your feedback transistor and signal - with 5V it is probably less than 0.5 mA due to the base-emitter path having some voltage drop as well.