Build Your Own Clone Message Board

It is currently Thu Mar 28, 2024 2:10 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Oct 28, 2016 1:27 am 
Offline

Joined: Tue Oct 25, 2016 8:36 pm
Posts: 6
From my work I've had quite a bit of experience with hardware development, but purely from a supervisory role, and so recently I've been playing around with ground up MCU circuit design to try to get a better understanding.

I put the following circuit together to allow me to play around with the MCU registers a bit and it does work - only intermittently.

The LED blinks as intended, then stops for an arbitrary time, flashes again a different number of times, off again etc. There doesn't seem to be any cyclic behaviour to it. It starts working without any external input (i.e. nudging it) so doesn't seem like a loose connection either. I realise the second Vss pin isn't grounded in the schematic, but this didn't help the circuit either when I tried it. Could it be because Vusb isn't grounded? I would have thought this would only affect USB operation.
Image
Code:
Code:
#include <stdio.h>
#include <stdlib.h>

#include <p18f2550.h>
#include <delays.h>

#pragma config FOSC = INTOSCIO_EC       

#pragma config WDT = OFF               

void main() {

    TRISAbits.TRISA1    = 0;    // Set RA1 as output
    LATAbits.LATA1      = 1;    // Set RA1 as HIGH

    while (1)
    {
        LATAbits.LATA1 = ~LATAbits.LATA1;   // Toggle LED pin
        Delay10KTCYx(25);                   // Delay
    }   
}

Here you can see the datasheet for the part.


Top
 Profile  
 
PostPosted: Fri Oct 28, 2016 11:52 am 
Offline
Site Admin
User avatar

Joined: Sun Jan 22, 2006 1:39 pm
Posts: 5983
Location: Richland, WA
What compiler are you using? MPLAB xIDE? Is C your go-to language? I'm more of a BASIC guy if I have my choice, but I do know some C. You're using a C based language, but I'm not familiar the commands you are using.

The tutorials at electrosome.com are pretty awesome. Here's a very basic one for making an LED blink on and off using an MPLAB compiler and C based code https://electrosome.com/led-pic-microco ... mplab-xc8/

In my experience, when something "kinda" works, but doesn't work perfectly, it's usually a problem with the config or registers. Your configs look a little sparse.

Is ~ the command for toggle? Perhaps, instead of trying to use the toggle command, try a more straight forward approach:
Code:
void main() {

    TRISAbits.TRISA1    = 0;    // Set RA1 as output

    while (1)
    {
        LATAbits.LATA1      = 1;    // Set RA1 as HIGH
        Delay10KTCYx(25);                   // Delay
        LATAbits.LATA1      = 0;    // Set RA1 as LOW
        Delay10KTCYx(25);                   // Delay
    }   
}


In my experience, the canned command statements like toggle and button and pot just causes more trouble than it's worth when your code starts getting more intricate. They only save you a couple lines of code, use up more processor, and can be a little buggy with certain PICs.

_________________
*patience is a virtue*

Please do not PM me. email is prefered. keith@buildyourownclone.com


Top
 Profile  
 
PostPosted: Fri Oct 28, 2016 12:30 pm 
Offline
Site Admin
User avatar

Joined: Sun Jan 22, 2006 1:39 pm
Posts: 5983
Location: Richland, WA
I overlooked the fact that you are using ICD3, so obviously you are using MPLAB. Definitely checkout that tutorial. MPLAB isn't my preferred dev environment, so I'm no expert, but I would guess your problem is with your config. See section 2.6 "Requirements for debugging" of the ICD3 manual. Looks like you're missing a few config statements. You may need to configure RB6 and RB7 as outputs as well.

Also, why are you using a syntax like TRISAbits.TRISA1 = 0; instead of something like TRISA1 = 0; and LATAbits.LATA1 = 1; instead of something like RA1 = 1;? I'm not saying it's wrong, because there's always more than one way to skin a cat, and MPLAB isn't my wheelhouse, but it just looks odd. I guess if MPLAB recognizes it and it's what you're familiar with, then stick with what works, but I can't help but wonder if that's not part of your problem as well.

_________________
*patience is a virtue*

Please do not PM me. email is prefered. keith@buildyourownclone.com


Top
 Profile  
 
PostPosted: Thu May 21, 2020 8:21 am 
Offline

Joined: Thu May 21, 2020 8:19 am
Posts: 1
Hi I know this is old but you seem to be missing a clock for the PIC - without an external crystal to set the timing it will appear random
Paul


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group