1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics Urgent PIC advice required...

Discussion in 'Modding' started by H2O-G33K, 22 Jun 2006.

  1. H2O-G33K

    H2O-G33K What's a Dremel?

    Joined:
    25 Jan 2003
    Posts:
    240
    Likes Received:
    0
    I'm trying to get a load of code working on a PIC18F2550 but I can't even get the simplest thing in the world to work! Here's my source:

    http://www.geekops.co.uk/HyperLight.asm

    ...when I simulate it in MPLAB, it looks like it ought to work - various bits on the three ports should switch on/off. When I program it onto the pic though, I get no evidence that anything is happening at all. I'm able to write / verify the code fine so I don't think the PIC is at fault.

    Any suggestions would be VERY gratefully received!
     
  2. shotgunefx

    shotgunefx What's a Dremel?

    Joined:
    4 Feb 2004
    Posts:
    449
    Likes Received:
    0
    "In theory, theory and practice are the same. In practice, they are not." :)

    I'm not familar with the PIC18s at all, but did you check the simple stuff in the circuit? Voltage, oscillator, etc?
     
  3. ch424

    ch424 Design Warrior

    Joined:
    26 May 2004
    Posts:
    3,112
    Likes Received:
    41
    In the InitChip routine, you need to move into Bank1 before writing to the TRIS registers, then back to Bank0 afterwads. I think there's an instruction to do that on the 18F PICs.

    Why aren't you using C? The compiler is free.

    ch424
     
  4. bubsterboo

    bubsterboo What's a Dremel?

    Joined:
    24 Jan 2006
    Posts:
    800
    Likes Received:
    3
    Whats the best Pic compiler in your opinion? For a pic 18f and 16f
     
  5. ch424

    ch424 Design Warrior

    Joined:
    26 May 2004
    Posts:
    3,112
    Likes Received:
    41
    The Microchip one that's free: MPLAB and C18 compiler

    The free version of C18 works perfectly. As for 16F PICs, just use MPLAB.

    ch424
     
  6. H2O-G33K

    H2O-G33K What's a Dremel?

    Joined:
    25 Jan 2003
    Posts:
    240
    Likes Received:
    0
    I've double checked the input to the chip - it has power and ground in the appropriate places. I'm able to program and verify the data on the chip. I'm using the internal oscillator (or trying to).

    I don't need to switch banks because of the special access function of the 18F chip.

    I'm not using C (yet) because I have some code I wanted to port from a 16F737 and I wanted to start on familiar ground. Since I can't even get a very simple program to give me a sign it's working though, the language I'm using is the last of my worries :(

    This is really frustrating!
     
  7. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    Hi Jon,

    Few things you might want to try. First of all, if you're using the internal oscillator, your OSCCON setting is incorrect, set it to b'01110000'. It looks like you've been a little mislead by the 'System Clock Select Bits'. What it actually means is that if you have both internal and external oscillators, you can switch between the two - but since you are only using the internal oscillator, then you need to set this as the primary oscillator.

    There's also an error in your delay - decf W isn't valid - it should be decf WREG.

    Also if you're using MPLAB, you don't have to specify ACCESS or BANKED for SFRs like TRIS as MPLAB takes care of this for you.

    Finally your config word is wrong for internal oscillator, plus you're using the old convention for declaring the config settings. Also remember to disable low voltage programming!! Try:

    CONFIG FOSC = INTOSCIO_EC, PWRT = OFF, BOREN = OFF, WDT = OFF, MCLRE = ON, LVP = OFF, CPUDIV = OSC2_PLL3

    If I remember correctly, this PIC does not support PLL on the internal oscillator block.

    Regarding C, its really not worth using it on a PIC of this size. I'd suggest it's use on the 16 bit PICs, but because the instruction set is too small to efficiencly compile from C to ASM, it's not worth it on 10/12/16/18 series PIC processors - but people who love C will always try to use it on them...
     
  8. H2O-G33K

    H2O-G33K What's a Dremel?

    Joined:
    25 Jan 2003
    Posts:
    240
    Likes Received:
    0
    Nice one Steve, that's solved a few issues... I'm now running this. It seems to take a loooong time before the thing starts up (up to about 30 seconds!). When it does start up it appears to be running very slowly. I would expect the loop in there to give a delay of ~1/10th of a second but it seems to be running at something closer to 1 second. Is there a divider I've not set somewhere?
     
  9. ch424

    ch424 Design Warrior

    Joined:
    26 May 2004
    Posts:
    3,112
    Likes Received:
    41
    Sorry, I didn't realise that (about changing banks) - all the 18 asm I know is from reading the dissembly listing from the compiler.

    With regards to the slowness, this is the config I'm using on that chip. 4MHz XTAL, but the CPU runs at 48MHz.

    SteveyG, as I'm sure you know, the 18F2550 has USB built in, and only a couple of really experienced programmers have got it's USB working with ASM. They have 1KB of RAM and run at 48MHz. All of Microchip's examples (well, all the fun ones, like USB CDC, USB mass storage and their TCP/IP stack) rely on using C.

    H2O, are you going to be using USB? If so, you'll basically have to use C. If not, why did you go for the 2550 not the 2520? And what did you link to, it sounds exciting?

    ch424
     
  10. H2O-G33K

    H2O-G33K What's a Dremel?

    Joined:
    25 Jan 2003
    Posts:
    240
    Likes Received:
    0
    Ooops, that link should've been this. It's just a slightly modified version of the code I posted before.

    Microchip's demo's are written in C, but I found a rather promising looking article on USB in assembler here.

    I will be using USB eventually, but for the time being I just need to get the code I had running on my other PIC on this one. I'm supposed to be heading of to a festival later today and I want to take my new toys with me. No point in bringing them if they don't work though :(

    Thanks guys,
    Jon
     
  11. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    I'm not sure about the start up issue, I'll have to look into that one. How do you have MCLR connected?

    The link doesn't seem to work in your post.
     
  12. H2O-G33K

    H2O-G33K What's a Dremel?

    Joined:
    25 Jan 2003
    Posts:
    240
    Likes Received:
    0
    Ah HA! Nice one Steve - the connection that was pulling the MCLR pin high had come loose :)
     
  13. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    :) Is it all working now then?
     
  14. H2O-G33K

    H2O-G33K What's a Dremel?

    Joined:
    25 Jan 2003
    Posts:
    240
    Likes Received:
    0
    Sort of... well, possibly.... the PIC starts up okay but seems to stop after a bit. Need to double check what the program should actually be doing. Time for some more investigation!

    [Edit] Problem solved - i had a couple of things tied to ground which should've been tied to Vin which was causing a few problems. All working well now :D[/Edit]
     
    Last edited: 26 Jun 2006

Share This Page