|
|
View previous topic :: View next topic |
Author |
Message |
kittysoman2013
Joined: 24 Apr 2020 Posts: 1 Location: Banned - spammer
|
How to run my init code before ccs init code ? |
Posted: Fri Apr 24, 2020 12:08 am |
|
|
Before ccs initializes things like the uart I want my init code to run first. How do I do this? What I need to do is to set outputs as quick as possible.
thx Soman _________________ He-banned-llo, My na-banned-me is So-banned-man, ni-banned-ce to me-banned-et y-banned-ou |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Apr 24, 2020 12:54 am |
|
|
There is a little tiny bit you can't avoid, but several things are involved:
First for all your peripheral setups, use 'NOINIT'. This prevents the boot
initialisation code being generated. You then have to call the initialisation
for each peripheral after the boot.
So (for example)
Code: |
#USE RS232(UART1, BAUD=9600, BITS=8, NOINIT, STREAM=PC)
//Then main
void main(void)
{
//your code to intialise
setup_uart(9600,PC); //will generate the UART init code
}
|
Then second thing is not to have any variables initialised. Have your main
do your required initialisation, and then do the port setups for I2C, RS232
etc, and then call the 'real' main function. Have this contain your variables
then these will only be initialised when this function is called, not at boot.
Then the third, add:
Code: |
#device NO_DIGITAL_INIT
|
This prevents the I/O pin initialisation from being done.
Done like this, your port initialisation can be just about four instruction
times after boot.
I have to query the thinking here though. The PIC takes time before it's
code actually starts running. If you have a crystal oscillator you really
need PUT, and in this case many clock cycles will pass before the chip
actually starts. You really need to design the external hardware, so all
pins are held to 'safe' levels, until the PIC starts. So high impedance bias
resistors ensuring switches are turned 'off' and nothing untoward will
happen till you start things.... |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Fri Apr 24, 2020 4:26 am |
|
|
Ttelmah wrote: | I have to query the thinking here though. The PIC takes time before it's
code actually starts running. If you have a crystal oscillator you really
need PUT, and in this case many clock cycles will pass before the chip
actually starts. You really need to design the external hardware, so all
pins are held to 'safe' levels, until the PIC starts. So high impedance bias
resistors ensuring switches are turned 'off' and nothing untoward will
happen till you start things.... |
This is absolutely correct. Keep in mind that the PIC powers up with all pins as inputs which is the safest possible way to start. Anything that the PIC drives should have appropriate pullup/pulldown/bias resistors to ensure that nothing bad will happen between power being applied and processor actually starting to execute code. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Apr 24, 2020 5:04 am |
|
|
An 'old school' test
1) remove PIC from socket. yes, back then, when the dinosaurs roamed ,we put PICs in sockets.....heck every DIP was in a socket (with bypass cap).
2) apply power to PCB.
3) see if anything 'bad' happens, motors spinning, valves energized, LEDs on...
The point being that NOTHING should happen, if it does, then you need to pullup or pulldown the control inputs to whatever devices the PIC will be controlling. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Fri Apr 24, 2020 9:51 am |
|
|
temtronic wrote: | An 'old school' test
1) remove PIC from socket. yes, back then, when the dinosaurs roamed ,we put PICs in sockets.....heck every DIP was in a socket (with bypass cap).
2) apply power to PCB.
3) see if anything 'bad' happens, motors spinning, valves energized, LEDs on... |
4) If the project can be hot swapped (system as a whole powered but your project can be inserted into or removed from the system at any time), and your project has some sort of communication channel/lines with the rest of the system, you must ensure that if the PIC isn't powered, then that does not hurt the communication going on in the rest of the system. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Apr 25, 2020 5:38 am |
|
|
I've been thinking about this again.. and it also depends upon PIC and clock speed.
Modern PICs (16/18) can run at 64MHz, so 'power up / init' is less than a 'blink of an eye' compared to 16C84s running at 4MHz.
and yes, I've been bitten by 4.........sigh, more than once too.... |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Sat Apr 25, 2020 10:28 am |
|
|
temtronic wrote: | and yes, I've been bitten by 4.........sigh, more than once too.... |
Why do you think I added it to the list? I think most experienced people have had this happen to them. |
|
|
|
|
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
|