Continue to Site

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);
}}
 

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.
 

I am using ccs compiler and the internal oscillator. I am not sure about the maximum delay value

thanks for the response
 

If i use #use delay(clock=8000000) it works correctly. So can't i use a faster clock with the internal oscillator?

thanks
 

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).
 
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

Back
Top