Device configuration

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

Re: Device configuration

Postby Dimebag » Sun Jul 27, 2014 8:41 am

I couldn't get __delay_ms() to work, so I made my own 1 second delay.
Code: Select all
void delay1second(void) {

    int DelaySec = 9174; //9174
    //999.994ms
    int Delay1Sec = 6; //6

      for (inside = 0; inside < DelaySec; inside++) {
        for (outside = 0; outside < Delay1Sec; outside++) {
        }
    }
}

void main(void) {

    Initialization(); //Set all device pins.

    while (1) {
        delay1ms();
        PORTD = 0x01; // array[0];
        delay1ms();
        PORTD = 0x00;
    }
}
 
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby ric » Sun Jul 27, 2014 9:14 am

What problem did you have with __delay_ms() ?
Note, your routine will change delay, depending upon which optimisation level the compiler is using, and is even liable to get optimised away completely if the innermost count variable isn't declared "volatile".
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Dimebag » Sun Jul 27, 2014 10:30 am

Well I don't know how use it with mplabx. I tried to use it weeks ago, I discovered that it didn't matter the delay_ms(5000) I added it did the same stopwatch cycles. I decided to make my own due to not getting anywhere with __delay_ms(). It is very difficult to explain a problem if I don't know the problem to start with. I am trying, just very frustrating atm.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby ric » Sun Jul 27, 2014 10:42 am

Dimebag wrote:Well I don't know how use it with mplabx.

MPLABX is just the editing environment. It is the compiler that matters.
I tried to use it weeks ago, I discovered that it didn't matter the delay_ms(5000) I added it did the same stopwatch cycles.

I can't work out what you are saying here.

I decided to make my own due to not getting anywhere with __delay_ms(). It is very difficult to explain a problem if I don't know the problem to start with. I am trying, just very frustrating atm.

Just ask. Don't give vague explanations of what you did, show the actual code, and say what happened.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Dimebag » Sun Jul 27, 2014 10:59 am

Break point at line 92 in file D:/MPLABXProjects/Blinker.X/BlinkLED.c cannot be resolved to a valid program memory address

Code: Select all
#include <xc.h>
#define __delay_ms;
#define XTAL_FREQ = 20000000;

 


and
Code: Select all
void main(void) {

    Initialization(); //Set all device pins.

    while (1) {
        __delay_ms(1000);
        PORTD = 0x01; // array[0];
        __delay_ms(5000);
        PORTD = 0x00;
    }
}
 
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby ric » Sun Jul 27, 2014 11:33 am

Remove the
#define __delay_ms;
line.

There is a bug in the MPLABX editor, which puts a red squiggle under __delay_ms() when you use it, but it compiles fine.
Using that #define to get rid of the squiggle actually removes the real call to the function.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Dimebag » Sun Jul 27, 2014 1:10 pm

so,
XTAL_FREQ = xxx should work if only the function/macro is called. __delay_ms() should be available to mplabx user to set clock speed with TCY1. I am trying to understand Rick. I have tried to get the Macro...I just missed something to get it to work.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby ric » Sun Jul 27, 2014 1:20 pm

Dimebag wrote:so,
XTAL_FREQ = xxx should work if only the function/macro is called.

__delay_ms() is actually a macro defined by the compiler, and it uses the XTAL_FREQ definition as part of its calculations to get the correct delay.

__delay_ms() should be available to mplabx user to set clock speed with TCY1.

I have no idea what you are trying to say here.
I don't know why you are still referring to MPLABX. It is the compiler (Hitech C, XC8, whatever) that is providing this function. MPLABX is just the editor.

I am trying to understand Rick. I have tried to get the Macro...I just missed something to get it to work.

Have you removed the line I asked you to, and tried it? It should just work.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Device configuration

Postby Dimebag » Sun Jul 27, 2014 1:38 pm

I am back to square one again. I don't use HITECH complier Rick. I must have missed some important parts of the mplabx complier files. You are teaching me what to do, its just not working as it should.
Last edited by Dimebag on Sun Jul 27, 2014 1:42 pm, edited 1 time in total.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Device configuration

Postby ric » Sun Jul 27, 2014 1:42 pm

What are you using?
MPLABX is not a compiler. You must have some compiler installed if you're writing in C.
You mentioned XC8 back on page 1.
I said "HiTech C, XC8, whatever)".

The __wait_ms() macro is available in both, as XC8 is just a development from HiTech C.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

PreviousNext

Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 10 guests

cron