|
|
View previous topic :: View next topic |
Author |
Message |
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
PIC24HJ to PIC24EP pin mapping |
Posted: Thu Jul 07, 2016 7:17 am |
|
|
Compiler: 5.026
Device: From 24HJ256GP206 to PIC24EP512GP806
Hello,
I am currently using the 24HJ256GP206 device and I want to change to the PIC24EP512GP806.
All pins match (a few I just need to change port E to port G) but the ones that concern me the most are the following (because I am using them on the PIC24HJ and need them on the PIC24EP):
PIC24HJ
=====
Pin 31 == U2RX
Pin 32 == U2TX
Pin 33 == U1TX
Pin 34 == U1RX
Pin 39 == CLKIN
Pins 42-45 == EXT INT1-4
PIC24EP
=====
Pin 31 == RP100
Pin 32 == RP101
Pin 33 == RP99
Pin 34 == RP98
Pin 39 == RPi60
Pins 42-45 == RPi72-75
It's the first time I look at the PIC24EP-series and I'm not quite sure how to address this pin-mapping issue.
So, how do I tell the PIC24EP to configure its pins so that they have the same functions as the PIC24HJ?
I am currently reading the PIC24EP manual but I want to speed-up the process. If you can post code, that would be very helpful.
Thanks!
Ben |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Thu Jul 07, 2016 7:34 am |
|
|
You don't use RP numbers, but pin names.
So pin 31, is PIN_F4.
Code: |
#PIN_SELECT U2RX=PIN_F4
#PIN_SELECT U2TX=PIN_F5
|
This then connects U2 to these pins.
If you then use your UART setup by UART name (no reference to pin numbers), the compiler will just use the hardware directly:
Code: |
#use rs232(UART2, baud=57600, ERRORS)
|
Directly uses the selected pins.
U1, is the same except on PIN_F2, and F3
CLKIN for what?. If you mean the oscillator, this is already hardware mapped to the same pin. The pin can be used as a relocatable peripheral, if you are not using the clock input, but otherwise the hardware oscillator input is already there. CLKIN itself, is not a relocatable peripheral.
The INT's are just called INT1, INT2, INT3, INT4, and these can be mapped to any suitable pin, so:
Code: |
#PIN_SELECT INT1=PIN_D8
#PIN_SELECT INT2=PIN_D9
#PIN_SELECT INT3=PIN_D10
#PIN_SELECT INT4=PIN_D11
|
|
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Thu Jul 07, 2016 8:16 am |
|
|
Hi Ttelmah,
Ok, that seems pretty clear. Thanks so much.
As for the CLKIN pin, on my circuit I am using PIN 39 as the clock input because it's getting its clock from an external oscillator (FXO-HC735R-36.864). That clock feeds the master clock of an audio CODEC as well as the MCU.
On the PIC24H, it shows on the pinout diagram that PIN 39 is OSC1/CLCKIN/RC12.
On the PIC24E, it shows OSC1/RPi60/RC12.
So, maybe I am just confused with the terminology? It's true, I don't see any reference in my code for "CLKIN" but I guess I just took for granted that it was that word I should have used rather than OSC1?
In my header file, I have these two lines:
Code: |
#fuses HS, WDT, PR, WPOSTS16
#use delay( crystal = 36864000, clock = 73728000 ) |
So basically, other than for the pin mapping, these two devices are pin-to-pin compatible and only a few minor changes are needed, correct?
I will be bumping the crystal from 36.864MHz to 60MHz.
Thanks again,
Benoit |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Thu Jul 07, 2016 9:09 am |
|
|
Ok, so I did the pin mapping and it's almost compiling.... I still have two issues + the CLKIN from my previous post above:
First, in PIC24HJ header file, I have COMPARE_PWM and I use it here:
Code: |
setup_compare( 1, COMPARE_PWM | COMPARE_TIMER2 );
setup_timer2( TMR_INTERNAL | TMR_DIV_BY_1, Value );
set_pwm_duty( 1, (( Value + 1 ) / 2 )); |
I am using pin D0 as as a 128kHz PWM.
For the PIC24EP, I only see COMPARE_PWM_EDGE rather than simply COMPARE_PWM.
In both cases, the value is 0x0006. Does this mean it's the same thing? I will assume so but clarification would be appreciated.
And when I try to compile with the above three lines and change COMPARE_PWM to COMPARE_PWM_EDGE, I get two errors 'Invalid parameters to built-in function :: Invalid pin'. When I double-click on the errors, the compiler highlights <COMPARE_TIMER2> from the first line above and when I click on the second, it highlights the parentheses inside the third line. So obviously, the compiler is popping errors but not pointing me to the right place it seems??
Second, on the PIC24H, INT0 is on pin 35 but on the PIC24E, it is pin 46.
I cannot simply solder a wire because PIN 46 on the PIC24H is already used as my PWM output.
Given that my circuits are already done and working with the PIC24H, is there a way on the PIC24E to tell it to use pin 35 as an interrupt?
It's not super critical, that pin is used to detect if the on-board SD card has been inserted or removed but I don't want to have a periodic timer checking that pin if it's high or low because the processor is already doing a million other things at the same time (processing real-time data)... that's why the interrupt is handy.
Thanks again,
Ben |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Thu Jul 07, 2016 10:47 am |
|
|
The error is telling you that you have an invalid pin. Did you do a pin_select statement for your PWM pin? All remappable peripherals require a pin_select statement(s) before their functions can be used.
D0 is a remappable pin and PWM requires remapping.
Also Pin35 (PIN_F6) is remappable, so you can put a remappable interrupt on there. (so another pin_select)
You should spend some time reading section 11.4 of your datasheet to understand the peripheral pin select. If you use other peripherals in this category you will need to map them as well. Tables 11-1 and 11-3 have all the input and output sources that must be remapped. |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Thu Jul 07, 2016 11:09 am |
|
|
Hi Jeremiah,
Thanks for the info.
But if you look at the PIC24H and PIC24E, the 'H' version has PIN 35 (F6) as U1RTS/SCK1/INT0/RF6.
Now if you look at the 'E' version, PIN 35 only says RP102/RF6. But if you look at PIN 46, it says INT0/RP64/RD0.
Then in the Microchip specs DS70616G, page 25, if you look at <TABLE 1-1 PIN I/O DESCRIPTIONS> and scroll down to the external interrupts (middle), it shows that INT 0 is _NOT_ a PPS pin but the others are.
So, although PIN F6 is a reprogrammable and D0 is reprogrammable, INT0 is stuck on D0 from what that table 1-1 tells me.
However, if you know how to remap INT0 to RF6, then please show me the code to do it because I have no clue.
As for D0 being a remappable pin and PWM requires remapping, I'm confused there as well. Why would I need to re-map the PIN D0 for the PWM when on both devices, PIN D0 is PIN 46? The remapping would only be for stuff like UART1 and such... but this is the pin itself.
Again, this pin mapping thing is new to me and I don't have the PIC with me, I just placed the order this morning. Now I'm just trying to recompile the code for the new PIC to see how it will react.
You seem to know what I am trying to do. Can you post the code? Because in all honesty, I don't know to remap an interrupt that is not remappable and how to remap pin D0 (46) to the same pin D0 (46).
Thanks again,
Benoit |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Thu Jul 07, 2016 12:01 pm |
|
|
You can't remap fixed peripherals. That's the whole point of the word 'fixed'....
What you could do is put another interrupt on the re-mappable pin, if you are not using them all. |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Thu Jul 07, 2016 12:24 pm |
|
|
But aren't there only 5 external interrupts (INT0-INT4)?
And as for Jeremiah's message regarding the PWM pin D0 that I am currently using, I don't see how this pin can be mapped to the PWM because it is the same on both PIC versions: D0 is PIN 46. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Thu Jul 07, 2016 12:36 pm |
|
|
There are a lot of other ways of generating an interrupt. You can (for instance), use 'input capture', to generate an interrupt each time an input counts, by using a timer, and having this reset on a count of 1. However if you want INT0, then this is fixed on the pin it is on.
There are two different PWM's on the more complex chip. The normal timer based PWM, and the separate high speed PWM module. The latter is setup using the setup_hspwm function, and uses fixed pins. The former is a relocatable peripheral. So effectively there are two PWM 1's. One the high speed one, and the other the traditional one. Both can be used at the same time. If you are using 'setup compare', you are using the timer based one, and this requires you to have selected the pin using #pin select....
The normal timer based peripheral is 'output compare', and on the old chip you were using OCx to generate this, and it is the equivalent OCx peripheral that you have to setup. |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Fri Jul 08, 2016 4:43 am |
|
|
Hi Ttelmah,
Ok, that's good to know that there are two different PWMs. Again, this is a new device to me.
However, I still don't understand how to re-map pin D0 (46) which I am already using to pin D0 (46)..... Or in other words, if I absolutely need to use #PIN_SELECT for PIN D0 for PWM 1, then what is the #PIN_SELECT I need to setup given that this is my PWM setup for the 24H:
setup_compare( 1, COMPARE_PWM | COMPARE_TIMER2 );
setup_timer2( TMR_INTERNAL | TMR_DIV_BY_1, Value );
set_pwm_duty( 1, (( Value + 1 ) / 2 ));
And getting back to your second reply to me, am I wrong to use the term CLKIN for the input clock on pin OSC1/RPi60/RC12? Should I have used the term OSC1 instead?
I guess clarifying these two issues will enable me to compile my code. I am receiving the parts today.
Thanks again!
Ben |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Jul 08, 2016 8:20 am |
|
|
You are generating your PWM here using an output compare module. As I have already said this module's output pin is called 'OCx', with the 'x' being the number of the module being used (1 in this case). So you need to select OC1 to the pin you want. If you look at the output compare module block diagram (15-1), it shows the pin names used. On your old chip, you will see that PIN46, has OC1 on it (no mention of PWM you note).
#PIN_SELECT OC1=PIN_D0
On the clock it doesn't matter, except if you had looked at the oscillator diagram, you would see that the primary oscillator input pin is already fixed to the pin you want. 'CLKIN', could apply to so many other things (synchronous serial, timers, etc. etc..). The oscillator pins can _not_ be relocated, since they have to be working for the chip to actually boot, if an external oscillator is being used, so when you asked about relocating 'CLKIN', I asked 'of what'.... |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Fri Jul 08, 2016 8:24 am |
|
|
EDIT:
Looks like Ttelmah drank some good coffee this morning. Beat me by a few mins!
benoitstjean wrote: |
However, I still don't understand how to re-map pin D0 (46) which I am already using to pin D0 (46)..... Or in other words, if I absolutely need to use #PIN_SELECT for PIN D0 for PWM 1, then what is the #PIN_SELECT I need to setup given that this is my PWM setup for the 24H:
setup_compare( 1, COMPARE_PWM | COMPARE_TIMER2 );
setup_timer2( TMR_INTERNAL | TMR_DIV_BY_1, Value );
set_pwm_duty( 1, (( Value + 1 ) / 2 ));
|
You are not remapping PIN_D0 to PIN_D0, you are going to remap PIN_D0 to the PWM peripheral. pin_select doesn't map pins to other pins. It maps pins to peripherals (and vice versa).
Out of the box, on the EP chip, the PWM module doesn't have any pins. The pin_select is a way to *assign* pins to the peripheral so you can use it.
I don't know your chip specifically, but it would be something similar to what has already been discussed:
#pin_select OC1 = PIN_D0
Just some quick comments
benoitstjean wrote: |
Hi Jeremiah,
Thanks for the info.
But if you look at the PIC24H and PIC24E, the 'H' version has PIN 35 (F6) as U1RTS/SCK1/INT0/RF6.
Now if you look at the 'E' version, PIN 35 only says RP102/RF6. But if you look at PIN 46, it says INT0/RP64/RD0.
Then in the Microchip specs DS70616G, page 25, if you look at <TABLE 1-1 PIN I/O DESCRIPTIONS> and scroll down to the external interrupts (middle), it shows that INT 0 is _NOT_ a PPS pin but the others are.
|
My comment earlier was to assign it to another interrupt so you could use the same exact pin # (INT1, etc.). Is there any reason it *has to be* INT0? There are very few reasons for which one would pick INT0 specifically.
benoitstjean wrote: |
So, although PIN F6 is a reprogrammable and D0 is reprogrammable, INT0 is stuck on D0 from what that table 1-1 tells me.
However, if you know how to remap INT0 to RF6, then please show me the code to do it because I have no clue.
|
You probably don't need to remap INT0 at all. Just switch INT0 to another INT like INT1 or such and then remap INT1 to that pin.
#pin_select INT1 = PIN_F6
After that just make sure to switch your ISR code and enable/disable interrupt code to match the new interrupt. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Jul 08, 2016 8:53 am |
|
|
It's late afternoon here, and I've spent the day traipsing many miles.
Searching shops for an old thermometer. Need one close to an original, so that I can re-manufacture the brass plate, and it'll look/fit correctly.
Visited something over 500 antique dealers today.
Collapsed into my chair, for some programming....
Anyway he seems to already be using all four of the re-locatable interrupts (look at his original post). Why, I don't know. Five separate external interrupts does seem OTT....
However input capture offers him loads more interrupts. You can program any of these the capture on either the rising or falling edge. Only extra overhead, is to make sure you read the buffer in the interrupt handler (or the interrupt can't be cleared). |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Fri Jul 08, 2016 9:02 am |
|
|
Ah! Gotcha! Ok so I guess the OC1 (Output Compare) is what confused me! Just tried it and it works!!!
When I say it works, I mean it now compiles without errors. I haven't received the PIC devices yet (sometime today) and then I am leaving for 2 weeks on holidays so I will try it physically upon my return.
As for INT0, the reason to use that one particularily is that all my PCB's are done and working with the PIC24H and I am using all 5 external interrupts. INT0 on the PIC24H is on different pin than on the PIC24E... that's like the ONLY different and of course, it's not remapable. It's not a big deal because it is only used to detect the presence of an SD card and the interrupt is fired upon insertions/removal.
When I do version 2, I will look into that pin to change it.
Now I guess my last question pertains to the OSC1/CLKIN/RC12 pin 39 on the PIC24H which is OSC1/RPi60/RC12 on the PIC24E.
I am getting my PIC clock (square wave) from an external source and it goes into PIN39. I thought that the OSC1/OSC2 pins were for the little 2-pin tin-can crystals tied between OSCa and OSC2 and for high-speed oscillators (square wave like mine), although I am still using PIN39, it's a "clock input" hence CLKIN.
So my question is on the PIC24E, since PIN39 doesn't say CLCKIN, will my 60MHz oscillator still work?
Thanks a million!
Ben |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Fri Jul 08, 2016 11:20 am |
|
|
Ttelmah wrote: |
Anyway he seems to already be using all four of the re-locatable interrupts (look at his original post). Why, I don't know. Five separate external interrupts does seem OTT....
|
I missed that! Thanks.
benoitstjean wrote: |
As for INT0, the reason to use that one particularily is that all my PCB's are done and working with the PIC24H and I am using all 5 external interrupts. INT0 on the PIC24H is on different pin than on the PIC24E... that's like the ONLY different and of course, it's not remapable. It's not a big deal because it is only used to detect the presence of an SD card and the interrupt is fired upon insertions/removal.
|
For something that simple, consider using a Change Notification interrupt:
Code: |
#INT_CNI
void cni_isr(){
//do stuff
//If you have multiple pins issuing this interrupt, you have to check
//each one.
}
void main()
{
enable_interrupts(INTR_CN_PIN | PIN_D0);
enable_interrupts(INTR_CN_PIN | PIN_D1); //if you want another
enable_interrupts(GLOBAL);
while(TRUE)
{
}
}
|
It doesn't require remapping pins (so no pin select). However there are some caveats:
1. Only one interrupt for all CN selected pins. So if you choose to use multiple CN pins, in the interrupt you need to check each one individually to see which one or ones (multiple) fired the interrupt.
2. It always fires for both rising and falling edges. If you don't care, great, but if you do, you'll need to use a variable to remember the last state and compare it to figure out what type of edge it is. However if all you care about is if it is high or low, you can just read the pin input register to find that out and do what you need to do.
In your case you only need to replace INT0, so you can just do PIN_D0 and look at high/low to determine insertion and removal. |
|
|
|
|
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
|