L298 current sensing + pwm

Hi, i want to aply pwm on a solenoid for controling the flow of a Gas valve. Is it possible to measure the current using the sense pins of the L298 when it is used in PWM Mode? How do i connect it to the Microcontroller?

The voltage across the sense resistor would be PWM and probably need amplifying then low pass filtering to make a usable analog feedback signal.
What is the solenoid current?

Or, use one of these, (or similar), would still need LPF.

Hi.. the maximum current should be about 165mA...

Unless you use synchronous rectification mode (which means PWM'ing two direction pins in antiphase,
rather than the enable), the current reverses across the sense resistor every cycle so no amount of
averaging will be useful/meaningful, you have to sample the voltage across the sense resistor in synchrony with
the PWM (such as via a timer overflow interrupt). That brings up the thorny issue of analogRead()
taking 110us which is 'quite a long time' for an ISR.

Don't forget the 4 diodes with using the L298 - most modules have them, they are never optional.

Are you using the full H-bridge or just part of it as a half-H-bridge? If the latter you can PWM
just the input pin, need only 2 diodes. You would be smart to set the L298 sense resistor to
zero ohms and add a sense resistor directly to ground from the undriven end of the solenoid, where
it always gets the solenoid current whereever it is in the PWM cycle. Averaging probably won't be
needed as the inductance of a solenoid will do that for you...

I need to drive 2 Solenoids, because of that the current sensor at the input wil not work, but at the output. The board is >this<.
If possible i wanted to use the biult in sense pin. But if the Analog read is to slow its a problem.
Keep in mind that i use a Teensy 3.1 not Arduino. I wanted to set the PWM frequency at about 24kHz, what makes it litlebit tricky to measure.. Is there no function wich reads only the voltage peaks? What if i put a cap to the sense pins?

The current sense pin on the L298 is intended for use with the companion L297 chip, which generates PWM signals for coil current control.

This is ancient technology. You would be much better off using a modern self-contained motor driver, such as those sold by Pololu.

o5i_:
I need to drive 2 Solenoids, because of that the current sensor at the input wil not work, but at the output. The board is >this<.
If possible i wanted to use the biult in sense pin. But if the Analog read is to slow its a problem.
Keep in mind that i use a Teensy 3.1 not Arduino. I wanted to set the PWM frequency at about 24kHz, what makes it litlebit tricky to measure.. Is there no function wich reads only the voltage peaks? What if i put a cap to the sense pins?

There's no easy way to do this in hardware, maybe a separate isolated current sensor (hall effect) on
the solenoid circuit would be the best way. You still have slowish analogRead() to worry about, but once
you sense on the load and the load is inductive you get to read the true current. Isolation is pretty
much needed if the load is PWM'd, and you do get some spikes from the switching still which a little
filtering will tame.

More modern motor driver chips often have internal circuitry to sample sense-resistor voltage synchronously
with the PWM automatically, which keeps the external circuitry simple. The L298 is more ancient than
most devices you'll ever see BTW.

I realized that the pololu drivers would be better choice, but for now i think i try whitout current sense and if there are problems i switch to the DRV8801