From PIC16F690 to PIC18F26K20 + The big function!

Discussion in 'Embedded Systems and Microcontrollers' started by Eric007, Jan 13, 2012.

  1. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Hi Guyz,

    Most of you guyz know I been using PIC16F690 since i started playing with Pics uC but now I'm shifting to PIC18F26K20 (16MIPS, 3.8Kb RAM,...)

    Attached is my usual template that i been using...
    Now i want to know about the major changes I'll have to make about this template!?

    Have a look especially at the 'variable definition section', the 'interrupt processing section', the 'config fuse section', and 'header file section'...the rest is easy to change!

    In the meantime I'm quickly scrolling through the datasheet to get familiar with this PiC18F...(you can also tell me where i need to put emphasis on...)

    Also where (provide links) can I order a 64Mhx Crystal for this PIC18F26K20

    Will talk about the big function is next post!!

    regards, Eric
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Have a look in the "c:/Program Files/Microchip/MPASM Suite/Template/Code" folder on your computer, you should find a template there.
     
    Eric007 likes this.
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005

    It might help if you mentioned what you are trying to do. :confused:


    Why punish yourself with assembler? The 18F is optimized for C. You should take advantage of that fact.
     
  4. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    you might be right by saying that i'm punishing myself with assembler BUT i'm feeling much confortable with assembler than C!

    I don't really like C but I'll make an effort tho...

    SEEMS LIKE NONE OF YOU HAVE VIEWED MY TEMPLATE

    thx!
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    Why do you assume that?


    Maybe the count on views is not working correctly.
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I had a look at it before my last post, I guess the counter is broke.

    Also, you want a 16MHz crystal and use the 4xPLL to make the internal clock 64MHz, or just use 16MHz internal oscillator and 4xPLL if accuracy isn't too important.
     
  7. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Guess you are right!!! it still displaying 0 views!

    Will talk about my big fuction in a few hours...Late here!!

    the datasheet is a bit scary...lol...lots of banks:eek:...
     
  8. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    That is where the 18F and C shine. No need to worry about banks unless you need to larger chunks of memory and even then all you need to do is define your custom bank in the linker file.
     
  9. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33

    OhK!!! Actually i want to run my function very fast (16Mhz), or more if possible, so i thought i had to buy a 64Mhz crystal and as Pic divides its frequency by 4, i would get 16Mhz...

    But there's another way as you suggested...will have a look at datasheet...

    So you meant, if i got you right, i should just get a 16Mhz Crystal and use the 4xPLL, right?

    Thx!
     
  10. stahta01

    Member

    Jun 9, 2011
    133
    21
    I do not care for the formatting of the template.
    The mixing of tab and spaces is one thing I dislike about the PIC Asm. examples given by Microchip. Your template only looks formatted correctly when I set tabs at 8 spaces.

    I try to use only lower case keywords; you used mixed case for these "Cblock" and "Org". Most or maybe all times it works both ways. But, I am used to C where it fails all the time if lower case is not used.

    Tim S.
     
  11. hexreader

    Active Member

    Apr 16, 2011
    250
    82
    Maximum Crystal frequency is 25MHz for this PIC, and don't forget the you need two capacitors to go with it.

    External 64MHz Crystal Oscillator module might be an option, assuming such a thing exists.

    Also be aware that only the "industrial" version of your PIC runs at 64MHz. If you happen to have the "extended" version of the PIC, then you are limited to 48MHz if you want to stay within spec.

    I agree with the other posters. If it were me, I would choose 16MHz crystal (+ capacitors) and use PLL to multiply this by 4
     
    Eric007 likes this.
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Eric007 likes this.
  13. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    What do you need the maximum speed for anyway?

    I've found that many running at max clock cycle tend to also use a lot of delays, which knocks the speed back down.

    Dual Level interrupts are the best feature in the PIC18 series (well, that or USB), but speed wise, Interrupts + timers save a ton of code and execution time. However, if they aren't used optimally, they can be their greatest weakness, and people will swear dual level interrupts suck because their interrupt was interrupted.

    I'd suggest trying C out, BoostC by sourceboost is free with all optimizations (2kB code limit, only $50 for unlimited code size, not the insane $1,500 some vendors want), try making a medium complexity program in assembly, and the same in C, then compare code size and execution cycles. Until you are very good at assembly, a compiler usually makes better code than raw assembly. Once you know assembly fairly well, build the framework in C, and optimize the produced assembly you don't like or can improve via inline assembly, or a separate .asm function to finish the build.
     
  14. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    If it will help, I attached an 18F assembly language example...
     
    Last edited: Jan 14, 2012
  15. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Beautiful. I love the extensive comments, and minimum delays in getting stuff done.
     
  16. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    On to yours..

    I do like the reminder where you note which pins will be called by which name. The mixing of upper and lower case, as stated earlier, is a bit unconventional for assembly.

    You do great with the comments, describing what each line does.

    However:

    Your lines vary between 69 and 90 columns, which will wrap on the "standard" 80 column display.

    You should have at least 16F690 for the target if this is a 16F690 template, and the filename should be something like 16F690-template.asm which you can save as another name once it's a new project.

    Work on your alignment to make the code a lot easier to read. You have mixed tabs and spaces on almost every line. What you can do to fix this is convert all tabs to spaces, then convert all spaces back to tabs, and re-align the parts that aren't aligned. I prefer to use all spaces as tabs myself, since different people have their tab settings set between 2 and 8, you have no idea how it will look on their screen.

    Comment functional lines more.

    One thing that jumped out at me is this:
    Code ( (Unknown Language)):
    1.  
    2. ;****************************************************************************************
    3. ;    Interrupt Service Routine
    4. ;****************************************************************************************
    5.  
    6.     ;Timer 0 Interrupt -- Occurs once every X ms
    7.  
    8.     ; --- other isr here ---
    9.  
    10.     goto    isr_end
    11.  
    You don't clear the interrupt and timer flags before exiting the interrupt, only the context. I know it's a small thing, but if it's your template, the timer should be ready to add code to and you are done, or you shouldn't set up a code block for the timer at all. You shouldn't have to debug your template.

    Overall, it's workable, but the few things I mentioned above will make it look a lot more readable, and if looking for a job, the code will look far more professional.

    I'm not trying to bring you down, this is all constructive criticism from having to work on code from other people, and the mixed tab/space thing drives me nuts, to the point I have a macro that converts all tabs to spaces from the get go.
     
  17. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    you will find out when i talk about my 'big function'

    Nice!

    Hope there's a way of preventing other interrups to be interrupted...

    That is why i don't want to shift to C now...I first want to be VERY competent in assembly before having a look at what C offers...
     
  18. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Like thatoneguy said, it just beautiful!! what else should i add?:D

    And i REALLY like the way you created own intruction in the 'define' section!!

    This has really helped...

    Thanks a lot Mike!
     
  19. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Thanks!

    Ohk! I will fix that...

    I always comment each line of code but as this is a template maybe that is why you have that impression...

    please repost my template edited with all comments!

    I'm a bit surprised with this...coz i always clear the flag first then go to the isr. So if got you well, you saying I should clear the flag right before exiting the isr?

    yes it's my template! you are right! I debugged my template before posting...generally I only edit an existing code block for the new application I NEVER write from scratch...

    I'm Not down at all but on the contrary I smile while reading your comments and they all make sense plus I'm trying to improve myself...

    Now, can you repost my template with correct spacings and all the above so i can see...it will help more

    Thanks so much!!!
     
  20. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    I will talk about my big function as soon as i can...as i'm doing a quick reading on the datasheet to get familiar with this Pic!

    One more thing, the package type (SPDIP) of the PIC chip is the one that sits well on breadboard, right!?

    regards, Eric!
     
Loading...