Device configuration

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

Device configuration

Postby Dimebag » Wed Jul 16, 2014 12:36 pm

Is it best practice to set all of a devices pins as input/output or, just set the pins needed for the target devices application?
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby Tom Maier » Wed Jul 16, 2014 1:10 pm

It's best to set unused pins for output.

Electromagnetic waves fill the environment and when they hit a conductor, it induces a current in the material. An input is high impedance (high resistance). This very tiny current oscillating across the high resistance creates a significant voltage, which can cause the input pin to oscillate. A low impedance (low resistance) output pin experiences the same current flow, but since voltage is equal to current flow times resistance, the resulting voltage is very low, so it causes no problem.

So the same electromagnetic field that can cause a 3 volt oscillation on an input pin would only cause a few millvolts on an output pin.

The oscillation on the input pin might not disturb your program, but can cause large currents to flow in the oscillating logic gates of the pin, resulting in abnormally high current flow for the design. That high current flow could disturb the program if it got too high, or it could burn out the input pin.

Also, if you have an input pin with a high impedance circuit you can get the same effect. A circuit with 1 Megohm input impedance circuit attached to it could oscillate easily under the influences of the ambient electromagnetic exposure. So, high impedance circuits need to be treated as a possible source of trouble.
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Tom Maier » Thu Jul 17, 2014 12:33 pm

Well, speak of the devil...

Microchip just made a new appnote about dealing with electromagnetic interference in analog input circuits...

http://www.microchip.com/stellent/idcpl ... e=en570565
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Dimebag » Thu Jul 17, 2014 2:47 pm

Thank you very much Tom.
I asked the question about device configurations (18F452@ 20osc) due to the application problem I am going to face head on. I plan on creating a code that controls 8 servo motors "Radio Controlled Robotics application" My main concern at this stage is the choice of Pulse Width Modulation timer modules 1,2 operation as a baseline measurement.
I was also thinking of using a 555 timer circuit set to 0.1ms discharge and use interrupt change on pin after period expires. Any helpful hints please.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby Tom Maier » Thu Jul 17, 2014 3:37 pm

The 555's may not be needed...

For slower speed timing requirements you can take one timer and make many independant virtual timers (call them "clocks"). The real timer interrupt ticks up (or down, whatever you like) a bunch of independant variables in every interrupt time.

Code: Select all
-------------------------------------------------
my_timer_interrupt()     //  0.1 msec, 400 instruction cycles @ 20 MHz
{
  // tick up all the clocks...
  clock1++;      // tick up clock 1
  clock2++;     // tick up vlock 2
// make more clocks!

  if (clock1 > 85)
  {
      // do some stuff that is not to long,
     // or set a flag for the main code to trigger off
      clock1 = 0;         // reset the clock
  }  // end clock1


  if(clock2 > 1200)
  {

  }

}  // end timer interrupt
---------------------------------------
Last edited by Tom Maier on Thu Jul 17, 2014 3:55 pm, edited 2 times in total.
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Tom Maier » Thu Jul 17, 2014 3:49 pm

By the way, if you are planning something that will require a lot of intense timing requirements, it would be to your advantage to get off that old chip and go to a more advanced version that can run 32 MHz or more. It will give you a shorter instruction cycle and thus more "ticks" and instructions for you timing routines.

And if you plan on doing anything math intensive, get off the pic18 alltogether and move to the pic24 line of chips. The pic18 sucks at math besides just incrementing and decrementing. It is more of a bit-banger chip. The pic24 has true integer math architecture, so multiplys and divides run 30 times faster or more.
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Dimebag » Fri Jul 18, 2014 7:42 am

At this stage I am going to stay with the 18F452 device until I feel comfortable with programming in C.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby Dimebag » Fri Jul 18, 2014 12:08 pm

I can't see how many instruction cycles the device has carried out with this code. I did have breakpoints set on statement. for (f= 4000, f > 0; f--) and at pivit_2();
Complier: mplabx xc8
I need a little help please. I am just a bit lost at the moment with reading Google code sources. I found that a fair amount of code on Google need header files. I would like to write source code that work without making the situation worse.

Code: Select all
void pivit_2(void) {
    PORTB = 0x55;
}

//Statement covering the start up output and input pins of Device.

void main(void) {
    Initialization();

    while (1) { //running code goes inside this loop
        for (f = 4000; f > 0; f--);  //int f = 0;

        pivit_2();
        {
        }


    }
}
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby ric » Fri Jul 18, 2014 12:47 pm

Have you tried single stepping this code in the simulator, or looking at the generated assembly code?
I like to see how my C code is being interpreted. You quickly find things like the loop test "f != 0" is simpler/quicker than "f > 0".
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Dimebag » Fri Jul 18, 2014 1:47 pm

Have you tried single stepping this code in the simulator
Yes
are you talking about the output file format?
project properties/XC8 global options: ELF/DWARF, COFF

I am trying to understand your reply ric. I am not sure what generated assembly code is.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Next

Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 12 guests

cron