Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

#use delay(clock=4000000) wrong output at leds

Status
Not open for further replies.

maoterk

Newbie level 5
Joined
Jun 18, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
Hi, i'm new at programming and i tried this easy code for flashing leds with dspic33e usb starter kit, but it seems to take around 5 seconds to flash rather than 1
Any suggestions?
Code:
#include <33EP512MU810.h>
#use delay(clock=40000000)
#byte PORTD=0xF81
void main() {

set_tris_d(0x00); 

WHILE (TRUE){
output_high(PIN_D2);
delay_ms(1000);
output_low(PIN_D2);
delay_ms(1000);
}}
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,933
Helped
4,874
Reputation
9,766
Reaction score
4,662
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
127,032
I'm not sure which compiler you are using but two possibilities come to mind...

Is the clock configured properly - for example are you using an internal 8MHz clock instead of your external 40MHz one? That would account for being five times slower than expected.

Is there a maximum value for the delay_ms() function that you could be exceeding?

Brian.
 

maoterk

Newbie level 5
Joined
Jun 18, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
I am using ccs compiler and the internal oscillator. I am not sure about the maximum delay value

thanks for the response
 

maoterk

Newbie level 5
Joined
Jun 18, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
If i use #use delay(clock=8000000) it works correctly. So can't i use a faster clock with the internal oscillator?

thanks
 

xenos

Full Member level 4
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
Well, the oscillator documentation says that:
The primary oscillator and Internal FRC oscillator sources can optionally use an on-chip PLL to
obtain higher operating speeds.
Doc: https://ww1.microchip.com/downloads/en/DeviceDoc/70580C.pdf

On other microchip devices I have successfuly turn PLL on internal OSC, but these devices seems to have a startup limitation that may be a problem.
Check paragraph: "7.7.1 Input Clock Limitation at Start-up for PLL Mode"
It seems to me that you may not change PLL on the running oscillator and you should temporarily swap to an other one (eg to an external XT).
 

Gorgon

Full Member level 6
Joined
Nov 10, 2005
Messages
345
Helped
75
Reputation
150
Reaction score
67
Trophy points
1,308
Location
Norway
Activity points
3,642
Hi, i'm new at programming and i tried this easy code for flashing leds with dspic33e usb starter kit, but it seems to take around 5 seconds to flash rather than 1
Any suggestions?
Code:
#include <33EP512MU810.h>
#use delay(clock=40000000)
#byte PORTD=0xF81
void main() {

set_tris_d(0x00); 

WHILE (TRUE){
output_high(PIN_D2);
delay_ms(1000);
output_low(PIN_D2);
delay_ms(1000);
}}

Since you have set the delay clock parameter to 40 000 000, it is natural that the speed is 1/5 of what you expect, if your actual CPU clock is 8MHz.

The delay(clock) parameter is not adjusting the CPU clock, it's only used as a base value for the compiler to compute the number of loops that is needed for the correct software delay.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top