Hot!__delay_ms(); command wont work with Dspic33

Page: 12 > Showing page 1 of 2
Author
caudill002
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2017/11/18 13:14:29
  • Location: 0
  • Status: offline
2018/06/13 17:28:21 (permalink)
0

__delay_ms(); command wont work with Dspic33

Hello,
 
I recently just got back into coding PIC and I wanted to step the game up with a Dspic33EV256GM102. I wanted to use the UART ability to communicate with a PC.
 
I wanted to start easy and turn on an LED. That was pretty standard. I then wanted to blink the LED. The second step I am having issues. Every time I try to use the command, __delay_ms();, the program wont compile and gives me an error for __delay_ms();. I have used this command on previous code and it worked great. Maybe Im forgetting something because its been awhile since I coded a PIC. 
 
I am using an Internal Clock.... I thought maybe it was because I wasn't using a timer, I implemented a timer and still not working. I have tried to get __delay_ms(); for a couple of hours and its still not working. I have checked the datasheet a couple times, must be missing something so if you have any solutions or comments, let me know. I have posted my mcc.h code below and it was created using MCC.
 
Also, I never fully grasp the concept of oscillators. If you have some lessons that I can learn. They will be much appreciated. 
 
Thanks


#ifndef MCC_H
#define MCC_H
#include <xc.h>
#include "pin_manager.h"
#include <stdint.h>
#include <stdbool.h>
#include "interrupt_manager.h"
#include "traps.h"
#include "uart1.h"
#include "tmr1.h"
#include "adc1.h"

#define _XTAL_FREQ 7370000UL

/**
  Section: Type defines
 */
    
/**
 * CORCON initialization type enumerator. Supported types:
 * CORCON_MODE_PORVALUES
 * CORCON_MODE_ENABLEALLSATNORMAL_ROUNDBIASED
 * CORCON_MODE_ENABLEALLSATNORMAL_ROUNDUNBIASED
 * CORCON_MODE_DISABLEALLSAT_ROUNDBIASED
 * CORCON_MODE_DISABLEALLSAT_ROUNDUNBIASED
 * CORCON_MODE_ENABLEALLSATSUPER_ROUNDBIASED
 * CORCON_MODE_ENABLEALLSATSUPER_ROUNDUNBIASED
 */
typedef enum tagCORCON_MODE_TYPE
{
    CORCON_MODE_PORVALUES = 0x0020, /** Use POR values of CORCON */
    CORCON_MODE_ENABLEALLSATNORMAL_ROUNDBIASED = 0x00E2, /** Enable saturation for ACCA, ACCB
                                                             * and Dataspace write, enable normal
                                                             * ACCA/ACCB saturation mode and set
                                                             * rounding to Biased (conventional)
                                                             * mode. Rest of CORCON settings are
                                                             * set to the default POR values.
                                                             * */
    CORCON_MODE_ENABLEALLSATNORMAL_ROUNDUNBIASED = 0x00E0, /** Enable saturation for ACCA, ACCB
                                                             * and Dataspace write, enable normal
                                                             * ACCA/ACCB saturation mode and set
                                                             * rounding to Unbiased (convergent)
                                                             * mode. Rest of CORCON settings are
                                                             * set to the default POR values.
                                                             * */
    CORCON_MODE_DISABLEALLSAT_ROUNDBIASED = 0x0022, /** Disable saturation for ACCA, ACCB
                                                             * and Dataspace write and set
                                                             * rounding to Biased (conventional)
                                                             * mode. Rest of CORCON settings are
                                                             * set to the default POR values.
                                                             * */
    CORCON_MODE_DISABLEALLSAT_ROUNDUNBIASED = 0x0020, /** Disable saturation for ACCA, ACCB
                                                             * and Dataspace write and set
                                                             * rounding to Unbiased (convergent)
                                                             * mode. Rest of CORCON settings are
                                                             * set to the default POR values.
                                                             * */
    CORCON_MODE_ENABLEALLSATSUPER_ROUNDBIASED = 0x00F2, /** Enable saturation for ACCA, ACCB
                                                             * and Dataspace write, enable super
                                                             * ACCA/ACCB saturation mode and set
                                                             * rounding to Biased (conventional)
                                                             * mode. Rest of CORCON settings are
                                                             * set to the default POR values.
                                                             * */
    CORCON_MODE_ENABLEALLSATSUPER_ROUNDUNBIASED = 0x00F0, /** Enable saturation for ACCA, ACCB
                                                             * and Dataspace write, enable super
                                                             * ACCA/ACCB saturation mode and set
                                                             * rounding to Unbiased (convergent)
                                                             * mode. Rest of CORCON settings are
                                                             * set to the default POR values.
                                                             * */
} SYSTEM_CORCON_MODES;

