|
|
View previous topic :: View next topic |
Author |
Message |
delene
Joined: 13 Oct 2003 Posts: 32
|
PIC18f4523 |
Posted: Tue Jan 10, 2012 4:38 am |
|
|
I had my code all working perfectly on the 16f877A and the 18f452. I then decided to change to the 18f4523 and with a few tweeks have gotten it to work, but I do have some hassles.
I have a membrane keypad with the on button connected to pin_a4. On the 16f877a and 18f452 only when you push this button does the board turn on.
With the pic18f4523, as soon as you put power it turns on, the code though only starts working when the button is pushed.
This also means that the board never turns off.
What would be causing this? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Jan 10, 2012 5:53 am |
|
|
On the PIC18F452, and many other PICS, RA4 is an open drain output. I suspect your application uses this to latch the power on. In other words sets A4 as an input, reads it, if the external pushbutton pulls it low (there will be a pull up resistor somewhere) then the firmware sees that and then drives RA4 as an output, holding it low, keeping the power on.
However the PIC18F4523 is different, RA4 is a normal output, therefore it cannot be used in the same way. The symptoms you describe are pretty much what I'd expect from this. You could alter the firmware to operate it in a open drain way by careful use of output_drive() (i.e. output a low continuously, but drive the output to hold it low. Hi z, or read it as an input, to give a 1).
RF Developer |
|
|
delene
Joined: 13 Oct 2003 Posts: 32
|
|
Posted: Tue Jan 10, 2012 6:38 am |
|
|
What you are saying makes sense, but I am a little uncertain as to how to use the output_drive.
My exisiting code is
Code: | StartUp:
if (input(PIN_A4)) // Scale turned on
goto StartUp;
output_low(PIN_A4); |
and then when I want to turn off I use Code: | output_high(PIN_A4); |
How and where would I use the output_drive();
Thank you for the help |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Jan 10, 2012 8:53 am |
|
|
You actually need to use fast io, which will affect all port B io.
You need something like this:
Code: |
#use FAST_IO(A)
output_float(PIN_A4); // Or set bit 4 to input using set_tris_a()
// Note all bits of port B are now in fast mode and are inputs. You must
// set all relevant bits of port B to be inputs or outputs as required by
// the reast of your code. You can use set_tris_B() to set all bits of port B
// at once, or you can use output_drive() for each bit you want to use as a
// output, BUT not bit 4 which must be set as an input, or output_float().
output_low(PIN_A4); // Set A4 to output a zero; when we drive it that is.
StartUp:
if (input(PIN_A4)) // Scale turned on
goto StartUp;
// Please, please, please don't use goto!! This should be a simple while with
// no code. Read it as "loop round and round while A4 is high."
while (input(PIN_A4));
// A4 is now low as the button has been pressed.
output_drive(PIN_A4); // Drive pin A4. This now latches the power.
// Other code...
output_float(PIN_A4); // Release pin A4. It will float high, turning off the power.
|
One question: does this actually control the power? If so then pressing the button boots the PIC, which has to latch the power in its start up. I've done this before (with an ARM) and it works fine provided you don't hang around doing too much initialisation before latching the power. Then releasing the power latch actually turns of the processor completely, saving a lot of power.
RF Developer |
|
|
delene
Joined: 13 Oct 2003 Posts: 32
|
|
Posted: Tue Jan 10, 2012 9:18 am |
|
|
Hi RF Developer...
I tried out your code - and made a note about the while statement, and unfortunately it still doesn't work. As soon as I put power to the board, it is on - just waiting for the on button to be pressed. Nor does it turn off.
Quote: | One question: does this actually control the power? If so then pressing the button boots the PIC, which has to latch the power in its start up. I've done this before (with an ARM) and it works fine provided you don't hang around doing too much initialisation before latching the power. Then releasing the power latch actually turns of the processor completely, saving a lot of power. |
Yes PIN_A4 is actually controlling the power. That snippet of startup code is the very first thing that is done, only once it has been turned on does anything get initialised.
What else can I try |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Jan 10, 2012 10:16 am |
|
|
Is there a pull up resistor on A4? If there is, what value is it? It should be pulled up to the battery or input power, NOT to the controlled power. If there isn't, then the design may have relied on A4 floating high due to a) the PIC input (which is different on the 18F4523 compared to the 18F452) and on the external circuitry, i.e. the PSU stuff. Note there is a danger of over volting the input when power is off, so pull up should be a a highish value, >= 10K probably.
All PIC IO pins are set as inputs on start-up (maybe on reset, or may only be at power-up. Probably NOT on warm starts, i.e. restarts in firmware). So, the pull up to unswitched supply will hold the pin high and the PSUs off. Most PSU ICs have an active low enable which allows this to work. Then when the button is pressed the PSUs are enabled and the PIC boots. After a while, could well be 100ms or more, your code gets run and you drive A4 low. You don't actually need to input it, if the micro is running the button MUST have been pressed as there is power to run! However you cannot actively drive A4 high in case the button IS pressed, thereby shorting A4 to ground, which is not good, and may blow up your PIC.
You now have the PIC up and running and the firmware has control of the power. The user can keep the button pressed and hold the power up if they like, but as soon as they let go, the PIC can switch off. That means that you should not continue running normally after trying to turn the power off, you should continuously loop, say with a simple while(TRUE);
That's how this sort of thing normally works. So, either the pull up isn't as it should be, for example its to switched +5V rather than unswitched. That would mean A4 would be low when power is applied and the PSU would start. Also there may be a well meaningingly added capacitor across the power button, or some other "slugging" of the power control signal that slows it down. It also only really works with batteries where the unswitched power is always present, and its probably going to start by itself when the batteries are first connected. That's certainly how our handheld instrument worked when I last did this.
So there are quite a lot of system issues to think about and test and all my previous comments about the nature of A4 remain true.
RF Developer |
|
|
|
|
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
|