I have a previous thread about this, but I dropped the topic for a while. I'm using this current sensor
TLI4970-D050T4 located at the emitter leg of a power IGBT, which is being switched at 5 kHz.
It's a low side switching configuration, i.e, motor at the collector leg. The sensor has the default parameters according to the datasheet. I'm thinking of triggering an external GPIO interrupt every rising edge of the PWM signal, and sample the current at this point. Do you think it's a good idea?
Probably not a good idea. Fastest response time is 57 usec, period of the 5 kHz PWM is 200 usec, though at the best sensor could capture 30% PWM and up. What is more problematic, current is not a linear function, and slow sigma-delta adc is no-go with exponentially rising current. So, I'd say - no.
The thing is that I'm trying to sample the current only when the transistor is ON. Do you suggest a better way?
Better is SAR adc. Sensor is shunt or hall, someting like acs712. What is uCPU, does it have an adc?
Better is SAR adc. Sensor is shunt or hall, someting like acs712. What is uCPU, does it have an adc?
I can't change the sensor for now.
I'm thinking of triggering an external GPIO interrupt every rising edge of the PWM signal, and sample the current at this point. Do you think it's a good idea?
Triggering is correct approach with SAR adc, to ensure time stamping of the measurements relatively to PWM pulse. Here is different things, sensor has internal adc (slow sigma-delta) and filter, so it does sampling all the time, there is no trigger. Request over SPI is getting already processed data, and measurements is gonna to be erroneous with PWM.
There really should be an internal triggering path in your STM32 ADC & timer peripherals, but if not, using external GPIO interrupt of course works as well, as you describe.
There really should be an internal triggering path in your STM32 ADC & timer peripherals, but if not, using external GPIO interrupt of course works as well, as you describe.
To read the sensor, I should pull CS low, read SPI data, and pull CS up. So, I'm receiving a digital signal, not an analog signal. That's why I'm not using any ADC in the uC. I came up with also connecting the PWM to a GPIO and trigger an interrupt to read SPI when rising edge of the PWM signal to avoid reading when the transistor is OFF. I was not sure of this approach. I'm simply going to test it.