USB current consumption

USB current consumption

Postby Manoj » Mon May 06, 2019 12:39 pm

Hello. Need your advice again.
I am using pic24fj256gb110 .I am also using a pendrive to store data.
Every thing is working fine. except when I attach the usb, the measured readings from analog pins start to fluctuate.
So I thought addition to the usb is consuming more current than the voltage regulator can provide(i.e. 150 mA).
The entire circuit is consuming 137 mA without usb. And with usb it consumes 170 mA.
So I introduced a 2nd 5v regulator. Two voltage regulators have same battery and same ground.
Then powered the usb socket and Vbus from its output.
I checked ,there are no noise in the supply voltage or system reference voltage.
But the problem still remains.
What should I do?
Manoj
 
Posts: 37
Joined: Mon Apr 09, 2018 8:01 am

Re: USB current consumption

Postby ric » Mon May 06, 2019 9:12 pm

You don't mention what reference voltage you are using, or how your ADC is configured (particularly if you are using enough "acquisition time").
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: USB current consumption

Postby Manoj » Fri Jul 12, 2019 10:31 am

I noticed one thing . in presence of MonitorMedia() function & the Pen drive together causes the ADC values to fluctuate 2-3 millivolts.
Simply with out MonitorMedia() ,in presence of pendrive ADC increases 1 millivolt but it stays constant, does not fluctuate.
Any idea how to rectify it?
Thank you.
Manoj
 
Posts: 37
Joined: Mon Apr 09, 2018 8:01 am

Re: USB current consumption

Postby ric » Fri Jul 12, 2019 10:41 am

You still didn't mention what reference voltage you are using, or what acquisition time.
Show your schematic and your code and you'll get much better answers.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: USB current consumption

Postby Manoj » Fri Jul 12, 2019 12:27 pm

There is no problem with the circuit diagram .Because its working with another device.
Mcu is running on 3.2 volt. Ref voltage for McU is 1.024 volt. USb is running at almost 5 volt.
Code:-//*****************************//
void __attribute__((__interrupt__, auto_psv)) _ADC1Interrupt( void )
{
if (IFS0bits.AD1IF)
{
IFS0bits.AD1IF = 0;

if (VectorFlag)
// {if (StepCount&0x01)

{
if (Ch1)
{
ADC=GETREADINGCH1-BiasValue1; //-0x8000;
}
else
{
ADC=GETREADINGCH2-BiasValue2;
}


CumRef+=(SinTable[StepCount])*(float)ADC;
CumQuad+=(CosTable[StepCount])*(float)ADC;
}
// // To work an alternate samples
if (Zeroing)
{
ReadingCount++;
//ADC=GETREADINGCH1;
CumZero1+=GETREADINGCH1;
CumZero2+=GETREADINGCH2;
if (ReadingCount==MeasureSteps) //32cycles X 128 per cycle.
{
Zeroing=FALSE;
ReadingCount=0;
}
}

if (FilterFlag) // frequency scanning
{
FReadings++;
ADC=GETREADINGCH1-BiasValue1; //FCh1bias;
ScanRef+=((float)ADC*(float)ADC);
ADC=GETREADINGCH2-BiasValue2; //FCh2bias;
ScanQuad+=((float)ADC*(float)ADC);
if (FReadings==AVGNO)
{
// PWMpreiod=16000000/(c*64);
OC1RS = (int)(PWMpreiod-1); // PWM period
OC1R = (int)((PWMpreiod/2)-1 ); //50% initial duty cycle
FilterFlag=FALSE;
}

}
if (MeasureFlag)
{
MsrReadings++;
ADC=GETREADINGCH1-BiasValue1; //-0x8000;
// Read2[MsrReadings]=(float)ADC;
CumRef+=((float)ADC*(float)ADC);
ADC=GETREADINGCH2-BiasValue2;
CumQuad+=((float)ADC*(float)ADC);
if (MsrReadings==AVGCYCLES)
{
MeasureFlag=FALSE;
}

}


}
}
//***********************************************************************************************************************************************************//
I am using timer3.
//*************************************************************************************************************************************************************//
void Measure(void)
{
#define AVGCYCLES 1024
ShowMainMast(); // clock
if(settings.ModeSetting==VEL)
{
DispL2(0);
Put_String_LCD ("Overall Velocity ");
DispL3(11);
Put_String_LCD(" mm/s RMS");
DispL4(11);
Put_String_LCD(" mm/s RMS");
}
else
{
DispL2(0);
Put_String_LCD ("Overall Displacement");
DispL3(11);
Put_String_LCD(" micron ");
DispL4(11);
Put_String_LCD(" micron ");
}
DispL3(0);
Put_String_LCD("Ch1:");
DispL4(0);
Put_String_LCD("Ch2:");
IEC0bits.INT0IE=FALSE; //Disable INT0
FILTEROUT=1; //Bypass filter.
SHORTDELAY();
VectorFlag=FALSE;
Zeroing=FALSE;
CumRef=0;
CumQuad=0;
MsrReadings=0;
KEY_PRESSED=0;
UpdateRange();
UpdateFrequency();
PR3=6400; //coresponds to a sampling frequency of 2.5Khz// Those calculations correspond to an Fosc = 32MHz, so Fcy = //16MHzIf PR3 = 6400, then the timer will roll over at Fcy/6400 = 16MHz / 6400 = 2500
MeasureFlag=TRUE;
while (MeasureFlag) //start measuring cycle of 2500 readings..
{
}
Amount1=sqrt(CumRef/AVGCYCLES)*32/ScaleDivider;
if (settings.currentRange==R2)
{
if (Amount1 >25.6)
{
sprintf (LCDBuf,"^^^^ ");
}
else
{
sprintf (LCDBuf,"%06.1f",Dispmultiplier*(Amount1-.1));
}
}

else if (settings.currentRange==R3)
{
............
...
..........
............
....
.....
}
if (KEY_PRESSED==S1)
{
mainstate=MAIN_MENU;
current_option=2;
previous_option=0;
KEY_PRESSED=0;
IEC0bits.INT0IE=TRUE;
}

}
//***********************************************************************************************************************************************************************************//
This fuction is called from the while(1) loop.
I placed the MonitorMedia() function at the starting of While loop.