/**
 * RCON error type enumerator. Supported types:
 * ERR_RCON_TRAPR
 * ERR_RCON_IOPUWR
 * ERR_RCON_CM
 * ERR_RCON_WDTO_ISR
 */
typedef enum tagERROR_TYPE
{
    ERR_RCON_TRAPR = 1, /** A Trap Conflict Reset has occurred **/
    ERR_RCON_IOPUWR = 2, /** An illegal opcode detection, an illegal address mode or Uninitialized W register used as an
                             * Address Pointer caused a Reset **/
    ERR_RCON_CM = 3, /** A Configuration Mismatch Reset has occurred **/
    ERR_RCON_WDTO_ISR = 4 /** WDT time-out has occurred **/
}SYSTEM_RESET_TYPES;

/**
 * RESET CAUSE Masks. Supported masks:
 * RESET_MASK_WDTO
 * RESET_MASK_SWR
 * REST_MASK_EXTR
 * RESET_MASK_CM
 * RESET_MASK_IOPUWR
 * RESET_MASK_TRAPR
 */
typedef enum tagRESET_MASKS
{
  RESET_MASK_WDTO = 0x0010,
  RESET_MASK_SWR = 0x0040,
  RESET_MASK_EXTR = 0x0080,
  RESET_MASK_CM = 0x0200,
  RESET_MASK_IOPUWR = 0x4000,
  RESET_MASK_TRAPR = 0x8000,
} RESET_MASKS;

/**
 * @Param
    none
 * @Returns
    none
 * @Description
    Initializes the device to the default states configured in the
 * MCC GUI
 * @Example
    SYSTEM_Initialize(void);
 */
void SYSTEM_Initialize(void);

/**
 * @Param
    none
 * @Returns
    none
 * @Description
    Initializes the oscillator to the default states configured in the
 * MCC GUI
 * @Example
    OSCILLATOR_Initialize(void);
 */
void OSCILLATOR_Initialize(void);

/**
* Checks reset cause, flashes UI with an error code as a result.
*
* Note: this function should be called before any use of CLRWDT
* since it has a side-effect of clearing the appropriate bits in the
* register showing reset cause (see DS70602B page 8-10)
*/
uint16_t SYSTEM_GetResetCause(void);


/**
 * Enables Watch Dog Timer (WDT) using the software bit.
 * @example
 * <code>
 * WDT_WatchdogtimerSoftwareEnable();
 * </code>
 */
inline static void WDT_WatchdogtimerSoftwareEnable(void)
{
    RCONbits.SWDTEN = 1;
}

/**
 * Disables Watch Dog Timer (WDT) using the software bit.
 * @example
 * <code>
 * WDT_WatchdogtimerSoftwareDisable();
 * </code>
 */
inline static void WDT_WatchdogtimerSoftwareDisable(void)
{
    RCONbits.SWDTEN = 0;
}

/**
 * Clears the Watch Dog Timer (WDT).
 * @example
 * <code>
 * WDT_WatchdogTimerClear();
 * </code>
 */
inline static void WDT_WatchdogTimerClear(void)
{
    ClrWdt();
}

/**
 * Gets the base address of the DEVID register for the currently selected device
 * @return base address of the DEVID register
 * @example
 * <code>
 * uint32_t devIdAddress;
 * devIdAddress = DEVICE_DeviceIdRegisterAddressGet();
 * </code>
 */
inline static uint32_t DEVICE_DeviceIdRegisterAddressGet(void)
{
    return __DEVID_BASE;
}

/**
 * Initializes the CPU core control register.
 * @example
 * <code>
 * CORCON_Initialize();
 * </code>
 */
inline static void CORCON_Initialize()
{
    CORCON = (CORCON & 0x00F2) | CORCON_MODE_PORVALUES; // POR value
}

