Sign in to follow this  
Followers 0

GPUtils PIC bug?


34 posts in this topic

Posted

Right actually it's not working... And I've no idea why! It's getting back straight 1s.

Here's the code I kinda 'converted' it from;


  RTC_t rtc;

  I2C_start();    // START

  I2C_out_byte(0xD0);   // DS1307 hardware address + write command

  I2C_sack();	 // slave ACK

  I2C_out_byte(0x00);   // we will read from this address

  I2C_sack();	 // slave ACK

  I2C_start();	 // repeated START

  I2C_out_byte(0xD1);   // DS1307 hardware address + read command

  I2C_sack();	 // slave ACK

  rtc.sec = I2C_in_byte();   // read sec

  I2C_ack();	 // master ACK

  rtc.min = I2C_in_byte();   // read min

  I2C_ack();	 // master ACK

  rtc.hour = I2C_in_byte();  // read hour

  I2C_ack();	 // master ACK

  rtc.dweek = I2C_in_byte();  // read dweek

  I2C_ack();	 // master ACK

  rtc.day = I2C_in_byte();  // read day

  I2C_ack();	 // master ACK

  rtc.month = I2C_in_byte();  // read month

  I2C_ack();	 // master ACK

  rtc.year = I2C_in_byte();  // read year

  I2C_nack();	 // master NACK

And here's my code;

#define I2C_V2 true

#include <plib/i2c.h>

    int Data[6];

    OSCCON = 0b10100011;

    TRISC = 0x00; // turn on tri-state register and

				 // make all output pins

    PORTC = 0x00; // make all output pins LOW

    TRISA = 0x00;

    PORTA = 0xFF;

    OpenI2C( MASTER, SLEW_OFF);

    __delay_ms(90);

    __delay_ms(90);

    __delay_ms(90);

    PORTA = 0x00;

    SSPADD = 0x3F;

    StartI2C();

    IdleI2C();

    WriteI2C( 0xD0 );  // sends address to the

    IdleI2C();

    WriteI2C( 0x00 );

    IdleI2C();

    StopI2C();


    StartI2C();

    IdleI2C();

    WriteI2C( 0xD1 );  // sends address to the

    IdleI2C();

    WriteI2C( 0x00 );  // sends address to the

    IdleI2C();

//    RestartI2C();

    Data[0] = ReadI2C();

    IdleI2C();

    AckI2C();

    IdleI2C();

    Data[1] = ReadI2C();

    IdleI2C();

    AckI2C();

    IdleI2C();

    Data[2] = ReadI2C();

    IdleI2C();

    AckI2C();

    IdleI2C();

    Data[3] = ReadI2C();

    IdleI2C();

    AckI2C();

    IdleI2C();

    Data[4] = ReadI2C();

    IdleI2C();

    AckI2C();

    IdleI2C();

    Data[5] = ReadI2C();

    IdleI2C();

    AckI2C();

    IdleI2C();

    Data[6] = ReadI2C();

    IdleI2C();

    NotAckI2C();

    IdleI2C();

    StopI2C();

    PORTA = Data[0];

    __delay_ms(90);

    __delay_ms(90);

    __delay_ms(90);

    __delay_ms(90);

    PORTA = 0;

    __delay_ms(90);

    __delay_ms(90);

    __delay_ms(90);

    __delay_ms(90);

    PORTA = Data[1];

    Sleep();

Any ideas?

Share this post


Link to post
Share on other sites

Posted (edited)

Oh I don't believe it! I'm sure I read this RTC was 3.3v only so was using a 3.3v regulator and my 18LF4520... Now I read it needs 4.5-5.5v to function!

DAMNIT!

I'll program the normal 18f4520 sometime and try it.

EDIT: It's getting results now, not sure if they're correct but the seconds are changing... Feel like a right bloody tool for not working this out earlier :|

Edited by n_K

Share this post


Link to post
Share on other sites

Posted

Right, I'm reusing this thread! Got a pretty strange problem with the same microchip (18f4520) that I really can't quite get my head around...

Switched to using xc8 (free) and mplabx, and was experimenting with RS232 communication on the PIC, now for some reason for the example BAUDCON values provided in the datasheet, I've always had to use 1 less than the given value, so 11 instead of 12 for 19.2Kbps as if I use 12 it doesn't work, and this is connected up to a modified PC PSU with an LM7805 regulator on the 12V rail...

Now this has been working kinda well until I decided to switch over to the 5V rail as the regulator hasn't got a heatsink and I want to do some longer testing, switched it over and guess what? RS232 communication now fails, I get really weird values on the PC... So I recompiled my source but this time using the PROPER BAUDCON value specified in the datasheet, 12... Now RS232 communication works fine once again, but if I switch back to using the LM7805 it fails unless I switch BAUDCON BACK to 11.

