Problems with LED flashing, chaser, motor driver, basically anything I do.

Discussion in 'Embedded Systems and Microcontrollers' started by Artikbot, May 30, 2012.

  1. Artikbot

    Thread Starter Member

    Nov 7, 2010
    45
    1
    Hello,

    I've been trying to get into the microcontroller world for some time now, but every time I make a new attempt, I miserably fail and quit for a month.

    I'm currently on my fifth attempt, and probably well over my 100 hours of reading, coding, programming, re-checking code, re-checking circuitry, programming again,... But my circuits keep failing to work.

    I'm trying to do the simple LED blinker, as sad as it sounds.

    I run a 18F4220, programmed with a Kits R Us K150 programmer (I bought it built to ensure working condition).

    The code is as follows. Ports in side B declared as all outputs, then a loop that turns them off, waits, turns them on, waits, and repeats itself. Clock set by INTOSCIO2, and set at 8MHz internal frequency.

    Code ( (Unknown Language)):
    1. #include <p18f4220.h>
    2.  
    3. #pragma config OSC = INTIO2
    4. #pragma config FSCM = OFF
    5. #pragma config WDT = OFF,DEBUG = OFF
    6.  
    7. void delay (void)
    8. {
    9. int i;
    10. for (i = 0; i < 10000; i++);
    11. }
    12. void main(void)
    13. {
    14. OSCCON = 0x72;
    15.  
    16. TRISB = 0;
    17. while(1)
    18.     {
    19.     PORTB = 0;
    20.     delay();
    21.     PORTB = 0x5A;
    22.     delay();
    23.     }
    24. }
    But instead of blinking, I get absolutely no activity.

    The layout is pretty easy. Power from VDD pin, ground from VSS. From any of the side B pins to a resistor, then to a LED, to ground.

    Power is fed via a 5V 1A LM7805 regulator-based PSU.


    I think it has to do with fuses not being properly programmed, or whatnot. Because the code cannot be simpler...


    Any help will be widely appreciated :)
     
    Last edited: May 30, 2012
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    What compiler do you use?
     
    Artikbot likes this.
  3. Artikbot

    Thread Starter Member

    Nov 7, 2010
    45
    1
    First of all, thanks for reading :)

    I use Microchip's own C18. I code on MPLAB 8.76, as MPLAB X seems to bug out in my system.

    To burn the PIC I use Kits R Us' own MicroBrn, with the .hex files that come out of MPLAB needing to be fixed using their tool, FixHex (not entirely sure why, but if I don't do this the burner throws an error).
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    First then it comes to #pragma settings. As you are a beginner. Try to set the config bits in MPLAB it is in the toolbar under configure. Go thourgh all the bits. Also remember to disable the MCLR function. Then download this document. I know you do not use the same chip. But it can be useful as a primer
    http://ww1.microchip.com/downloads/en/DeviceDoc/41370C.pdf
     
    Artikbot likes this.
  5. nerdegutta

    Moderator

    Dec 15, 2009
    2,514
    784
    Shouldn't one more pin be connected to POS via a resistor? MCLR or something. I don't remember and I could be way off....
     
    Artikbot likes this.
  6. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    Which pin of PORTB are you using to connect to the LED?
    Why are you setting PORTB = 0x5A; ?
    Use PORTB = 0xFF;
     
    Artikbot likes this.
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Good point. I think ALL VDD, VSS pins need to be connected
     
    Artikbot likes this.
  8. Artikbot

    Thread Starter Member

    Nov 7, 2010
    45
    1
    Okay, I discovered that I can manually program the fuses in the burner. Apparently they are set properly now.

    After doing this, I completely removed the delay routines in the code, and it turns on now, making me thing that the issue is the delay routine.

    @nerdegutta: No idea... But why is it running now? o.o

    @MrChips: I read it somewhere in the internet, in some of the thousand tutorials I've gone throug :p. I used to use a binary bit only for this matter until I read that 0x5A thing... I'll use your suggestion instead :)

    @t06afre: Thanks for the heads-up, I'll pop cables to every Vdd and Vss pin :)


    I'm writing a blinker using the delay.h as we speak. Reporting back soon!

    Thanks a lot guys, you help is priceless :)


    Edit: EPIC. I have a blinking led in front of me, a TRUCKLOAD of thanks to you guys, words cannot describe the happiness that fills me right now :)

    Edit2: Implemented a table (or a vector, for this purpose) and an incremental variable to make a chaser, which happens to work :)

    This weekend I'll experiment with the PWM controllers and try to build a DC motor driver, an RGB controller or whatever crosses my mind LOL. Thanks again!
     
    Last edited: May 30, 2012
Loading...