5931 views|29 replies

135

Posts

1

Resources
The OP
 

I encountered a problem again, about the problem of PIC24FJ64GA004 clock oscillation [Copy link]

 
How to set the clock selection of PIC24FJ64GA004 microcontroller? I have written a program. I use software simulation SIM to simulate the delay function delay1s(); the delay time is more than 160ms. But the simulation effect on proteus simulation software is about 3 seconds. The LED is on for 3 seconds and off for 3 seconds. I don't know what's wrong. Can you help me? Thank you. Attached is the program and simulation picture.

微信图片_20180901191351.png (47.5 KB, downloads: 0)

微信图片_20180901191351.png

微信图片_20180901191359.png (48.99 KB, downloads: 0)

微信图片_20180901191359.png
This post is from Microchip MCU

Latest reply

Now people usually use xc8 or xc16  Details Published on 2018-9-6 22:08
 

1w

Posts

25

Resources
2
 
Doesn't the current XC16 have a delay function? Just set the clock and you can use it.
This post is from Microchip MCU

Comments

I am using the c30 compiler. What is the problem here?  Details Published on 2018-9-1 20:19
 
 
 

135

Posts

1

Resources
3
 
dcexpert posted on 2018-9-1 20:01 Doesn't the current XC16 have a delay function? Just set the clock and you can use it
I am using the c30 compiler. What is the problem here?
This post is from Microchip MCU
 
 
 

135

Posts

1

Resources
4
 
_TRIS, MACRO_ARG21(pin), MACRO_ARG22(pin)) = DIR #define PIN_OUT(pin, OUT) MACRO_CONCAT3(_LAT, OUTPUT) MACRO_CONCAT3(_TRIS, MACRO_ARG21(pin), MACRO_ARG22(pin)) = DIR #define PIN_OUT(pin, OUT) MACRO_CONCAT3(_LAT, OUTPUT) MACRO_CONCAT3(_TRIS, MACRO_ARG21(pin), MACRO_ARG22(pin)) = DIR #define PIN_OUT(pin, OUT) MACRO_CONCAT3(_LAT, OUTPUT) MACRO_CONCAT3(_TRIS, MACRO_ARG21(pin), MACRO_ARG22(pin)) = DIR MACRO_ARG21(pin), MACRO_ARG22(pin)) = OUT #define PIN_IN(pin) MACRO_CONCAT3(_R, MACRO_ARG21(pin), MACRO_ARG22(pin))
This post is from Microchip MCU

Comments

This is a special use of macros, which is to combine two contents into one. It is very useful when using a series of regular registers and is also common in many programs. In particular, when you want the program to automatically adapt to different models of MCUs, use this method to automatically configure the corresponding registers.  Details Published on 2018-9-1 20:37
 
 
 

1w

Posts

25

Resources
5
 
werjufour posted on 2018-9-1 20:20 And I don't quite understand your definition #define MACRO_CONCAT2_EXPAND(a, b) a ## b #define MACRO_CONCAT2( ...
This is a special use of macros, which is to combine two contents into one. It is very useful when using a series of regular registers and is also common in many programs. In particular, when you want the program to automatically adapt to different models of MCUs, using this method to automatically configure the corresponding registers is very helpful for program porting. There is also a delay function in C30, which seems to be __delay_ms(). You need to include a header file. I haven't used PIC microcontrollers for a long time, so I can't remember it clearly. C30 can be replaced by XC16, which supports more functions.
This post is from Microchip MCU

Comments

This is the first time I've seen a macro definition like yours, so I was confused and had no idea what it meant. Is there a solution for the program I just used that uses C30?  Details Published on 2018-9-1 21:42
This is the first time I've seen a macro definition like yours, so I was confused and had no idea what it meant. Is there a solution for the program I just used that uses C30?  Details Published on 2018-9-1 20:41
 
 
 

135

Posts

1

Resources
6
 
dcexpert posted on 2018-9-1 20:37 This is a special use of macros, which is to combine two contents into one. It is very useful when using a series of regular registers. In many programs...
This is the first time I have seen such a macro definition, so I was confused after reading it and had no idea what it meant. Which program I just used c30? Is there any solution?
This post is from Microchip MCU

Comments