/**
 * Sets the CPU core control register operating mode to a value that is decided by the
 * SYSTEM_CORCON_MODES argument.
 * @param modeValue SYSTEM_CORCON_MODES initialization mode specifier
 * @example
 * <code>
 * CORCON_ModeOperatingSet(CORCON_MODE_ENABLEALLSATNORMAL_ROUNDUNBIASED);
 * </code>
 */
inline static void CORCON_ModeOperatingSet(SYSTEM_CORCON_MODES modeValue)
{
    CORCON = (CORCON & 0x00F2) | modeValue;
}

/**
 * Sets the value of CPU core control register.
 * @param value value that needs to be written to the CPU core control register
 * @example
 * <code>
 * CORCON_RegisterValueSet(0x00E2);
 * </code>
 */
inline static void CORCON_RegisterValueSet(uint16_t value)
{
    CORCON = value;
}

/**
 * Gets the value of CPU core control register.
 * @return value of the CPU core control register
 * @example
 * <code>
 * corconSave = CORCON_RegisterValueGet();
 * </code>
 */
inline static uint16_t CORCON_RegisterValueGet(void)
{
    return CORCON;
}

/**
 * It handles the reset cause by clearing the cause register values.
 * Its a weak function user can override this function.
 * @return None
 * @example
 * <code>
 * SYSTEM_ResetCauseHandler();
 * </code>
 */
void __attribute__ ((weak)) SYSTEM_ResetCauseHandler(void);

/**
 * This function resets the reset cause register.
 * @return None
 * @example
 * <code>
 * SYSTEM_ResetCauseClearAll();
 * </code>
 */
void SYSTEM_ResetCauseClearAll();

#endif /* MCC_H */
/**
 End of File
*/

#1

