|
|
View previous topic :: View next topic |
Author |
Message |
mcbrideja Guest
|
PIC18F1220 18pin vs 20pin constant definitions |
Posted: Fri May 23, 2003 12:38 pm |
|
|
In reference to my post about:
Picdem2 board, ICD2, 18F1220, USB, MPLAB 6.21 not programming
It appears that there is a difference with the mapping of defined constants for pins between the 18pin and 20pin version. The 20pin version has AVSS and AVDD pins that the 18pin does not. When telling the chip to make RB0 high, RB3 goes high. How do I get the constants correct? Where is the info?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514712 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Fri May 23, 2003 2:40 pm |
|
|
:=In reference to my post about:
:=Picdem2 board, ICD2, 18F1220, USB, MPLAB 6.21 not programming
:=It appears that there is a difference with the mapping of defined constants for pins between the 18pin and 20pin version. The 20pin version has AVSS and AVDD pins that the 18pin does not. When telling the chip to make RB0 high, RB3 goes high. How do I get the constants correct? Where is the info?
------------------------------------------------------
This should be controlled by the hardware wiring on your
printed circuit board. Which package are you using on your
demo board ? Is it the 18 or 20 pin ? Which package is the board designed for ? Are you using an adapter of some sort ?
Have you checked the wiring with an ohmmeter ?
--------
It's possible, I suppose, that the .h file has incorrect
definitions for the pins. I don't have PCH, so I don't
know how it defines the pins, but in PCM, it's done like this:
<PRE>
CCS's Converted Converted to
value to hex binary fields
#define PIN_B0 48 0x30 00 110 000
#define PIN_B1 49 0x31 00 110 001
#define PIN_B2 50 0x32 00 110 010
#define PIN_B3 51 0x33 00 110 011
#define PIN_B4 52 0x34 00 110 100
#define PIN_B5 53 0x35 00 110 101
#define PIN_B6 54 0x36 00 110 110
#define PIN_B7 55 0x37 00 110 111
</PRE>
After I've converted it to binary fields, you can see that
the first 3-bit field is the Port address. In this case,
the address is 6, for Port B. The last 3-bit field is the
bit number, 0-7.
You could analyze the Port B values in your 18F1220.h file and
see if they are correct. CCS may use a different format,
because the port addresses are 3 digits in the 18F series.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514713 |
|
|
R.J.Hamlett Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Sat May 24, 2003 2:18 am |
|
|
:=In reference to my post about:
:=Picdem2 board, ICD2, 18F1220, USB, MPLAB 6.21 not programming
:=It appears that there is a difference with the mapping of defined constants for pins between the 18pin and 20pin version. The 20pin version has AVSS and AVDD pins that the 18pin does not. When telling the chip to make RB0 high, RB3 goes high. How do I get the constants correct? Where is the info?
There is no difference in the constant definitions between the two chips. The compiler, does not care which physical pin a feature is on, this is a matter for the external wiring round the chips. The only changes that 'matter', are the addition of the two extra supply pins for AVdd, and AVss, but even these make no difference to the compiler. Both versions of the chip, support on the analog port, selecting between using Avdd/AVss, and the Vref+/Vref- connections (look at the chips data sheet, page 155 for the four different configurations). On the 18pin version, selecting Avdd, or AVss, results in the normal Vss/Vdd supply being used (since the pins are joined internally), but on the 20pin versions, selecting these options allow an external supply to be used.
The four options that correspond to the four configurations in the data sheet, are in the include file, as:
#define VSS_VDD 0x00
#define VREF_VREF 0x30
#define VREF_VDD 0x20
#define VSS_VREF 0x10
RB3, is connected to the normal CCP, and also to the ECCP module. Are you sure you have set the configuration options for these modules, to disable them?.
Post a tiny code snippet, showing your initialisation, and just setting/resetting RB0, so we can see if anything is obvious.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514717 |
|
|
mcbrideja Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Tue May 27, 2003 8:28 am |
|
|
:=This should be controlled by the hardware wiring on your
:=printed circuit board. Which package are you using on your
:=demo board ? Is it the 18 or 20 pin ? Which package is the board designed for ? Are you using an adapter of some sort ?
:=Have you checked the wiring with an ohmmeter?
I have the 18 pin package. The board has an 18 pin socket for this chip, no adapter.(It has two other sockets as well, only one chip at a time can be used, all sockets share power and port wiring.) I have checked to make sure that the pinouts line up with the circuit pins. But I have been using a logic probe on the chip's pins directly to try and swee what was going on. I am going to look more deeply into the AVSS AVDD settings as suggested.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514781 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Tue May 27, 2003 2:17 pm |
|
|
:=I have the 18 pin package. The board has an 18 pin socket for this chip, no adapter.(It has two other sockets as well, only one chip at a time can be used, all sockets share power and port wiring.) I have checked to make sure that the pinouts line up with the circuit pins. But I have been using a logic probe on the chip's pins directly to try and swee what was going on. I am going to look more deeply into the AVSS AVDD settings as suggested.
-----------------------------------------------------------
I have an idea. Can you post the model of your Picdem2 board.
There's a picdem2, and a picdem2-Plus. Which do you have ?
Then we can look at the schematic, in the manual which is
available online.
Then, post the section of your .LST file that toggles the
port pin. From that, we can see exactly which port pin
is being toggled by the generated code, and compare it to
the schematic and see what's happening.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514794 |
|
|
mcbrideja Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Tue May 27, 2003 9:03 pm |
|
|
:=RB3, is connected to the normal CCP, and also to the ECCP module. Are you sure you have set the configuration options for these modules, to disable them?.
:=Post a tiny code snippet, showing your initialisation, and just setting/resetting RB0, so we can see if anything is obvious.
:=
:=Best Wishes
I am just using the simulator now to try and figure this one out. Here is what I am stuck with...
#include <18F1220.h>
#fuses XT,NOWDT,NOLVP
#use delay(clock = 4000000)
#zero_ram
void main(void){
SETUP_ADC(NO_ANALOGS | VSS_VDD);
SETUP_CCP1(CCP_OFF);
while(1)
{
output_low(pin_b0);//effects only latb.0
//delay_ms(500);
output_high(pin_b0);//effects only latb.0
output_high(pin_b1);//effects only latb.1
output_high(pin_b2);//effects only latb.2
output_high(pin_b3);//effects latb.3 and portb.3
output_b(0b11111111);//makes portb = 0b11101100
//delay_ms(500);
}
}
This chip has so many pins multiplexed I am guessing that that is my problem somewhere. I can't seem to isolate the significance of RB0, RB1 and RB4. And what is latb used for? This 18f series is killin me.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514800 |
|
|
mcbrideja Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Tue May 27, 2003 9:22 pm |
|
|
<font face="Courier New" size=-1>:=I have an idea. Can you post the model of your Picdem2 board.
:=There's a picdem2, and a picdem2-Plus. Which do you have ?
:=Then we can look at the schematic, in the manual which is
:=available online.
:=
:=Then, post the section of your .LST file that toggles the
:=port pin. From that, we can see exactly which port pin
:=is being toggled by the generated code, and compare it to
:=the schematic and see what's happening.
I have the Picdem 2 plus version. I was probing the actual pin on the MCU and it is getting set. I think the board may have issues. Please see my other post for my latest attempts with portb. (update) The board buzzes out as per the schematics. The problem is (with this chip at least) RB3 designation for the board is RA2 for the chip. And you guessed it, the board's RB0 is the chip's RB3. Sheesh!!
My ultimate design will use 1 ADC, CCP_PWM, and 2 port_b interupt on change pins. </font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514801 |
|
|
R.J.Hamlett Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Wed May 28, 2003 2:37 am |
|
|
:=:=RB3, is connected to the normal CCP, and also to the ECCP module. Are you sure you have set the configuration options for these modules, to disable them?.
:=:=Post a tiny code snippet, showing your initialisation, and just setting/resetting RB0, so we can see if anything is obvious.
:=:=
:=:=Best Wishes
:=I am just using the simulator now to try and figure this one out. Here is what I am stuck with...
:=#include <18F1220.h>
:=#fuses XT,NOWDT,NOLVP
:=#use delay(clock = 4000000)
:=#zero_ram
:=
:=void main(void){
:=SETUP_ADC(NO_ANALOGS | VSS_VDD);
:=SETUP_CCP1(CCP_OFF);
:=while(1)
:= {
:= output_low(pin_b0);//effects only latb.0
:= //delay_ms(500);
:= output_high(pin_b0);//effects only latb.0
:= output_high(pin_b1);//effects only latb.1
:= output_high(pin_b2);//effects only latb.2
:= output_high(pin_b3);//effects latb.3 and portb.3
:= output_b(0b11111111);//makes portb = 0b11101100
:= //delay_ms(500);
:= }
:= }
:=
:=This chip has so many pins multiplexed I am guessing that that is my problem somewhere. I can't seem to isolate the significance of RB0, RB1 and RB4. And what is latb used for? This 18f series is killin me.
The PIC ports, have an output latch (in this case 'latb'), and the physical port connections to the outside world, which are 'visible' through the portb register.
Now traditionally, you can only write to one address (portb), which automatically writes to the latch. The problem is that if (for instance), you have portb wired with a reasonably heavy load on some of the pins (especially a lot of capacitance), and do something like this:
(assume you start with all the pins low).
output_b(0xFF);
//At this point the pins start to drive high, but because
//of the capacitance, the actual voltage levels on the pin
//will remain low for several mSec.
output_b(input_b() & 0xFE);
//Now the chip performs a 'read modify write' operation, reading
//port B, anding it with 0xFE, and writing this to the port.
//Unfortunately, since the pins have not yet charged to the
//'high' state, the read returns a '0', and the result is to
//set the whole port to '0'...
Now quite a few internal operations perform a 'red modify write'
operation, so on the PIC12/16 family, where the only access is directly to the output port, you _have_ to allways bear in mind the likelyhood of this happening...
On the PIC 18 family, the port registers are seperated out. Hence you can access the output latch itself, seperately from the physical voltage on the pins. Setting a bit in 'latb', should allways result in the same bit being set in portb, with the following 'provisos':
1) It may take several machine cycles to happen, depending on the capacitance present.
2) If the bit is overloaded, it may never happen.
3) If the bit is set as an input, you can set the output latch, and the output pin will remain unchanged till the TRIS register is altered.
4) The presence of another 'device' driving the pin, can override the change.
Now if I run the code you show on the simulator, it runs fine. Before you reach the 'output_b' instruction, TRISB, has been set to '0b11110000', and the bottom four bits of the output latch, have all been set. The PORTB output register, has changed to 0b00001100, reflecting the change on bits 2, and bits 3, bit not on bits 0, and 1. When you then perform the whole port write, the same effect is seen, with the result on the PORTB register, being 0B11101100.
The problem then is that something else is overriding bits 0, 1 & 4.
Looking at the code, reveals that the fault is in the 'setup_adc(NO_ANALOGS)' instruction. This is putting a byte value of 0xF into the ADCON1 register, when a value of 0x7F is actually needed to disable all the analog bits...
Chaning this define in the 18F1220.h file to read:
#define NO_ANALOGS 0x7F // None
makes the outputs work as expected. :-)
I suggest you point this out to CCS, so they can modify this defintion in the future (the rest are also wrong for the individual ADC bits).
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514804 |
|
|
mcbrideja Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Wed May 28, 2003 7:47 am |
|
|
:=The problem then is that something else is overriding bits 0, 1 & 4.
:=Looking at the code, reveals that the fault is in the 'setup_adc(NO_ANALOGS)' instruction. This is putting a byte value of 0xF into the ADCON1 register, when a value of 0x7F is actually needed to disable all the analog bits...
:=Chaning this define in the 18F1220.h file to read:
:=#define NO_ANALOGS 0x7F // None
:=
:=makes the outputs work as expected. :-)
:=
:=I suggest you point this out to CCS, so they can modify this defintion in the future (the rest are also wrong for the individual ADC bits).
:=
:=Best Wishes
You have just made my day!! I have also found that the LEDs on my picdem 2 plus board do not appear to be wired correctly for the 18 pin socket. RB0 is tied to the RB2 LED. I have had to probe the pins on the chip itself for debugging.
Thank you for your explanation on latb, makes perfect sense. I have been using the 16F877 exclusively for a few years so the 18 series is all new to me. I have been programmer inhibited. I will be double checking the registers from now on as I slowly step up this project. My goal is 1 ADC, 1 PWM and 2 interrupt on change pins.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514811 |
|
|
R.J.Hamlett Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Wed May 28, 2003 10:28 am |
|
|
:=:=The problem then is that something else is overriding bits 0, 1 & 4.
:=:=Looking at the code, reveals that the fault is in the 'setup_adc(NO_ANALOGS)' instruction. This is putting a byte value of 0xF into the ADCON1 register, when a value of 0x7F is actually needed to disable all the analog bits...
:=:=Chaning this define in the 18F1220.h file to read:
:=:=#define NO_ANALOGS 0x7F // None
:=:=
:=:=makes the outputs work as expected. :-)
:=:=
:=:=I suggest you point this out to CCS, so they can modify this defintion in the future (the rest are also wrong for the individual ADC bits).
:=:=
:=:=Best Wishes
:=
:=You have just made my day!! I have also found that the LEDs on my picdem 2 plus board do not appear to be wired correctly for the 18 pin socket. RB0 is tied to the RB2 LED. I have had to probe the pins on the chip itself for debugging.
:=
:=Thank you for your explanation on latb, makes perfect sense. I have been using the 16F877 exclusively for a few years so the 18 series is all new to me. I have been programmer inhibited. I will be double checking the registers from now on as I slowly step up this project. My goal is 1 ADC, 1 PWM and 2 interrupt on change pins.
Your posted simple example, made it possible to duplicate the problem, and find the reason. :-)
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514815 |
|
|
mcbrideja Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Wed May 28, 2003 5:49 pm |
|
|
<font face="Courier New" size=-1>:=:=:=Chaning this define in the 18F1220.h file to read:
:=:=:=#define NO_ANALOGS 0x7F // None
:=:=:=
:=:=:=makes the outputs work as expected. :-)
:=:=:=
:=:=:=I suggest you point this out to CCS, so they can modify this defintion in the future (the rest are also wrong for the individual ADC bits).
I will.
<Previously entered question deleted. The world will never know how dumb it was.></font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514823 |
|
|
mcbrideja Guest
|
Re: PIC18F1220 18pin vs 20pin constant definitions |
Posted: Wed May 28, 2003 10:04 pm |
|
|
oops...
setup_adc_ports( NO_ANALOGS ) works much better than
setup_adc( NO_ANALOGS )
nevermind...
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514827 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|