Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Changing CCP2 pin on the fly

Status
Not open for further replies.

Urahara

Member
Hi Everyone

The CCP2 module of the 18F4620 MCU allows me to use either pin RC1 or RB3 for its capabilities. However, it seems that it can only be defined under the #pragma config directive in C18, which means it can either be RC1 or RB3 when powered-on.

Is there a way to switch btw the two pins in the program (I am using C18)?

I have a requirement for 2xPWM (pin RC1 and RC2) and 1xCapture (pin RB3??) functionalities, but unfortunately, the MCU has only two such modules.

Any thoughts or ideas? Thks!
 
The 18 series allows you to change config settings in software so you should be able to do what you need. You still have only two CCP modules so you'll lose a PWM module when you need the capture mode.
 
Really?!! :)

It's ok to lose one of the PWM capability on pin RC1 when I am using the capture capability on pin RB3. I just want to be able to switch from RC1 to RB3 when a specific function is needed, and then switch back from RB3 to RC1 when it's done.

Sorry for my ignorance, but how do I do this? Links, etc would be useful.

Thks!
 
I believe blueroomelectronics misunderstood your question. He said you can reassign the FUNCTION of the CCP2 pin on the fly.

You want to change the pin CCP2 is assigned to on the fly. Unfortunately, it can't be done. That #pragma directive sets config bits, which are not code-accessible variable registers, they're ROM like the program space. The same is true of all the config bits.

CCP2 pin selection is in the config bits and only the programmer can change it. You've got to choose RC1 or RB3 and stick with it, the code cannot reassign it.
 
Last edited:
Take a look in the EEPROM section of an 18F datasheet. Look for the CFGS bit. You can access the configuration bits after programming. I've not used it but recalled it was something you could do with 18F series PICs.
 
Even if there's a way to self-program it, you probably wouldn't want to do it as part of normal code because of the limited write endurance of the cells. They're rated for a lot, but if you were to keep messing with them constantly, it's possible to exceed it. Plus the self-programming feature is a bit touchy. It's block-oriented, it's slow, and under certain brownout conditions it may fail to write, it's also possible to have a glitch write the wrong block and brick the part until it's reprogrammed.

Urahara, you can use the Microchip selection guide for that. There are >=3x PWM in the 18F series. You might be able to do PWM in software if your period and duty requirements aren't really high.
 
Last edited:
You can write the config' fuse locations on 18F' devices under program control but I think you have to 'reset' the mcu for any changes to take effect.
 
Bill is right! From the datasheet, it seems possible to access the bit that controls pin assignment. Datasheet indicated that everything will pause when the write is taking place, and then continues from where it left off. No restart was mentioned.

Still, I am now thinking twice abt doing that, as I am concerned an unexpected power-off after changing the pin to RB3 would mess up the MCU.

Unfortunately, I could not find a 40-pin DIP package that has 3 CCP modules.

Now I am thinking of using the same RC1 pin for my purpose :
1) Backlight brightness control of LCD module using PWM (Default behaviour)

2) Capture of pulses generated by a photodiode, TSL230R (When required)
View attachment CCP2 Design..pdf


My questions are :
1) When RC1 is generating PWM to drive the LCD module, will it damage or cause problem to the photo-diode?

2) When RC1 is capturing the pulses generated by the photo-diode, will it damage or cause problem to the LCD module?

Thks!
 
prefers not to meddle with A2D stuff. Thks!

Think I will start another thread specifically asking for opinion abt the "workability" of my new design.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top