Why is my actual effect different from the delay in my software?  Details Published on 2018-9-1 20:42
 
 
 

135

Posts

1

Resources
7
 
werjufour posted on 2018-9-1 20:41 This is the first time I have seen a macro definition like yours, so I was confused and had no idea what it meant. How can I solve the problem of using C30 in a program I just used...
Why is the actual effect different from the delay in my software?
This post is from Microchip MCU

Comments

What is the difference? If it is just a delay, first define _XTAL_FREQ in the program, which represents the system clock frequency #ifndef _XTAL_FREQ #define _XTAL_FREQ 4000000L #endif Then use __delay_ms() or __delay_us() to delay.  Details Published on 2018-9-2 15:07
 
 
 

578

Posts

0

Resources
8
 
dcexpert posted on 2018-9-1 12:37 This is a special use of macros, which is to combine two contents into one. It is very useful when using a series of regular registers. In many programs...
Can this macro definition be applied to many MCUs? I don't understand what they mean
This post is from Microchip MCU

Comments

Most C compilers support it.  Details Published on 2018-9-2 14:54
 
Personal signature刻苦学习,共同进步
 
 

1w

Posts

25

Resources
9
 
Posted by Mayer Fengsui on 2018-9-1 21:42 Can this macro definition usage be applied to many MCUs? I don’t understand what they mean
Most C compilers support it.

This post is from Microchip MCU

Comments

For example: #define IO_OUTPUT 0 #define IO_INPUT 1 #define PIN_DIR(pin, DIR) MACRO_CONCAT3(_TRIS, MACRO_ARG21(pin), MACRO_ARG22(pin)) = DIR In the program, the LED pins are defined: #defin  Details Published on 2018-9-2 15:02
 
 
 

1w

Posts

25

Resources
10
 
dcexpert posted on 2018-9-2 14:54 Most C compilers support it.
For example: #define IO_OUTPUT 0 #define IO_INPUT 1 #define PIN_DIR(pin, DIR) MACRO_CONCAT3(_TRIS, MACRO_ARG21(pin), MACRO_ARG22(pin)) = DIR In the program, the LED pin is defined: #define LED1 A, 1 Initialization setting: PIN_DIR(LED1, IO_OUTPUT) The actual result is _TRIS A = 1 This usage looks complicated, but the advantage is that it can make the program more portable and readable, and it is more convenient to port the code on different C compilers and different microcontrollers. For a more detailed explanation, please refer to the explanations and examples in my book "Special Topic on AVR Microcontroller Application".

This post is from Microchip MCU

Comments

I still don't understand, I'll go look for "AVR MCU Application Special Topic Lecture"  Details Published on 2018-9-2 16:53
 
 
 

1w

Posts

25

Resources
11
 
This post was last edited by dcexpert on 2018-9-2 15:09
werjufour posted on 2018-9-1 20:42 Why is my actual effect different from the delay on my software?
What is the difference? If it is just delay, first define _XTAL_FREQ in the program, which represents the system clock frequency #ifndef _XTAL_FREQ #define _XTAL_FREQ 4000000L #endif Then use __delay_ms() or __delay_us() to delay. Note that there are two underscores in front, don't write it wrong. If the delay effect is different, it means that the clock setting or the default configuration word is incorrect. Please refer to the manual for setting. To ensure the effect, you can write the configuration word in the program instead of setting it through the programmer (different PIC microcontrollers have different configuration words). For example: #pragma config FOSC = INTOSC // Oscillator Selection bits (INTOSC oscillator: CLKIN function disabled)


This post is from Microchip MCU

Comments

First of all, I want to thank you. In the MPLAB SIM software simulation, the stopwatch shows about 300MS, but in the Proteus simulation, it takes about 3s to delay. I don't know how long the built-in delay function __delay_ms() delays. For example, if I want to delay 50ms, my system clock frequency and  Details Published on 2018-9-2 22:29
 
 
 

578

Posts

0

Resources
12
 
dcexpert posted on 2018-9-2 07:02 For example: #define IO_OUTPUT 0 #define IO_INPUT 1 #define PIN_DIR(pin, DIR) M ...
I still don't understand. I'll go and look for "AVR Microcontroller Application Special Topic Lecture"
This post is from Microchip MCU

