Pic32 and Micromag3 = false?

USB PICs and the UBW

Moderator: phalanx

Pic32 and Micromag3 = false?

Postby jondaeh » Sun Jan 17, 2010 10:47 am

Hi!

I'm (still) trying to get a PIC32(a UBW32 programmed in MPlab and Pickit2) and the Micromag3 to talk, but I think I have wasted my sunday on a dead end. The Micromag excpects 5v inputs, and the UBW only give 3,3V on it's IO.

Have anyone tried(and succeeded) with this before, or do I need a Darlington driver?

Jon
Norway
jondaeh
 
Posts: 31
Joined: Thu Feb 19, 2009 12:56 am
Location: Ålesund, Norway

Postby EmbeddedMan » Sun Jan 17, 2010 11:35 am

Jon,

One (non-ideal) solution is to switch the UBW32's I/O pins to open drain, and then put 10K pull-ups to 5V on them. You won't get super fast transitions high, but it's better than nothing. Check the PIC32 data sheet carefully - while most I/O pins are 5V tolerant, some aren't.

The "right" way to do it is to use a level translator chip.

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Postby jondaeh » Sun Jan 17, 2010 12:44 pm

Thanks Brian.

I am not so good at electronics, and have never used a pull-up resistor before. A quck search on google gave me the idea that it is a resistor that goes between the output pin I'm using(in ex. C14) and the desired output voltage(which will be the 5v pin).

Don't wanna fry anything here;)

Jon.
jondaeh
 
Posts: 31
Joined: Thu Feb 19, 2009 12:56 am
Location: Ålesund, Norway

Postby EmbeddedMan » Sun Jan 17, 2010 3:28 pm

Yup, you've got it right! A 10K ohm resistor connected from the output pin to +5V is what you want. Then you set the I/O pin to be an open drain output, which means that when you clear the pin low, it will drive the line low, but when you set the pin high, it will not drive it high but let the pull-up pull the I/O pin state to 5V.

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Postby jondaeh » Mon Jan 18, 2010 2:36 pm

Okey, tried out open drain configuration today. I got 5V output, but I encountered some problems I would like to get clarified.

Two of the four outputs I used, D9 and C14 would not go low. I tried both setting them to 1 and 0, but they still was high(5V). The two others acted just as excpected.

I understood from the Reference book and the datasheet for the PIC32 that it's only the outputs capable of being analog that can't be Open drain. This will be the B-register. I used the ports C14, D0, D9 and D10, non of this should be a problem, right?

I switched to some other pins(D8 and D11), and these worked fine. But as the magnetometer still won't respond I guess it has something to do with using the wrong pins or not using them right in the software.

As you can see in the code I attached I'm setting the respective ODC bits to 1, and then controlling the outputs with respective PORT-registers.

Maybe the magnetometer is dead, but wanna make completely sure before ordering another one. Any comments to my choosen pins and/or code is welcome:)

Jon.



Here are the function that sets up the I/O ports:
Code: Select all
//Setting up the nescessary ports and the serial port.
void init()
{
   //Setting the TRIS-registers
        TRISCbits.TRISC4 = 1;
   TRISDbits.TRISD8 = 0;
   TRISCbits.TRISC13 = 1;
   TRISDbits.TRISD0 = 0;
   TRISDbits.TRISD11 = 0;
   TRISDbits.TRISD10 = 0;
   
   //Making the outputs Open Drain
        ODCDbits.ODCD8 = 1;
   ODCDbits.ODCD0 = 1;
   ODCDbits.ODCD11 = 1;
   ODCDbits.ODCD10 = 1;

        //Setting the initial state of the I/O. D11 is the SSNOT pin, it's         
   //low  during magnetic reading.
        PORTDbits.RD0 = 0;
   PORTDbits.RD8 = 0;
   PORTDbits.RD11 = 1;
   PORTDbits.RD10 = 0;

        //Setting up the UART1 for 4800 baud.
   U1MODE = 0x8008;
   U1STA = 0x400;
   U1BRG = 2082;
   
         //Settign up the timer1.
   T1CON = 0x8030;
}


Note: this is from after I changed to the "new" I/O ports.
jondaeh
 
Posts: 31
Joined: Thu Feb 19, 2009 12:56 am
Location: Ålesund, Norway

Postby EmbeddedMan » Mon Jan 18, 2010 7:21 pm

Hmm. The one thing is that there are actually a lot of pins that have analog buffer front ends, and they are not 5V tolerant.

Here's the list of pins that you should not put 5V on:
B5,B4,B3,B2,B1,B0,B6,B7,A9,A10,B8,B9,B10,B11,B12,B13,B14,B15,C12,C15,C13 and C14

But that doesn't answer the question why C14 and D9 couldn't be set low. I'll give it a try on my UBW32 in a little bit and see if I can reproduce your results.

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Postby EmbeddedMan » Mon Jan 18, 2010 9:18 pm

Jon,

I wanted to make sure there wasn't something wrong with the R9 pin, so I ran the following code:


// Setting the TRIS-registers - outputs
TRISDbits.TRISD9 = 0;

// Making the outputs Open Drain
ODCDbits.ODCD9 = 1;

//Setting the initial state of the I/O. D11 is the SSNOT pin, it's
//low during magnetic reading.
PORTDbits.RD9 = 0;

PORTDbits.RD9 = 1;

PORTDbits.RD9 = 0;

PORTDbits.RD9 = 0;

As I stepped through the last four statements, I could see RD9 go high and low at the proper times on my scope. (This is with RD9 connected to +5 through a 10K pull-up.)

I'm not sure why it didn't work for you, but I'd disconnect your Micromag3 entirely from the circuit, and make sure each PIC32 I/O pin can be set high and low appropriately before you move on.

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Postby jondaeh » Thu Jan 28, 2010 3:14 pm

It have taken some time, but I have finally got some better connections between the UBW and the magnetometer, and changed the I/O's to only the D-registers. At least the outputs seems fine now.

I just got one little question left..should I tie the inputs to ground with a resistor to avoid floating? Is this necessary when using them towards a digital input like this?

Jon.
jondaeh
 
Posts: 31
Joined: Thu Feb 19, 2009 12:56 am
Location: Ålesund, Norway

Postby EmbeddedMan » Thu Jan 28, 2010 3:44 pm

If you are building a product for resale, or if you want to minimize current consumption (for battery life, etc.) then you should tie your inputs high or low so they don't float. The circuit will work with them left floating, but it's not a 'best practice'.

*Brian
User avatar
EmbeddedMan
 
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Postby jondaeh » Tue Feb 02, 2010 1:05 pm

I have finally got the magnetometer working. After reading the datasheet the tenth time I realized that it didn't need 5V, 3V is enough. Just using the I/Os for bitbanging, and it works fine.

Here is a link to the final code, if someone has dumped in on this post in desperate searching:

http://forum.sparkfun.com/viewtopic.php?t=19886

Thanks for the help Brian!

Jon.
jondaeh
 
Posts: 31
Joined: Thu Feb 19, 2009 12:56 am
Location: Ålesund, Norway


Return to USB Development

Who is online

Users browsing this forum: Bing [Bot] and 1 guest