Jump to content



Photo

GPUtils PIC bug?

gputils pagesel bug

  • Please log in to reply
33 replies to this topic

#1 n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 31 January 2013 - 00:06

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!


#2 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 31 January 2013 - 00:51

I'm much more familiar with the PIC 18F242 than the 18F4520, but I assume their instruction set is similar. It looks like you are completely disregarding the BSR (Bank Select Register) in your code. You are setting it with instructions such as movlb 0xf, then disregarding that value with movwf 0x2, 0. According to the PICmicro Quick Reference Chart:

RAM access bit
a = 0: RAM location in Access RAM (BSR register is ignored)
a = 1: RAM bank is specified by BSR register (default)

Hex
: 6Ff*
Mnemonic: MOVWF f,a
Description: Move WREG to f
Function: WREG → f


Just out of curiosity, why did you choose to program this project in assembly instead of C? SDCC is a good FOSS C compiler for the PIC18 that is undergoing rapid development. (Check out the SDCC SVN repo if you're interested.) If you would rather have a commercial compiler, the HI-TECH C compiler for the PIC18 is also excellent.

#3 OP n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 31 January 2013 - 01:56

Actually, that is the assembler, there is no movlb in the actual code file
PAGESEL 800h
CALL FUNC
PAGESEL $
BANKSEL d2
movwf d2
....
org 0x400
FUNC BANKSEL PCL
PAGESEL $
movwf d1
movlw b'00000100'
So quite what is going on... *shrug* I've not a clue.

Never been a fan of C on PICs, I like to know what they're actually doing... Or attempt, found some I2C 24c16 that reads/programs fine with a JDM programmer but using my own I2C implementations and loads off the 'net using custom methods and using the actual in-built I2C commands - None worked! There's a lot of I2C C examples for PIC chips on the net that consist of something like
I2CStart();
I2CRead('1010000');
I2CWrite();
...Fair enough you can write fast code but what the hell is actually going on? Same as on a PICAXE, well, I find PICAXE worse for it's got a bootloader running, all the time, so anything that's timing critical or to be very optimised will never be optimised.

EDIT: Just seen that SDCC project supports HC08, got an HC11 which appears to be backward compatible that I was slowly going to move on to, might give it a blast on that to see if/how it works :D

Edited by n_K, 31 January 2013 - 02:10.


#4 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 31 January 2013 - 02:14

C is very advantageous because it allows you to program the controller faster. I agree that its certainly possible to program the PIC18 in C and not understand what its doing underneath, but just because you program it in C doesn't necessarily mean that you don't! Knowing the instruction set means you understand that 16-bit and signed variables have higher overhead, float is not supported in hardware so it should be used sparingly (if at all), and there are only three pointer registers. That's why its probably best to learn assembly first, but I wouldn't rely on it for anything super complicated.

On a side note, I have working I2C code that I wrote to communicate between the PIC18 and a serial EEPROM. (In C, of course! I'm just insane, not a masochist.) It uses the PIC18's built-in I2C functions and relies on no third-party code. I will send it to you if you're interested.

Actually, that is the assembler, there is no movlb in the actual code file


Maybe you should consider invoking movlb and movwf directly then. Even if you are not writing those commands at the moment, it is happening according to the code you posted.

Also, doesn't using directives that expand into multiple assembly instructions somewhat defeat the reason why you're using assembly instead of C?

#5 OP n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 31 January 2013 - 02:22

This is the problem though, because it's relocatable code, if I mix another library with it or even if I don't, it's a mis-match of things and so unless I specifically put the address in - I don't know where it'll be nor what bits to set when using one function from another. I only spotted why this was going wrong by accident in gpsim, seeing it be fine at address 400 then come to an increment of PCL and suddenly jump to instruction 6 out of the blue - then saw the PCLATH and PCLATU registers - set them manually and it works fine but I shouldn't have to set them manually - gpasm and gplink should be doing that with the pagesel/banksel instructions as far as I'm aware, so I'm not sure if I'm doing it wrong or if the program is bugged and I'd feel a complete tool to sign up to sourceforge to report this problem if it isn't a bug :(. [There was also no RTL/RRL instruction present, for some reason it's 'rrcf' and 'rlcf' :s again not sure if it's a bug]

I've tried using the internal I2C functions too but this EEPROM (there's no spec sheet either for this exact model, 24c16 (Not 16A! And not atmel!) by and the 18f4520 just don't like each other for some reason. I've got a 16f88 I might try with it sometime but I also found a 93c46n that works brilliantly and prefer having seperate SDO and SDI lines :D

#6 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 31 January 2013 - 02:32

I've tried using the internal I2C functions too but this EEPROM (there's no spec sheet either for this exact model, 24c16 (Not 16A! And not atmel!) by and the 18f4520 just don't like each other for some reason. I've got a 16f88 I might try with it sometime but I also found a 93c46n that works brilliantly and prefer having seperate SDO and SDI lines :D


I have the 24LC515. There are a couple important considerations, but do you have 10K pull-up resistors on your SCL and SDA lines? Also, are you sure you have the address right? On my EEPROM, the A0, A1, and A2 pins determine the user-defined part of the address, which must be included with the static device address. If you don't have the datasheet and don't know the device address, you could always try brute-forcing it by trying every address until one is accepted. (Since its only 8 bits that shouldn't take very long.) You would need to be sure everything else was correct for that to actually work, though.

#7 OP n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 31 January 2013 - 02:51

10k!? No! I've tried 3.8K and 2.2K.
The address is the problem, well, might be... The atmel 16a spec sheet says it has no address pins and it's forced to 000 but I grounded them anyway.
The first time I tried just doing my own 'brute force' attempty at the whole I2C thing and copied atmel's waveforms (not using the in-built I2C lines) and it did kind of work, and by kind-of I mean sporatically (it was not running at 100KHz, it was running using LEDs so I could see it, so very slow). If I powered the device on 20 times, say, 5 times the EEPROM would respond with the data, some of those times it would be delayed by a few clocks, but the other 15 or so times it wouldn't do anything, but the JDM programmer for the PC reads the chip fine each time!
EDIT: Or would it? Might be getting confused between the 93c46n and the 24c16 here actually as to if it even replied properly. Don't think it did actually.

Edited by n_K, 31 January 2013 - 02:52.


#8 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 31 January 2013 - 04:18

The datasheet for my EEPROM says the I2C speed should be between 100 - 400 KHz, so I set mine to 350 KHz. Like I already mentioned, I put a 10K pull-up resistor on the SCL and SDA lines. I used 0xA0 as my address because my static device ID is 1010, my user-configurable ID pins are all grounded (000), and I want to write by default (0). Since the PIC18 is big-endian, my 8-bit address is 10100000 (0xA0) when I want to write and 10100001 (0xA1) when I want to read. Obviously it will be a little different depending on the EEPROM chip you're using, but maybe my configuration will help.

#9 OP n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 31 January 2013 - 12:04

Here's one attempt I tried which literally just hammered the data out at a slow speed (so I could see the LEDs):
;RB0 = CLK
;RB1 = OUT/IN
;START
movlw   b'00000011'
movwf   LATB
call Delay
movlw   b'00000001'
movwf   LATB
call Delay
movlw   b'00000000'
movwf   LATB
call Delay
;/START
;DATA
;101000010
movlw   b'00000011'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000011'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000011'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
movlw   b'00000001'
movwf   LATB
call Delay
;
  movlw   b'00000000'
  movwf   LATB
  call Delay
;
;/DATA
bsf LATD, 0
call Delay
call Delay

;CHECK
movlw   b'00000010' ;RB1 now an input
movwf   TRISB
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
bsf	 LATB, 0
call Delay
bcf	 LATB, 0
call Delay
;
;/CHECK
bcf LATD, 0

;STOP
movlw   b'00000001'
movwf   LATB
call Delay
movlw   b'00000011'
movwf   LATB
call Delay
movlw   b'00000000'
movwf   LATB
call Delay
;/STOP

goto Start

Another one I quickly attempted using the actual PIC I2C functions:
movlw b'00000000'
movwf INTCON
movwf INTCON2
movwf INTCON3
movwf ADCON0
movlw b'00001111'
movwf ADCON1
movwf CMCON
movlw b'00000000'
movwf RCON
movwf PIR1
movwf PIR2
movwf PIE1
movwf PIE2
movwf IPR1
movwf IPR2
movwf CMCON
movwf CVRCON
movlw b'00000000'
movwf SSPADD
movlw b'10000000'
movwf SSPSTAT
movlw b'00001000'

movwf SSPCON1
movlw b'00000000'
movwf SSPCON2
call Delay
BSF SSPCON1, 5
call Delay
BSF PIR1, 3
call Delay
BSF SSPCON2, 0
BSF PIR1, 3
call Delay
;movlw b'11010000'
movlw b'110100000'
movwf SSPBUF
BCF SSPCON2, 6
call Delay
call Delay
movf SSPBUF, w
movwf LATA
BSF SSPCON2, 6
call DelayL
movlw b'110100000'
movwf SSPBUF
BCF SSPCON2, 6
call Delay
call Delay
swapf SSPBUF, w
movwf LATA
sleep

Now I look I've not a clue about the 1101... movlw, it's got 9 bits :s. And the other one I tried was just basically nicked from http://nnp.ucsd.edu/...les/i2c_CFD.asm though I changed it to remove the 2nd lot of addressing as the 24c256 has 16-bit addresses that the 24c16 and below don't.

But yes unfortunately none worked. I might have another go at them in the future.... As I'm currently having problems with pagesel in gputils, do you know if there's an official MPASM for linux anywhere?

#10 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 31 January 2013 - 15:49

I don't think MPASM was ever released for Linux. However, there is GPL source code available for the MPLAB Assembler and MPLAB C compiler for the PIC24, dsPIC, and PIC32. The existing PIC16 and PIC18 toolchains are completely incompatible with the PIC24 and PIC32 toolchains, so it might not do you any good.

In case you are interested, the C30 source code is buried on a page deep in Microchip's website that looks like something straight out of 1990. There is also some discussion of building an older version of the compiler for Debian on the Microchip user forums. The Debianized source is quite old and not in the modern Debian packaging format, but the debian/control and debian/patches/* should get you started if you want to build the current version of C30 for Debian or some other Linux distribution. Good luck!

Edit: I just discovered something. If you install the free (but not FOSS) MPLABX in Linux, it will install MPASM. MPLABX 1.60 installed MPASM 5.48 as /opt/microchip/mplabx/mpasmx/mpasmx on my machine. Potentially unlike Microchip's ASM30, the version of MPASM installed with MPLABX will work with the PIC18.

#11 OP n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 31 January 2013 - 20:28

That, is, insane.
Warning[205]: Found directive in column 1. (PAGESEL)
Message[312]: Page or Bank selection not needed for this device. No code generated.

So... What the hell? Because I've got an 18f4520 I need to manage the PCLATH and PCLATU registers myself? What a heap of ****. I can't believe how pathetic that is! What's the point in having the functions at all then if you can't use them.

#12 OP n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 05 February 2013 - 21:25

So I got a DSPIC30F4013 in the mail today... Thought it'd be fun to play around with it in gputils but there appears to be a slight minor drawback; it's not supported in gputils :(.
So I just had a quick look around and saw the HI TECH C compiler that supports it for $850 and some 'csd 24 bit' that supports it for $350... Both are $850 and $350 too expensive for me for playing around with!
Got any suggestions for C compilers ? :p Or heck, even assembly at this point!

#13 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 06 February 2013 - 16:01

I don't have a dsPIC, but from what I understand they are approximately equivalent to the PIC24. I use Microchip's MPBLAB XC compiler with my PIC24FJ128GA010. I think that will work with your DSPIC30F4013 as well.

#14 OP n_K

n_K

    Neowinian Senior

  • Tech Issues Solved: 3
  • Joined: 19-March 06
  • Location: here.
  • OS: FreeDOS
  • Phone: Nokia 3315

Posted 06 February 2013 - 19:18

Alright nice I'll give it a go when the PC I do PIC work on is back in operation.

#15 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 06 February 2013 - 20:00

I just checked the XC16 v1.1 User Manual to make sure that my assumption that the compiler supports your device as well is correct. According to section 1.2:

1.2 DEVICE DESCRIPTION
The MPLAB XC16 C compiler fully supports all Microchip 16-bit devices:
• The dsPIC® family of digital signal controllers combines the high performance required in digital signal processor (DSP) applications with standard microcontroller (MCU) features needed for embedded applications.
• The PIC24 family of MCUs are identical to the dsPIC DSCs with the exception that they do not have the digital signal controller module or that subset of instructions. They are a subset, and are high-performance MCUs intended for applications that do not require the power of the DSC capabilities.


The latest version of the MPLAB XC 16 compiler and user manual can be downloaded here, and the source code can be downloaded here (since the compiler is GCC based). The XC16 C compiler runs perfectly on my Debian 7 (AMD64) installation, so I assume it will work equally as well for you on Arch.