Hi,
Trying to read with reasonable accuracy (+/- 25mA) a current over a 30mOhm resistor, or 50mOhm. Attempting not to go above 50mOhm for efficiency.
No speed requirement and triggering the ADC at 2Hz from RTC.
Here's the expected reads. You can see that I've lowered the 0.1A value to try and get a read. With the 30mOhm I can't, but I can start to get a read with the 50mOhm at about 200mA
// 0.03 ohm * 0.1A = 0.003v, /0.55*1023 = 6 // 0.03 ohm * 0.5A = 0.015v, /0.55*1023 = 28 // 0.03 ohm * 0.9A = 0.027v, /0.55*1023 = 50 #define USB_CURRENT_CHANGE_HYSTERESIS 1U #define USB_CURRENT_USB2_ADC_VALUE 2U #define USB_CURRENT_USB3_ADC_VALUE 28U #define USB_CURRENT_USBC_CC15_ADC_VALUE 50U
ADC is configured to run a 62KHz. MainClk at 250KHz. 64 samples
// ADC0
ADC0.CALIB = ADC_DUTYCYC_DUTY25_gc;
ADC0.CTRLB = ADC_SAMPNUM_ACC64_gc;
ADC0.CTRLC = ADC_PRESC_DIV4_gc | ADC_REFSEL_INTREF_gc; // 62.5KHz
ADC0.CTRLD = ADC_INITDLY_DLY256_gc | ADC_ASDV_ASVON_gc | 0b111 << ADC_SAMPDLY_gp;
ADC0.DBGCTRL = ADC_DBGRUN_bm;
ADC0.EVCTRL = ADC_STARTEI_bm; // Auto trigger
ADC0.SAMPCTRL = 0x1F; //SAMPLEN 31
//ADC0.INTCTRL = ADC_RESRDY_bm;
ADC_CONFIG(USB_CURRENT_ADC_CHANNEL, USB_CURRENT_ADC_REF);
ADC0.CTRLA = ADC_RUNSTBY_bm | ADC_RESSEL_10BIT_gc | ADC_ENABLE_bm;
As good as it gets without a op-amp across the resistor?




