• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

GPUtils PIC bug?

Question

n_K    2,056

So I've been using GPUtils for a few weeks now, used to use MPASM back in the day on windows but I have to say I really like GPUtils.

So I've been playing around with this PIC 18F4520 IC I have and have been writing a pretty large program (in terms of pages). I've been frustrated for a whole day now on why a function won't work and has undesirable behaviour - returns 0 or crashes or resets the PIC... Then I realised something - the code was too long for one page and I've been coding in the next page without knowing it.

So (this is all reloctable code - NOT absolute) I read up on using BANKSEL and PAGESEL in GPUtils... Unfortunately, it appears to do buggar all, I'm not sure if I'm using it wrong or if features is bugged and just isn't working. This is the code I'm using (from the lst to see the addresses):

000288   0b0f	 andlw   0xf			  ANDLW b'00001111'
										   PAGESEL 400h
										   PAGESEL FUNC
00028a   ec00	 call    0x400, 0		 CALL FUNC
00028c   f002
										   PAGESEL $
00028e   0100	 movlb   0			    BANKSEL d2
.....
										   org 0x400

000400   010f	 movlb   0xf			  FUNC BANKSEL PCL
										   PAGESEL $
000402   6e02	 movwf   0x2, 0		   movwf d1
000404   0e04	 movlw   0x4			  movlw b'00000100'

And as can be seen - PAGESEL is doing nothing if I provide it with the function name or an address, I have to alter the PCLATH register manually as if I'm using absolute assembly which is a bit dumb and will always vary depending on what's added or what it's linked with or if anything is changed so I'm unsure if I'm doing something wrong or if I need to report a bug.

(Compiling using: gpasm -c 18f4520LCD.asm, linking using: gplink -m -c -s /usr/share/gputils/lkr/18f4520.lkr -o 18f4520LCD 18f4520LCD.o)

Anyone else got GPUtils, a programmer and can see if this is happening when they try this?

Thanks!

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0
n_K    2,056

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
  • 0
n_K    2,056

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
  • 0
Karl L.    275

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
  • 0
n_K    2,056

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
  • 0
Karl L.    275

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
  • 0
n_K    2,056

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
  • 0
Karl L.    275

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
  • 0
n_K    2,056

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  

  • Recently Browsing   0 members

    No registered users viewing this page.