1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Using PWM on a 18F13K22

Discussion in 'Microcontrollers' started by MrDEB, Nov 27, 2013.

  1. Little Ghostman

    Little Ghostman Well-Known Member Most Helpful Member

    Joined:
    Jan 7, 2011
    Messages:
    3,702
    Likes:
    426
    Location:
    SCOTLAND
    for that chip there are a fair few fuses to set,have a look in the header file or the mplab config help file

    also what is your exact setup? as in PC? or Laptop? if laptop is the laptop plugged in or on battery?
    is the usb hub powered?
    was/is anything else plugged into the usb hub when you tried this? the voltage seems low to me, also obvious but you never know. Make sure you have the junebug on a non conductive surface! i had it on the carpet once and it kept telling me it had a short!
     
  2. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    It's been awhile but I am using a pickit2. Eliminated several issues. I built a new board, used ohm meter as always before inserting pic. Measured voltage at the IC socket before inserting pic as well. Tested the pickit2 output as well using the brief instructions when using TOOLS / TROUBLESHOOTING and tested Vdd , mclr Vpp etc. Pickit2 works.
    Inserted original pic and still low Vpp. Inserted new pic and all is well with Vpp etc. Now I am just trying to blink an LED to verify the pic and oscillator are working. I am presently trying to interpret the data sheet and make changes to the INCLUDE file I have named oscKseries. The basis was obtained from another similar code and I am adjusting for what I am doing But still need adjustments. Am surprised there is no module that I have found that is for the K series of pics.
     
  3. Little Ghostman

    Little Ghostman Well-Known Member Most Helpful Member

    Joined:
    Jan 7, 2011
    Messages:
    3,702
    Likes:
    426
    Location:
    SCOTLAND
    in mplab folder there is a 18f pic config file that list's all config settings for just about all the 18f pic's (it has yours i checked, open another module of a similar chip, rename it and then just fill in ALL the k22 stuff! miss nothing out because the K series bite if you get it wrong, i have used them alot and they are great but dont forgive mistakes, you spend 60% project time just getting them to work, i see themas alot more complicated than standard 18f chips, but thats because they are packed full of goodies! they are not hard to use if you are very rigid and make sure you doing everything by the book and no sloppy set up, i am betting your other pic has the MCLR set wrong ;) sounds daft but also check you have the power pins round right way because from memory some the K series are different way round.
    But most of all SET each and every fuse because there are alot and not all power up as you think. pay particular attention to ALL OSC settings for that chip
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22

    I will check the MPLAB files THANKS
    maybe by accident I can get this candle project up and maybe running along with all my other projects.
     
  6. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    Having very little or really any experience with MPLAB . I found the 18F13K22 file but am I to assume there is a file that shows the CONFIG settings for this PIC? and if so ??
    I found a listing of settings but it is not a header file or actual settings. I perhaps am misinterperting wrong. Won't be the first time and won't be the last.
    Going to pour over the data sheet and try to set all the fuses hopefully.
     
  7. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    Hopeful fuses are the best kind.
     
  8. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I think I found the listing of all the config settings for this pic in MPLAB.
    now to use the different settings etc. Brief example of what I located
    Code (text):

    ;  Oscillator Selection bits:
    ;    FOSC = LP            LP oscillator
    ;    FOSC = XT            XT oscillator
    ;    FOSC = HS            HS oscillator
    ;    FOSC = ERCCLKOUT    External RC oscillator, CLKOUT function on OSC2
    ;    FOSC = ECCLKOUTH    EC, CLKOUT function on OSC2 (high)
    ;    FOSC = ECH          EC (high)




     
     
  9. Little Ghostman

    Little Ghostman Well-Known Member Most Helpful Member

    Joined:
    Jan 7, 2011
    Messages:
    3,702
    Likes:
    426
    Location:
    SCOTLAND
    try this

    but before you open it you have to rename it keep the main name but change the last bit from .txt to .chm
    its a help file with all settings for 18f chips but you cant upload those files here so i changed the .chm to .txt just change it back and it will open
     

    Attached Files:

  10. Little Ghostman

    Little Ghostman Well-Known Member Most Helpful Member

    Joined:
    Jan 7, 2011
    Messages:
    3,702
    Likes:
    426
    Location:
    SCOTLAND
    no such thing as an accident and with these chips you wont get anything by accident, you are going to have to take it step by step without jumping all over the place. People think i was being harsh when i outlined doing the project the way i do, but to be fair had you done as i suggested right at the start then you would have had one kick arse candle by now. ok we all have our own ways of learning and working but some stuff dosnt have short cuts, like electronics and pics, cutting corners makes the journey bumpy and longer, and know i am not having a go just pointing out you could save yourself alot of hassle.
    that file i posted has saved me many times
     
    • Like Like x 1
  11. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    Absolutely true! You laid out an excellent methodology to tackle a project.
     
  12. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    Setting up the internal oscillator isn't rocket science and does not require a Swordfish module. The Swordfish module is a convenience to handle the setup for many PICs; since the part you want to use isn't included, just set it directly.

    First set the OSCCN register:
    OSCCON = %01100011

    This sets the oscillator to 8 MHz and selects the internal oscillator.

    image.jpg

    Next, the OSCTUNE register must be set:

    OSCTUNE = %00000000

    This turns off the PLL multiplier.

    image.jpg

    So the FIRST four lines of your code will be:

    Device = 18F13K22

    Clock = 8

    OSCCON = %01100011

    OSCTUNE = %00000000

    Note: these must be typed exactly as shown including the percent sign (which indicates a binary number). There are a total of exactly eight numbers in each of these statements.
     
  13. Little Ghostman

    Little Ghostman Well-Known Member Most Helpful Member

    Joined:
    Jan 7, 2011
    Messages:
    3,702
    Likes:
    426
    Location:
    SCOTLAND
    sorry jonsea i suggested doing the module as i dont use swordfish i didnt know you could set it like that, i am used to C, a
    also make sure you set the primary oscillator on etc :D
     
  14. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    No problem. Modifying the Swordfish module would make it easy to change to different micros, but MrDEB's track record makes the direct approach safer.

    The nice thing about Swordfish modules is that they're written in Swordfish, so they can be easily changed.
     
  15. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    What isn't clear is whether you calibrated the PICkit 2 Vdd from the main level of the tools menu. This is quite apart from testing Vdd under the tools/troubleshooting menu. Why? Because all of the measurements under the troubleshooting menu are based on the PICkit 2 being calibrated. Everything in that section is referenced to Vdd and the value set in the calibration step. If you bypassed this step, everything measured under the troubleshooting menu is bogus.

    I explained this in MSG #53, but who's counting?
     
  16. Little Ghostman

    Little Ghostman Well-Known Member Most Helpful Member

    Joined:
    Jan 7, 2011
    Messages:
    3,702
    Likes:
    426
    Location:
    SCOTLAND
    i now have some 18f13k22 chips i tried one quickly earlier but it played up with the PK2 but was ok on PK3??? and icd3. but it is supposed to be ok with PK2. having used alot of the K series pics i have to admit they can play up if you are not spot on with them, they seem far more intolerant of the casual approach than my other favorite pic 18f4685.
    i think for this project i would have been tempted to use one pic and shift registers but the code would have been alot harder. after monday (sorting my other projects until then) i am going to have a go at a candle, i have an idea i want to try out that hopefully should make a really good candle
     
  17. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    I've used the 18F14K40 and the 18F25K20 & K22 without much trouble, other than some of the periferels are rearranged.
     
  18. Little Ghostman

    Little Ghostman Well-Known Member Most Helpful Member

    Joined:
    Jan 7, 2011
    Messages:
    3,702
    Likes:
    426
    Location:
    SCOTLAND
    the worse one i have used was 18f45k22 it was really fussy about everything!! i had to make sure the power supply was really well decoupled. maybe just a one off chip, but out of all the 18f's i have used the K lot were by far the ones i had to pay most attention to detail! probably because they have so many fuse settings!
    i am also using a 30F4013 and that hardly has any fuses! at least he isnt using a chip with pps :facepalm::facepalm::facepalm:
     
  19. MrDEB

    MrDEB Active Member

    Joined:
    Apr 16, 2007
    Messages:
    4,364
    Likes:
    22
    I have my white flag ready as I just can't get this pic to work.
    I checked the pickit2 calibration etc. but still no led blink to indicate a working pic. The code should work but going to try it out on the 18f2420 setup. This will tell me IF there is something wrong with my code hopefully. I tried setting the OSCCON etc as per Jons suggestion (I had my module set with same values ).
    Maybe LittleGhost can get his 18F12K22 working. I looked over the data sheet, the Swordfish Forum, DDIY, Electrotech etc. Not very many people are using this chip. maybe because of the difficulty of getting it to work??
     
  20. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,793
    Likes:
    134
    Location:
    morristown,tn
    Post the code your really using there no way to help you without it.
    Swordfish doesn't like osccon setting in the main code I've had the osc not start up to full speed hours after the chip is powered on.
     
    • Like Like x 1
  21. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,118
    Likes:
    90
    Location:
    Seattle, WA
    Sigh. MrDEB, I truly wish you could post a message with pertinent details that can be comprehended by mere mortals such as myself.

    In the paragraph above, you talk about PICkit calibration, internal oscillator settings and etc and say "it doesn't work." From that statement, nobody can know what "it" is.

    Questions. A clear, concise answer is required to each before I will do anything further to help you.

    1. Did you run the Vdd calibration procedure under the PICkit 2 GUI?

    2. When you attempt to write to the 18F13k22 chip, does it complete satisfactorily or is there an error message displayed? If so, post screen captures of the PICkit 2 GUI and of the error message.

    3. Did you verify the code was written correctly to the 18F13K22? It's an option under the PICkit 2 GUI.

    4. If and only if the code was written into the 18F13K22, how do you know it's not working? Simplest possible program. Post code and schematic diagrams in a clear readable format. I'm not going to guess at what you're doing or assume you have correct connections. Sorry, past performance suggests to do so is foolish.

    5. If the internal oscillator code isn't working (post your actual code), and the chip is actually being programmed (verified in the PICkit 2 GUI), try it with a crystal and 22 pF caps.

    Sorry to be blunt, but if you want help, you need to post all of the details clearly and concisely with appropriate documentation posted. Many of us have been burned in the past by making assumptions about what you are asking, or assuming schematics actually show what you have connected.

    I do not believe the 18F13K22 chip should be any more difficult than any other 18F chip to use, but as always, attention to detail and the data sheet will be required.
     

Share This Page