Thursday 16 December 2021

Using Config Parts in Microcontroller Centered Projects

 Microcontrollers are generally specialized in a particular function, therefore while they're very variable devices today, you will find numerous different (often conflicting) alternatives for how you might want the electronics to work. You may think that this setup is done in software, but what if you'd like the hardware to do something a certain way from ab muscles start? Remember that Microchip PIC units may "boot" in a matter of milliseconds, there wants to be a way you telling the hardware how exactly to act in advance of it beginning up. This information addresses how to really get your microcontroller based challenge functioning how you expect when it begins up.


Enter config bits, or, while they was once named, config fuses. Back the occasions when microcontrollers were program-once units, you probably did blow a fuse in order to plan them. Today, most micros have thumb storage which can be programmed countless amounts of times, but you will find however one-time-programmable (OTP) products about.


Regardless, there's a bunch of "config words" that establish how the micro is going to act from the get-go. Let's search at some of those alternatives (we'll choose the PIC18F2620 as an example) and then see how to plan them. Sourceboost gives you all the config strings in a ready-to-use structure for including in your project. The format has got the config portions suffixed with exactly the same title because the config term in order to make sure that the right parts are going in the proper word. Obviously, your config phrases will soon be different if you're using a various microcontroller, but you should understand enough here to place you in the proper direction.


In the 18F2620, the config bits are located in display, but at a top storage location. They're located at 0x300001 and upwards. For old reasons due to the way storage once was arranged on PIC microcontrollers, config phrases are numbered with each quantity having a "high" and "low" byte.


CONFIG1L doesn't occur on the 18F2620. When it did, it'd stay at 0x300000 location.


CONFIG1H includes portions that specify oscillator options. Typically, in Stuck Adventures jobs we use and try external deposits which give more correct and reliable results. That does burn up two hooks nevertheless, and sometimes these may become more crucial compared to the rate at that your processor is running. The external crystal oscillator is known as the HS oscillator (if you're performing the normal issue of seeking to run the micro as rapidly since it can go). In the 18F2620, you can also help the PLL element which will give you a four-times rate boost. From openbullet config are also alternatives allow the fail-safe clock monitor (that buttons to the interior oscillator should the external one fail, and an option to enable the switching between various oscillator sources.


We generally suggest that you employ an external crystal, and turn fully off any oscillator changing / failover modes. In prototyping, it is essential to own trusted, repeatable effects (mostly so you can reduce steadily the axes of error). It's probable to configure the 18F2620 to set up utilising the inner oscillator (which operates at 8Mhz, or 32Mhz with the PLL enabled) and then change to the outside one (we work with a 10Mhz crystal with PLL permitted providing you 40Mhz). That gives you quicker start-up from stops in rest mode or on bootup, if that's crucial, except for prototyping, this is typically perhaps not necessary.


Our suggested config line for CONFIG1H:


#pragma DATA _CONFIG1H, _OSC_HSPLL_1H & _IESO_OFF_1H & _FCMEN_OFF_1H


CONFIG2L grips brown-out reset and the energy up timer. Brown Out Reset (or BOR) is the ability for the microcontroller to reset it self if the source voltage comes under a specified threshold. It will stay static in reset state before the source goes back within the threshold. This can mean some battery keeping (at least, once the battery is level beyond a certain level, it'll end draining energy as quickly) - but at that point there's no performance available anyway. The ability on timer waits on initial power-on for the present to go above the BOR voltage tolerance, then hangs around for still another 65ms before stopping things down for real. This can help assure that your power supply is regular before wanting to accomplish any code.


We have observed some fairly unstable results from the 18F2620 when screening some LED show panels. We thought the application was crashing or resetting the micro when actually, the thing that was happening was the BOR was being tripped as more LEDs were illuminated and the ability offer dropped. As a result, until you've got a real dependence on it, we suggest switching it off. Leaving the energy offer to be in before beginning the firmware, is generally a good idea (you're not likely going to notice the 65ms it takes).


#pragma DATA _CONFIG2L, _BOREN_OFF_2L & _BORV_2_2L & _PWRT_ON_2L


CONFIG2H offers you options for the watchdog timer. This is a timer that resets the PIC in a certain amount of time (you can largely specify just how long which may be). It could be excellent plan to reset your PIC if you're performing something from that you simply might never recover - while hopefully you're written good enough rule that this cannot occur! Alternately, the watchdog timer also can take the PIC out of sleep mode. What this means is you are able to prepare for the PIC to get to sleep for a specific amount of time (if nothing otherwise happens). For prototyping, we suggest changing the watchdog timer off. Should you allow it, be sure you reset the watchdog timer frequently or - effectively, you can imagine what'll happen.


#pragma DATA _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H


CONFIG3H has an accumulation arrangement items. You are able to pick for the RE3 pin to be accessible (as insight only) or for that flag to be MCLR (which resets the micro when taken low). For prototyping, to be able to reset the micro by demanding an option is easier than pulling the power out.


The LPT1OSC bit gives the possibility of a "large power" function or a "low power mode" ;.The lower power method is more painful and sensitive in large noise environments. Therefore if battery consumption is essential, you'll need to style your world carefully. For prototyping, obviously, we would suggest causing this in large power mode.


PBABEN, lets you specify if PORTB pins 0 - 4 should awaken as analog feedback hooks or electronic pins upon reset. Needless to say you can change that in pc software in the ADCON1 register at any time.


The CCP component is really a Record / Examine / PWM element and one last CONFIG3H bit enables the "steering" of this result to be on possibly RC1 or RB3. That is convenient to manage to change in the event that you need one other operation available on one of these brilliant pins (RB3 is also analogue feedback 9 and RC1 may be Timer 1 oscillator input). Instead, your PCB layout may be simpler if you may shift this production to 1 or the other. For prototyping, usually that doesn't matter both way.


#pragma DATA _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _MCLRE_ON_3H


CONFIG4L includes some exciting possibilities and shows very obviously how important it's to be able to configure the PIC before startup.


The DEBUG bit enables hardware debugging. You are able to step through code, set breakpoints and etc - if you have your computer software set properly and this touch cleared. Electronics debugging also needs the unique utilization of RB6 and RB7 (also useful for ICSP programming). In most honesty, we find that sequential production is usually sufficient to find bugs, although you are able to debug a lot of PICs with simply a PicKit2.


XINST allows for the 18F extended instruction set mode. This isn't used by Sourceboost and if you change it on by mistake (regardless of the compiler you're using) there will be some quite unstable results. One of our visitors spent times trying to find the thing that was inappropriate along with his rule only to realise the XINST touch was set.


LVP gives you the ability to program the PIC using ICSP without requesting the "higher" Vpp voltage. There is a find however - you need to dedicate the RB5 green (PGM) to becoming an sign if you're in development setting or not. Provided the PicKit2 generates the best voltage anyway, there doesn't seem to be a lot of price in switching that on for prototyping purposes.


Finally, the STVREN offers the choice of experiencing the PIC reset if the heap overflowed or underflowed. If, like, you contact way too many nested operates, it will allow the PIC to reset. Once reset, you are able to examine why the PIC reset and report a fault. We recommend leaving that on - if your PIC shoes in the middle of doing anything, you can fairly think that you've used up the stack space (possible when you're serious in a nested situation and then an stop occurs).

No comments:

Post a Comment

The Untapped Potential of Email Selling in Business sector Outgrowth

 Email marketing has revolutionized business communication and marketing in the digital age. It is a direct form of marketing that uses emai...