Dynamically remapping output pins

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jan.didden
Posts: 82
http://meble-kuchenne.info.pl
Joined: Thu Dec 17, 2020 3:16 pm
Has thanked: 20 times
Been thanked: 12 times

Dynamically remapping output pins

Post by jan.didden »

I need to dynamically (under program control) remap the output of the PWM3 channel to different output pins, like B2, B3, B4.
In the PWM component properties dialog I can select an initial output pin, like B3. But then later in the program I need to redirect it to for instance B4.
Studying the data sheet (PIC16F15355) it appears that the output pin redirection register is RxyPPS with xy standing in for the output pin.
So to connect output PWM3 to pin B4 I would need to set register RB4PPS to the code for PWM3.
According to table 15.3 in the data sheet, that code is 0x0b.
So I need to set register RB4PPS to 0x0b to effect the redirect.

I'm not sure how to do this. Do I need a C-code block for that? RB4PPS is not recognised as a register name by FC.
Do I need to use one of the FC internal registers FCR_xxxx?
Can someone please enlighten me?

Jan

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Dynamically remapping output pins

Post by BenR »

Hi Jan,

Yes you're certainly on the right lines there, It should be as simple as using a C icon to write the following.

Code: Select all

RB4PPS = 0x0b;
You might also need to set the previous pin back to IO mode or the signal will appear on both pins, assuming B3 was the previously assigned pin.

Code: Select all

RB3PPS = 0x00;

jan.didden
Posts: 82
Joined: Thu Dec 17, 2020 3:16 pm
Has thanked: 20 times
Been thanked: 12 times

Re: Dynamically remapping output pins

Post by jan.didden »

Hi Ben, that does not appear to work, see attached.
I can select which LED is flashing by selecting the appropriate port/pin in the PWM component property dialog,
(which confirms the correct hardware connections), but it doesn't redirect due to the code.

Jan
Attachments
PWM_fader JD-1.fcfx
(16.9 KiB) Downloaded 47 times

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Dynamically remapping output pins

Post by BenR »

Hello,

You don't set flashcntr to 0 at the top of your program. Maybe that has something to do with it?

jan.didden
Posts: 82
Joined: Thu Dec 17, 2020 3:16 pm
Has thanked: 20 times
Been thanked: 12 times

Re: Dynamically remapping output pins

Post by jan.didden »

I'll check, but the flashing as such works correctly, so I don't think thats the issue, also it is defined with initial value 0.

Jan

jan.didden
Posts: 82
Joined: Thu Dec 17, 2020 3:16 pm
Has thanked: 20 times
Been thanked: 12 times

Re: Dynamically remapping output pins

Post by jan.didden »

No change. I also tried to re-enable the PWM after each redirect command, thinking that redirection might stop it.
But that didn't make a difference either.

But! The plot thickens, see attached.
I did reset the config bit that allows only a one-time redirection (for instance at init, but not when the program runs), but it could be that PPSLOCK is on at default.
Edit: it should be unlocked at default, according to the data sheet. And the unlock sequence didn't do the trick :-(

BTW How does one do a Banksel in C? asm Banksel PPSLOCK throws an error.

Jan
Attachments
pps.PNG
pps.PNG (122.92 KiB) Viewed 1830 times

jan.didden
Posts: 82
Joined: Thu Dec 17, 2020 3:16 pm
Has thanked: 20 times
Been thanked: 12 times

Re: Dynamically remapping output pins

Post by jan.didden »

Latest version, not sure what else to try.

jan
Attachments
PWM_fader JD-2.fcfx
(18.49 KiB) Downloaded 44 times

jan.didden
Posts: 82
Joined: Thu Dec 17, 2020 3:16 pm
Has thanked: 20 times
Been thanked: 12 times

Re: Dynamically remapping output pins

Post by jan.didden »

I found this video on the subject from Microchip: https://www.youtube.com/watch?v=tf2SfSm6fQg

Anyway, finally got it to work. It appears that if you redirect to another pin, you have to 'reset' the redirection that was in place before.
For example, if you redirect first to RB2 and then to RB3, you set the new pin:

RB3PPS = 0x0B // in case of the PWM3 redirect to B3
RB2PPS = 0x00 // reset previous redirect

Didn't find it anywhere in the doc but it works and in hindsight is logical. The 0x00 was an educated guess.
My light went on when I realized that in some cases the blinking color was a mix of two LED colors ...

BTW No need to unlock PPS, it is unlocked by power on default.

Jan
Attachments
PWM_fader JD-4.fcfx
(19.79 KiB) Downloaded 42 times
Last edited by jan.didden on Thu Jun 16, 2022 9:39 am, edited 1 time in total.

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Dynamically remapping output pins

Post by BenR »

Hi Jan,

Well done, glad you got it working and thanks for letting us know how.

Post Reply