24 Replies Related Threads

    jtemples
    Super Member
    • Total Posts : 10947
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 17:36:55 (permalink)
    0
    That code doesn't have __delay_ms() in it.
    #2
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 17:42:44 (permalink)
    5 (2)
    As above. Plus

    #define _XTAL_FREQ 7370000UL

    XC16 uses "FCY", not "_XTAL_FREQ"
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #3
    caudill002
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/11/18 13:14:29
    • Location: 0
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 18:20:49 (permalink)
    0
    This was my header file because my main code only latches B6 and then has a delay. So it only has two lines of code so I figured not to post it. Delay shouldn't be in my header file, It would be in my main code
    #4
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 18:27:36 (permalink)
    0
    You are misusing header files then. They should NEVER contain executable code.
    Organizing Code Files in C and C++ (Ignore the C++ specific bits)
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #5
    caudill002
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/11/18 13:14:29
    • Location: 0
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 18:40:09 (permalink)
    0
    I let MPLABs generate all my header files, through MCC. 
    I do see that I have the FRC for internal oscillator selected.
     
    I have tried:
    #define "FRC" 7370000UL
    #define "FYC" 7370000UL
    both doesn't like the statement delay.
     
    This may sound dumb but what is the difference between FRC, FYC, and _XTAL_FREQ??
    #6
    jtemples
    Super Member
    • Total Posts : 10947
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 18:44:57 (permalink)
    5 (1)
    #defines don't have quotes around them.  And neither of those is what you were told to use.
    post edited by jtemples - 2018/06/13 18:46:08
    #7
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 18:53:24 (permalink)
    0
    caudill002

    This may sound dumb but what is the difference between FRC, FYC, and _XTAL_FREQ??

    They are all wrong.
    It may be time to read the user manuals.
    Start with C:\Program Files (x86)\Microchip\xc16\v1.33\docs\MPLAB_XC16_C_Compiler_Users_Guide.pdf
    (correct the version number to match what you have)
    In there you will find:

    3.5.7 How Can I Implement a Delay in My Code?
    Using a device timer to generate a delay is the best method. If no time is available, then
    you can use the library functions _delay32, __delay_ms, or __delay_us, as they
    are described in the following document. It is available for download from the Microchip
    Technology website, www.microchip.com.
    “16-Bit Language Tools Libraries Reference Manual” (DS50001456)


    There is no need to download, you will find that file in the same folder.
    16-Bit_Language_Tools_Libraries_Manual.pdf
    In there you will find the documentation for __delay_ms(), which is where you should have started.



    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #8
    caudill002
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/11/18 13:14:29
    • Location: 0
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 18:54:58 (permalink)
    0
    Sorry,
     
    I used Quotes to signal what i implemented that differed the original. I also meant to type FCY
     
     
    #9
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 19:08:16 (permalink)
    0
    So show us what you really used. Don't modify it to illegal syntax.
    Have you read the user guides I indicated?
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #10
    caudill002
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/11/18 13:14:29
    • Location: 0
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 19:17:57 (permalink)
    0
    #define FRC 7370000UL
    #define FCY 7370000UL
    #define _XTAL_FREQ  7370000UL
     
    I believe it is an issue with the clock but im not 100% sure about that. If you said all of it was wrong above...everything that I have tried for the clock has to be incorrect then
     
    I have found the files and I read the part that you posted, It then directs me to the Tools_Libraries_Manual but I'm am sifting through the document for the information that pertains to the delays
    #11
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 19:20:55 (permalink)
    0
    caudill002
    I have found the files and I read the part that you posted, It then directs me to the Tools_Libraries_Manual but I'm am sifting through the document for the information that pertains to the delays

    Just Ctrl-F search for "__delay_ms"
    It's on page 206 in my copy.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #12
    jtemples
    Super Member
    • Total Posts : 10947
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 19:21:03 (permalink)
    3 (1)
    It is 100% not an issue with the clock.  The compiler has no idea about what clock you're using.  The delay macros will work the same with any clock.
    #13
    caudill002
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/11/18 13:14:29
    • Location: 0
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 19:35:32 (permalink)
    0
    Yeah, I have read it. It says that it relies on FCY to represent the instruction clock frequency. FCY must be defined before the header file. If FCY is not defined then the delay is declared external...
     
    I am trying sot work some things out. When i am selecting though the options for internal oscillator, FCY is not an option. It either FRC, Primary, External, and LPRC oscillator selections.
    #14
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 19:37:18 (permalink)
    0
    caudill002
    ...
    I am trying sot work some things out. When i am selecting though the options for internal oscillator, FCY is not an option. It either FRC, Primary, External, and LPRC oscillator selections.

    Who said "FCY" is an option?
    It is YOUR job to add a #define to the source code to tell the compiler what clock speed you have set.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #15
    caudill002
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/11/18 13:14:29
    • Location: 0
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 20:00:12 (permalink)
    0
    I have defined the clock speed in my source code...
    #define FCY  7370000UL
    is before my include header files and I am still having complications
    #16
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 20:05:59 (permalink)
    0
    bit hard to guess what exactly "complications" means.

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #17
    caudill002
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/11/18 13:14:29
    • Location: 0
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 20:09:24 (permalink)
    0
    I get this error
     
    main.c: In function 'main':
    main.c:67:5: warning: implicit declaration of function '__delay_ms'
    #18
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 20:25:08 (permalink)
    0
    Please show ALL the code in main.c

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #19
    caudill002
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2017/11/18 13:14:29
    • Location: 0
    • Status: offline
    Re: __delay_ms(); command wont work with Dspic33 2018/06/13 20:37:07 (permalink)
    3 (1)
    /**
    /**
    Generated Main Source File
    Company:
    Microchip Technology Inc.
    File Name:
    main.c
    Summary:
    This is the main file generated using PIC24 / dsPIC33 / PIC32MM MCUs
    Description:
    This header file provides implementations for driver APIs for all modules selected in the GUI.
    Generation Information :
    Product Revision : PIC24 / dsPIC33 / PIC32MM MCUs - pic24-dspic-pic32mm : 1.55
    Device : dsPIC33EV256GM102
    The generated drivers are tested against the following:
    Compiler : XC16 v1.34
    MPLAB : MPLAB X v4.15
    */
    /*
    (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
    software and any derivatives exclusively with Microchip products.
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
    WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
    PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
    WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
    BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
    FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
    ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
    THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
    MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
    TERMS.
    */
    #define FCY 7370000UL
    #include "mcc_generated_files/mcc.h"
    /*
    Main application
    */
    int main(void)
    {
    // initialize the device
    SYSTEM_Initialize();
    // When using interrupts, you need to set the Global Interrupt Enable bits
    // Use the following macros to:
    // Enable the Global Interrupts
    //INTERRUPT_GlobalEnable();
    // Disable the Global Interrupts
    //INTERRUPT_GlobalDisable();
    while (1)
    {
    LATBbits.LATB6 = 1;
    __delay_ms(100);
    }
    }
    /**
    End of File
    */
    */

    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5