I'm pretty perplexed by why the hell this is just playing up and being a nuisance, nothing is listed in the erratas about it. Measured the output voltage from the LM7805 and it's 4.99V, output from the 5V rail is 5.10V, and the PIC is using the internal oscillator set to run at 4MHz... So I can't really see or understand why a 0.11V difference means I need to use a different BAUDCON.

Has anyone got the foggiest idea why this is? What I do to fix this?

Share this post


Link to post
Share on other sites

Posted

You should always consider the value from the datasheet canonical. It is very rare that the manufacturer got the value wrong, especially for a large company like Microchip that tends to produce high quality documentation. I would suspect Microchip's compiler before the documentation, although the XC8 is GCC-based and immensely better than the previous two PIC16/PIC18 compilers they produced. The second setup with the 5V power supply sounds correct, and indeed appears to be based on your results. The first setup is suspect.

 

Assuming everything else stayed the same, it sounds like it might have something to do with your voltage regulator. According to their respective datasheets your regulator can produce up to 1.5A and your microcontroller can consume up to 300mA, so that shouldn't be a problem. What other devices do you have connected to your power rail? Are you trying to draw more than current than you regulator can provide?

Share this post


Link to post
Share on other sites

Posted

All that's connected up is the PIC, an elechouse RFID reader/writer (pulls up to 50mA) and a generic 16x2 LCD with backlight. When connected directly to the 5V rail it's pulling ~83mA in total which is more than enough for the setup. The 5V regulator is pulling 78mA from the 12V rail.

I'm using the standard reference implementation with the regulator with a 47uF 16V capacitor on the output of the regulator so to stabilise it. Still can't think why it'd be messed up.

Share this post


Link to post
Share on other sites

Posted

In that case I'm really not sure what the problem is. It sounds like you have your hardware setup correctly, but don't rule anything out too quickly. I have spend hours debugging my software just to discover that I had a bug in my hardware that "couldn't possibly happen", so I ruled it out hours before. (I have also had the same problem vice-versa. It's just part of microcontroller development, I think.) It doesn't sound like a power issue. The 11mV difference on your rail shouldn't be a problem; current draw is really what you should be looking at anyway.

Share this post


Link to post
Share on other sites

Posted

Haha I cannot actually believe this, fixed it. Replaced the 7805 with a LM2940CT-5 and behold it's working fine with the correct baud rate.

I started thinking there was something fishy with the regulator, put the LCD backlight and RFID reader power on transistors and it worked fine from the 5V rail but the 7805 regulator just made the screen backlight continually flash on and off in short bursts and wasn't powering the RFID reader or PIC.

Not sure what's up with the regulator, it's an official texas instruments one, well, the packaging states it is anyway. Picture is rubbish but here's a pic of the regulators, the TI 7805, 2*NI LM2940's and a Motorola 7905;

Ggj8gsS.jpg

Definately an interesting problem I've never seen or had before.

Share this post


Link to post
Share on other sites

Posted

Haha I cannot actually believe this, fixed it. Replaced the 7805 with a LM2940CT-5 and behold it's working fine with the correct baud rate.

I started thinking there was something fishy with the regulator, put the LCD backlight and RFID reader power on transistors and it worked fine from the 5V rail but the 7805 regulator just made the screen backlight continually flash on and off in short bursts and wasn't powering the RFID reader or PIC.

Not sure what's up with the regulator, it's an official texas instruments one, well, the packaging states it is anyway. Picture is rubbish but here's a pic of the regulators, the TI 7805, 2*NI LM2940's and a Motorola 7905;

 

I'm glad you solved your problem. Faulty hardware will do it every time. Now I recommend that you check your circuit to make sure you don't have a short. I have blown a voltage regulator or two that way. It never hurts to be too cautious.

 

Also if I ever need to make my eyes water and am lacking onions to slice, I will come back to this thread and look at that picture.

Share this post


Link to post
Share on other sites

Posted

I'm glad you solved your problem. Faulty hardware will do it every time. Now I recommend that you check your circuit to make sure you don't have a short. I have blown a voltage regulator or two that way. It never hurts to be too cautious.

 

Also if I ever need to make my eyes water and am lacking onions to slice, I will come back to this thread and look at that picture.

Haha the pics not THAT bad... well maybe it is...

I double checked and there is no short, it's using a PC power supply as the power source anyway and that automatically turns off supply power if there is a short (done it a few time accidentally on the 3.3V and 5V lines ;x).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.