Hi,
I'm trying to drive a p-mosfet Intelligent Power and Sensing Technologies | onsemi from pin #4 like so: Circuit Simulator Applet. The load is a step-up to 5v that feeds a 433MHz Tx.
I'm using an atmega328 on a breadboard at 8Mh, powered either from the arduino usb2serial adapter or a 1S lipo (4v2 - 3v7).
Well, when the pin gets low, if the bb is hooked to the usb2serial I get a couple of usb beeps and the IDE looses the virtual com port. Actually a little ago the usb2serial died!
If I replace the 220Ohm resistor with a 2.2KOhm resistor and the mosfet with a pnp transistor BC327, it works fine.
This is driving me crazy. Any help greatly appreciated.
The part of the code that drives pin 4:
...
#define TxPowerPIN 4
#define TX433PIN 12
...
void xmit(char *ck, char *hstring, char *tstring)
{
char *msgmask="%s,%02X,%s,%s,%s,%s";
digitalWrite(TxPowerPIN,LOW); // Turn on the p-mosfet
pinMode(TxPowerPIN, OUTPUT);
delay(50);
ADMUX = (0<<REFS1) | (0<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
int value;
for (int d=4; d>0; d--) {
// Start a conversion
ADCSRA |= _BV( ADSC );
// Wait for it to complete
while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
}// Repeat conversion
// Scale the value
// rawAnalogReadWithSleep();
value = (((InternalReferenceVoltage * 1024L) / rawAnalogReadWithSleep()) + 5L) / 10L;
//value = (((InternalReferenceVoltage * 1024L) / ADC) + 5L) / 10L;
// float vin=((analogRead(VoltagePIN)/1024.0)*aref)*(r1+r2)/r2;
float vin=(float)value/100.0;
char msg[64];
char vstring[10];
dtostrf((float)vin,4,2,vstring);
// dtostrf((int)value,3,0,vstring);
sprintf(msg, msgmask, loc, cnt, vstring, ck, hstring, tstring);
#if DBUG > 0
Serial.println(value);
Serial.println(msg);
#endif
// Send Data
vw_send((uint8_t *)msg, strlen(msg));
// vw_wait_tx();
// delay(400);
delay(200);
cnt++;
// digitalWrite(TxPowerPIN,HIGH);
pinMode(TxPowerPIN, INPUT); //Return to hi-z, mosfet-off
}
...