Comments

If you find it, please send it to me. I really don't understand it.  Details Published on 2018-9-2 22:31
 
Personal signature刻苦学习,共同进步
 
 

135

Posts

1

Resources
13
 
dcexpert posted on 2018-9-2 15:07 What is the difference? If it is just a delay, first define _XTAL_FREQ in the program, which represents the system clock frequency #ifndef _XTAL_FREQ ...
First of all, thank you. In the MPLAB SIM software simulation, the stopwatch shows about 300MS, but in the Proteus simulation, it takes about 3s to delay. I don't know how long the built-in delay function delays __delay_ms(). For example, if I want to delay 50ms, what should I fill in the system clock frequency and actual parameters?
This post is from Microchip MCU

Comments

The clock must of course be set to the actual frequency so that the time can be calculated accurately.  Details Published on 2018-9-3 12:26
 
 
 

135

Posts

1

Resources
14
 
Posted by Mayer Fengsui on 2018-9-2 16:53 I still don't understand it. I'll go look for "AVR Microcontroller Application Special Topic" to take a look
If you find it, send it to me. I really don't understand it.
This post is from Microchip MCU

Comments

I looked it up online, but there is no electronic version available. This is a printed book, so you can only buy the book to read it.  Details Published on 2018-9-3 00:25
 
 
 

578

Posts

0

Resources
15
 
werjufour posted on 2018-9-2 14:31 If you find it, please send it to me. I really don't understand it.
I looked it up online, but there is no electronic file to read. This is a printed book, so you can only buy the book to read it.
This post is from Microchip MCU

Comments

Isn't the host the author?  Details Published on 2018-9-3 18:27
 
Personal signature刻苦学习,共同进步
 
 

1w

Posts

25

Resources
16
 
werjufour posted on 2018-9-2 22:29 First of all, thank you. The stopwatch in my MPLAB SIM software simulation shows about 300MS, but in the Proteus simulation, it takes about 3s to delay...
The clock must be set to the actual frequency, so that the time can be calculated accurately.
This post is from Microchip MCU

Comments

Hey, how do I use these two delay functions __delay_ms() or __delay_us()? I want to delay 50ms and 10us, how should I write it?  Details Published on 2018-9-3 18:34
 
 
 

135

Posts

1

Resources
17
 
Posted by Meier Fengsui on 2018-9-3 00:25 I looked it up online, but there is no electronic file available. This is an unpublished book, so you can only buy the book to read it
Isn’t the host the author?
This post is from Microchip MCU
 
 
 

135

Posts

1

Resources
18
 
dcexpert posted on 2018-9-3 12:26 The clock must be set to the actual frequency, so that the time can be calculated accurately.
Sir, how do I use these two delay functions __delay_ms() or __delay_us()? How do I write a delay of 50ms and 10us?
This post is from Microchip MCU

Comments

The parameter is the delay time, __delay_ms(50) means 50ms. Of course, because the delay is done by code instead of by a timer, the accuracy is not very high.  Details Published on 2018-9-3 21:57
 
 
 

1w

Posts

25

Resources
19
 
werjufour posted on 2018-9-3 18:34 Hero, how do I use these two delay functions __delay_ms() or __delay_us(? How should I write a delay of 50ms and 10us?
The parameter is the delay time, __delay_ms(50) is 50ms. Of course, because it uses code delay instead of a timer, the accuracy is not very high.
This post is from Microchip MCU

Comments

The crystal oscillators I use are 8M, 16M, and 32M. Does the delay function __delay_ms(50) always delay for 50ms?  Details Published on 2018-9-5 21:30
The crystal oscillators I use are 8M, 16M, and 32M. Does the delay function __delay_ms(50) always delay for 50ms?  Details Published on 2018-9-5 21:30
 
 
 

135

Posts

1

Resources
20
 
dcexpert posted on 2018-9-3 21:57 The parameter is the delay time, __delay_ms(50) is 50ms. Of course, because it uses code delay instead of timer, the accuracy is not very...
The crystal oscillators I use are 8M, 16M, and 32M. Is the delay time of this delay function __delay_ms(50) always 50ms?
This post is from Microchip MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list