Microcontrollers tend to be dedicated to a certain purpose, so while they're very variable products today, you can find a number of different (often conflicting) options for how you could want the hardware to work. You may think that arrangement is performed in computer software, but what if you'd like the equipment to act a specific way from the start? Remember that Microchip PIC products can "boot" in a subject of milliseconds, there needs to be a way you telling the hardware how to behave in advance of it beginning up. This article covers how to get your microcontroller centered project functioning the way you assume when it begins up.
Enter config parts, or, as they was once named, openbullet configs. In the occasions when microcontrollers were program-once products, you actually did hit a fuse in order to plan them. Nowadays, many micros have display storage that can be developed tens of thousands of occasions, but you can find however one-time-programmable (OTP) units about.
Regardless, there's a bunch of "config words" that determine the way the micro will act from the get-go. Let's look at some of those alternatives (we'll choose the PIC18F2620 as an example) and then see how to program them. Sourceboost gives you most of the config strings in a ready-to-use format for including in your project. The structure has got the config pieces suffixed with exactly the same name because the config word so you can make certain that the proper pieces are going in the proper word. Of course, your config phrases will undoubtedly be different if you're utilizing a different microcontroller, but you should learn enough here to stage you in the proper direction.
In the 18F2620, the config parts are kept in flash, but at a high storage location. They're stored at 0x300001 and upwards. For historic causes because of the way memory was once established on PIC microcontrollers, config words are numbered with each quantity having a "high" and "low" byte.
CONFIG1L doesn't exist on the 18F2620. If it did, it would stay at 0x300000 location.
CONFIG1H includes parts that specify oscillator options. Usually, in Embedded Ventures jobs we try and use additional deposits which provide more accurate and reliable results. This does consume two hooks however, and often these may become more essential compared to the speed at which the chip is running. The outside crystal oscillator is referred to as the HS oscillator (if you're doing the typical point of seeking to run the micro as quickly as it will go). In the 18F2620, you can also allow the PLL component which will provide you with a four-times speed boost. From CONFIG1H may also be options to enable the fail-safe clock monitor (that turns to the internal oscillator if the outside one fail, and an option to enable the switching between various oscillator sources.
We usually suggest that you utilize an additional gem, and turn off any oscillator converting / failover modes. In prototyping, it is very important to own trusted, repeatable benefits (mostly in order to reduce the axes of error). It is probable to manage the 18F2620 to launch utilizing the internal oscillator (which works at 8Mhz, or 32Mhz with the PLL enabled) and then switch to the additional one (we use a 10Mhz gem with PLL allowed providing you 40Mhz). That gives you faster start-up from stops in rest setting or on bootup, if that's essential, however for prototyping, that is usually maybe not necessary.
Our proposed config chain for CONFIG1H:
#pragma DATA _CONFIG1H, _OSC_HSPLL_1H & _IESO_OFF_1H & _FCMEN_OFF_1H
CONFIG2L grips brown-out reset and the power up timer. Brown Out Reset (or BOR) is the power for the microcontroller to reset itself if the supply voltage falls under a specified threshold. It will stay in reset state before source dates back within the threshold. This could mean some battery keeping (at least, when the battery is level beyond a particular stage, it'll stop draining power as quickly) - but when this occurs there's no efficiency accessible anyway. The power on timer waits on original power-on for the source to get over the BOR voltage threshold, then hangs around for still another 65ms before kicking things down for real. This assists ensure your power is regular before attempting to perform any code.
We have seen some very unstable results from the 18F2620 when screening some LED show panels. We believed the program was crashing or resetting the micro when actually, the thing that was occurring was the BOR was being tripped as more LEDs were lit and the ability offer dropped. Therefore, unless you've got an actual need for it, we suggest changing it off. Causing the energy supply to be in prior to starting the firmware, is typically a good idea (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 controls for the watchdog timer. This is a timer that resets the PIC in a specific amount of time (you can largely specify just how long which may be). It may be excellent plan to reset your PIC if you're doing anything from that you may never retrieve - even though ideally you're written sufficient code this can not occur! Alternatively, the watchdog timer may also move the PIC out of sleep mode. This implies you are able to prepare for the PIC to get to sleep for a certain amount of time (if nothing otherwise happens). For prototyping, we suggest converting the watchdog timer off. If you do allow it, ensure you reset the watchdog timer regularly or - effectively, you can imagine what will happen.
#pragma DATA _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
CONFIG3H has an accumulation configuration items. You are able to pick for the RE3 flag to be available (as input only) or for that flag to be MCLR (which resets the micro when drawn low). For prototyping, being able to reset the micro by demanding an option is easier than pulling the power out.
The LPT1OSC bit allows the possibility of a "high power" function or a "low power mode" ;.The lower power function is more sensitive and painful in high noise environments. So if battery consumption is very important, you will need to style your world carefully. For prototyping, obviously, we'd recommend leaving that in large power mode.
PBABEN, allows you to specify if PORTB hooks 0 - 4 should get up as analog insight pins or electronic hooks upon reset. Needless to say you are able to change that in computer software in the ADCON1 enroll at any time.
The CCP element is just a Record / Compare / PWM element and your final CONFIG3H bit allows the "steering" of the production to be on often RC1 or RB3. This is handy to manage to modify if you need the other operation available on one of these simple pins (RB3 can also be analogue feedback 9 and RC1 could be Timer 1 oscillator input). As an alternative, your PCB format might be easier if you could move that productivity to one or the other. For prototyping, usually that doesn't subject possibly way.
#pragma DATA _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _MCLRE_ON_3H
CONFIG4L includes some fascinating possibilities and reveals really clearly how crucial it is to manage to change the PIC before startup.
The DEBUG bit allows hardware debugging. You are able to stage through rule, collection breakpoints and etc - if you have your pc software set properly and that bit cleared. Electronics debugging also involves the exceptional usage of RB6 and RB7 (also used for ICSP programming). In most credibility, we find that sequential output is typically adequate to locate bugs, even though you are able to debug lots of PICs with only a PicKit2.
XINST enables the 18F prolonged instruction set mode. This isn't used by Sourceboost and if you change it on by mistake (regardless of the compiler you're using) you will see some quite unstable results. Among our readers spent times searching for what was incorrect with his rule and then realise the XINST touch was set.
LVP gives you the capacity to plan the PIC applying ICSP without requesting the "higher" Vpp voltage. There is a find but - you'll need to devote the RB5 flag (PGM) to becoming an sign if you're in programming method or not. Given the PicKit2 generates the best voltage anyway, there doesn't appear to be a lot of value in changing this on for prototyping purposes.
Eventually, the STVREN gives the possibility of having the PIC reset if the bunch overflowed or underflowed. If, as an example, you contact a lot of stacked operates, it would allow the PIC to reset. Once reset, you can study why the PIC reset and record a fault. We suggest causing that on - if your PIC boots in the midst of doing anything, you are able to fairly think that you've utilized the collection place (possible when you're serious in a nested situation and then an stop occurs).
No comments:
Post a Comment