Microcontrollers are generally focused on a particular function, therefore while they're really variable units today, you can find numerous various (often conflicting) alternatives for how you could need the hardware to work. You might think that configuration is performed in computer software, but what if you want the hardware to do something a certain way from the very begin? Remember that Microchip PIC units may "boot" in a matter of milliseconds, there needs to be a way you telling the hardware how to behave prior to it beginning up. This informative article addresses how to truly get your microcontroller centered project functioning the way you expect when it starts up.
Enter config portions, or, while they used to be called, config fuses. Back the times when microcontrollers were program-once products, you actually did hit a blend in order to plan them. Nowadays, many micros have flash storage which can be designed thousands of situations, but you will find still one-time-programmable (OTP) devices about. Regardless, there's a number of "config words" that define how the micro is going to act from the get-go. Let's search at some of those possibilities (we'll select the PIC18F2620 as an example) and then see how to plan them. Sourceboost gives you all of the config strings in a ready-to-use format for including in your project. The structure has got the config portions suffixed with exactly the same name whilst the config word to help you ensure that the right bits are going in the best word. Obviously, your config phrases will be various if you're employing a different microcontroller, but you need to understand enough here to position you in the best direction. In the 18F2620, the config pieces are located in thumb, but at a higher memory location. They're located at 0x300001 and upwards. For traditional reasons as a result of way memory once was arranged on PIC microcontrollers, config words are numbered with each number having a "high" and "low" byte. CONFIG1L doesn't occur on the 18F2620. If it did, it would live at 0x300000 location. CONFIG1H contains pieces that establish oscillator options. Typically, in Embedded Adventures projects we try and use outside crystals which provide more correct and trusted results. That does use up two pins but, and often these can become more important compared to rate at that your chip is running. The additional crystal oscillator is known as the HS oscillator (if you're doing the conventional point of trying to perform the micro as quickly since it may go). In the 18F2620, you can even help the PLL module which will give you a four-times pace boost. From openbullet config are also choices allow the fail-safe clock check (that turns to the inner oscillator should the external one crash, and an alternative to enable the changing between various oscillator sources. We generally suggest that you utilize an additional crystal, and turn off any oscillator switching / failover modes. In prototyping, it is important to own reliable, repeatable benefits (mostly so you can decrease the axes of error). It is possible to manage the 18F2620 to launch using the inner oscillator (which works at 8Mhz, or 32Mhz with the PLL enabled) and then switch to the outside one (we make use of a 10Mhz crystal with PLL permitted giving you 40Mhz). That provides you quicker start-up from interrupts in rest mode or on bootup, if that's important, except for prototyping, that is usually not necessary. Our proposed config line for CONFIG1H: #pragma DATA _CONFIG1H, _OSC_HSPLL_1H & _IESO_OFF_1H & _FCMEN_OFF_1H CONFIG2L grips brown-out reset and the ability up timer. Brown Out Reset (or BOR) is the ability for the microcontroller to reset it self if the supply voltage falls below a specified threshold. It will remain in reset state until the source goes back over the threshold. This can suggest some battery keeping (at least, when the battery is flat beyond a particular stage, it'll stop wearing energy as quickly) - but at that time there's no efficiency accessible anyway. The ability on timer waits on preliminary power-on for the source to move above the BOR voltage tolerance, then hangs about for another 65ms before throwing things down for real. It will help guarantee your power is steady before attempting to implement any code. We have seen some pretty unstable benefits from the 18F2620 when screening some LED screen panels. We believed the program was piling or resetting the micro when in fact, what was happening was the BOR was being tripped as more LEDs were lit and the ability supply dropped. As such, unless you've got a real dependence on it, we suggest changing it off. Making the ability offer to be in before beginning the firmware, is usually advisable (you're most likely not planning to notice the 65ms it takes). #pragma DATA _CONFIG2L, _BOREN_OFF_2L & _BORV_2_2L & _PWRT_ON_2L CONFIG2H gives you adjustments for the watchdog timer. This is a timer that resets the PIC in a quantity of time (you may largely specify just how long that may be). It might be excellent intend to reset your PIC if you're doing something from that you simply might never retrieve - although hopefully you're prepared sufficient code that this cannot happen! Alternately, the watchdog timer can also pull the PIC out of sleep mode. What this means is you are able to organize for the PIC to get to sleep for a specific amount of time (if nothing otherwise happens). For prototyping, we recommend switching the watchdog timer off. If you do enable it, make sure you reset the watchdog timer regularly or - properly, you can think what'll happen. #pragma DATA _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H CONFIG3H has an accumulation configuration items. You are able to choose for the RE3 pin to be around (as insight only) and for that pin to be MCLR (which resets the micro when drawn low). For prototyping, to be able to reset the micro by pushing a switch now is easier than dragging the ability out. The LPT1OSC bit provides the choice of a "large power" setting or perhaps a "minimal energy mode" ;.The lower energy mode is more sensitive in large noise environments. Therefore if battery usage is vital, you need to style your signal carefully. For prototyping, obviously, we'd suggest making that in large energy mode. PBABEN, allows you to specify if PORTB pins 0 - 4 should awaken as analog input pins or electronic pins upon reset. Obviously you are able to change that in pc software in the ADCON1 register at any time. The CCP module is a Catch / Evaluate / PWM module and your final CONFIG3H touch enables the "steering" of this result to be on either RC1 or RB3. This is handy to manage to modify in the event that you require the other performance available on one of these pins (RB3 is also analogue input 9 and RC1 may be Timer 1 oscillator input). Alternately, your PCB format could be easier if you may shift that output to at least one or the other. For prototyping, usually this doesn't matter both way. #pragma DATA _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _MCLRE_ON_3H CONFIG4L includes some interesting alternatives and shows very obviously how essential it is to be able to arrange the PIC before startup. The DEBUG touch allows electronics debugging. You are able to step through signal, collection breakpoints and etc - when you yourself have your application set appropriately and that touch cleared. Electronics debugging also involves the unique utilization of RB6 and RB7 (also useful for ICSP programming). In most credibility, we realize that serial output is typically adequate to get bugs, although you can debug plenty of PICs with merely a PicKit2. XINST provides for the 18F lengthy training set mode. That isn't employed by Sourceboost and in the event that you move it on by mistake (regardless of the compiler you're using) you will have some fairly unstable results. One of our viewers spent times looking for what was improper with his signal and then realize the XINST bit was set. LVP gives you the capacity to program the PIC using ICSP without requesting the "higher" Vpp voltage. There is a catch however - you will need to devote the RB5 green (PGM) to being an sign if you should be in programming setting or not. Provided the PicKit2 produces the best voltage anyway, there doesn't seem to be plenty of value in switching that on for prototyping purposes. Ultimately, the STVREN offers the option of having the PIC reset if the collection overflowed or underflowed. If, as an example, you call way too many nested functions, it would allow the PIC to reset. Once reset, you are able to study why the PIC reset and record a fault. We recommend making this on - if your PIC shoes in the midst of performing anything, you can reasonably assume that you've consumed the stack space (possible when you're heavy in a nested condition and then an stop occurs).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
February 2020
Categories |