//***********************************************************************************************************************************************************************************//
void MonitorMedia( void )
{
BYTE mediaPresentNow;
BYTE mountTries;
SearchRec searchRecord;

USBTasks();

if (loggerStatus.overcurrentStateUSB)
{
// An overcurrent situation exists, and the USB has been shut down.
if (loggerStatus.mediaPresent)
{
PrintString( "\r\n***** USB Error - overcurrent detected *****\r\n" );
loggerStatus.mediaPresent = FALSE;
}
}
else
{
mediaPresentNow = USBHostMSDSCSIMediaDetect();
if (!mediaPresentNow)
{
loggerStatus.cannotInitialize = FALSE;
}
if ((mediaPresentNow != loggerStatus.mediaPresent) && !loggerStatus.cannotInitialize)
{
if (mediaPresentNow)
{
mountTries = 10;
while(!FSInit() && --mountTries);
if (!mountTries)
{
UART2PrintString( "\r\nAPP: Could not initialize media. Media format must be \r\n" );
UART2PrintString( " FAT or FAT32, and sector size must be 0x" );
UART2PutHexWord( MEDIA_SECTOR_SIZE );
UART2PrintString( ".\r\n" );
RedoCommandPrompt();
loggerStatus.mediaPresent = FALSE;
loggerStatus.cannotInitialize = TRUE;
}
else
{
int i;
USB_DEVICE_DESCRIPTOR *pDescriptor;

pDescriptor = (USB_DEVICE_DESCRIPTOR *)USBHostGetDeviceDescriptor( 1 );
i = 0;
while ((i<PROBLEM_THUMB_DRIVE_COUNT) &&
(pDescriptor->idVendor != problemThumbDrives[i].vid) && (pDescriptor->idProduct != problemThumbDrives[i].pid))
{
i++;
}

if (i < PROBLEM_THUMB_DRIVE_COUNT)
{
UART2PrintString( "\r\nThis thumb drive is not supported. Please replace with a different model.\r\n" );
loggerStatus.mediaPresent = FALSE;
loggerStatus.cannotInitialize = TRUE;
}
else
{
loggerStatus.mediaPresent = TRUE;

// Find the volume label. We need to do this here while we are at the
// root directory.
if (!FindFirst( "*.*", ATTR_VOLUME, &searchRecord ))
{
strcpy( volume.label, searchRecord.filename );
volume.valid = TRUE;
}
}

RedoCommandPrompt();
}
}
else
{
loggerStatus.mediaPresent = FALSE;
volume.valid = FALSE;

RedoCommandPrompt();
}
}
}
}
//*****************************************************************************************************************************************************************************//
As Pr3=6400 sampling freq is 2.5kHz.
Timer settings:-
//**************************************************************************************************************************************************************************//

void InitializeTimers(void)
{ T4CON=0x00; // Stop any 16/32-bit Timer4 operation
T5CON=0x00;
TMR5=0x00; // Clear contents of the TMR4 and TMR5
TMR4=0x00;
PR5=0x0049; // 0000 0000 0100 1001---->73
PR4=0x3E00;
IPC7bits.T5IP2=TRUE;
T4CONbits.T32=TRUE; //enable 32 bit mode
IFS1bits.T5IF = 0; // Clear Timer 5 Interrupt Flag
IEC1bits.T5IE=TRUE; // Enable Timer5 interrupt
T4CONbits.TON=TRUE; // Start Timer
T3CON=0b1000000000000000;

IPC2bits.T3IP = TIMER_INTERRUPT_PRIORITY;
IFS0bits.T3IF = 0;
TMR3 = 0;
IEC0bits.T3IE = 1;



//Setup TMR2 for Keyboard scan and tick count:
T2CON=0x00;
TMR2=0x00;
PR2=20000; //for 10msec
IFS0bits.T2IF=0;
IEC0bits.T2IE=1;
}

void IntialiseInterrupts(void)
{
//Setup INT0 Interrupt: Bydefault it is +edge triggered.
IPC0bits.INT0IP=5; //Priority 5
IFS0bits.INT0IF =0;
IEC0bits.INT0IE=TRUE; //Enable it
}
//**********************************************************************************************************************************************************************//
I can not provide the entire code What else do you need?
Last edited by Manoj on Mon Jul 15, 2019 11:14 am, edited 2 times in total.
Manoj
 
Posts: 37
Joined: Mon Apr 09, 2018 8:01 am

Re: USB current consumption

Postby ric » Fri Jul 12, 2019 12:34 pm

Those diagrams have been shrunk to just past the point where you can actually read anything.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to USB

Who is online

Users browsing this forum: No registered users and 1 guest

cron