|
|
View previous topic :: View next topic |
Author |
Message |
on7nh
Joined: 05 Jun 2006 Posts: 41 Location: Belgium
|
startup troubles DSPIC30F4013 |
Posted: Mon Aug 03, 2009 11:03 am |
|
|
Hey folk's
I have a strange problem,
Following code is running well in development mode.
When I reboot (power cycle) the system hangs.
When I change the fuse NOWDT in WDT, the system starts up, but restarted every XXX seconds...
What could be the problem?
Carl
Code: |
#include <30f4013.h>
//#device adc=12
#FUSES NOWDT // Watch Dog Timer
#FUSES EC
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
//#fuses pr
#fuses HS2_PLL4 // div by 3 and multiply the ext. clock of 40mhz by 8x
#FUSES PR_PLL // pll mode
//#fuses HS // div by 3 and multiply the ext. clock of 40mhz by 8x
//#FUSES PR // pll mode
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#define XTAL_FREQUENCY 64000000
#use delay(clock=XTAL_FREQUENCY)
#use rs232(stream = RS232, baud=19200,parity=N,xmit=PIN_F5,rcv=PIN_F4,bits=8)
int32 freq;
int32 teller,waarde;
int32 tellerfirst,laatstewaarde;
int32 gemetenwaarde;
int32 displayvalue;
int32 setpunt_maxgewicht,setpunt_maxfrequentie,setpunt_minfrequentie,setpunt_oscillator;
int run_as_master, lastview;
#define spiclk PIN_F6 // output
#define spidata PIN_F3 // output
#define text1 PIN_B0 // output
#define text2 PIN_B1 // output
#include <math.h>
#include <display2.c>
//////////////////////////////////////////////////////////////////////////
//interrrupt komende van DEMAG module/
//via optokcopler /
//////////////////////////////////////////////////////////////////////////
#int_ext0
void EXT_ISR()
{
if (teller ==2)
{
// waarde opslagen van eerste meting om niet te gebruiken.....
tellerfirst = get_timer23();
}
if (teller <1000)
{
// freq = get_timer23();
teller++;
}
if (teller ==203)
{
laatstewaarde = get_timer23();
set_timer23(0);
teller=0;
gemetenwaarde=(laatstewaarde-tellerfirst)/200;
}
}
///////////////////////////////////////////////////////////////////////////
Void main()
{
set_tris_b(0b11000011);
EXT_INT_EDGE(H_TO_L);
enable_interrupts(int_timer3);
set_timer23(0);
setup_timer2(TMR_EXTERNAL|TMR_DIV_BY_1|TMR_32_bit);
enable_interrupts(INT_EXT0);
enable_interrupts(intr_GLOBAL);
gemetenwaarde = 0;
tellerfirst=0;
printf("hello\n\r");
teller=0;
run_as_master=0;
setpunt_maxgewicht = 16000;
setpunt_maxfrequentie= 10500;
setpunt_minfrequentie=645;
setpunt_oscillator = 10000000;
sendbyte(72);
sendbyte(69);
sendbyte(76);
sendbyte(76);
sendbyte(79);
delay_ms(1000);
While(1)
{
// volgens Van den Berg ligt de frequentie tussen 500 en 10500 Hz
// dus
// bij 500 hz = 4000000 / 500 = 40000 / 5 = 8000
// bij 15000 hz = 4000000/10500 = 380
// resolutie = 8000-380 = 7620
// 16000 / 7620 = 2 kgr / digit
// berekening 10 mhz
// 10.000.000 / 500 = 20.000
// 10.000.000 / 10500 = 952
// 20.000 - 952 = 19048
// 16000 / 19048 = 0.83 kgr / digid
// instelligen....
// frequentie
// min bereik freq
// max bereik freq
// min waarde display
// maximum waarde display
if (input(text2)== true)
{
sendbyte(32);
sendbyte(32);
sendbyte(32);
sendbyte(32);
sendbyte(32);
sendbyte(72); //H
sendbyte(69); //E
sendbyte(76); //L
sendbyte(80); //P
sendbyte(32); //
}
if (lastview > 30 & input(text1) == 1)
{
sendbyte(32);
sendbyte(32);
sendbyte(32);
sendbyte(32);
sendbyte(32);
sendbyte(77);
delay_ms(300);
sendbyte(65);
delay_ms(300);
sendbyte(83);
delay_ms(300);
sendbyte(84);
delay_ms(300);
sendbyte(69);
delay_ms(300);
sendbyte(82);
delay_ms(300);
sendbyte(32);
delay_ms(500);
sendbyte(32);
delay_ms(300);
sendbyte(32);
delay_ms(300);
sendbyte(32);
delay_ms(300);
sendbyte(32);
lastview = 0;
}
lastview ++;
delay_ms(1000);
display(ABS(((10000000/GEMETENWAARDE)-setpunt_minfrequentie)* 1630/1000));
printf("%c[2J%c[H",27,27);
printf("FRQ %u\n\r",freq-tellerfirst);
printf("FRQ %u\n\r", freq);
printf("tellerfirst %u\n\r",tellerfirst);
printf("laatstewaarde %u\n\r",laatstewaarde);
printf("gemetenwaarde %u\n\r",gemetenwaarde);
printf("displayvalue %u\n\r",displayvalue);
}
} |
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Aug 03, 2009 11:37 am |
|
|
When you have the watchdog enabled, it must be "tickled" frequently to
tell the code that everything is working correctly.
restart_wdt();//at least one in the main while(1) loop
Your delays may not work with wdt on without using
#use delay(clock=18432000,RESTART_WDT) |
|
|
on7nh
Joined: 05 Jun 2006 Posts: 41 Location: Belgium
|
|
Posted: Mon Aug 03, 2009 12:24 pm |
|
|
Yes ! This is working !
Only I don't know why the pic is not booting without the WDT.
Now the time between power and booting is really long (about half a minute). Any sugestions to decrease this time?
Thanks
Carl |
|
|
parasram
Joined: 09 Sep 2009 Posts: 2
|
dspic30f4013 startup issue |
Posted: Thu Aug 05, 2010 10:59 pm |
|
|
I am seeing this same problem.
My guess is that the external clock needs some time to stabilize.
What is happening is that you may be getting an oscillator fail trapped and the code hangs until the WDT expires (30s in your case).
I believe the solution is to enable clock switching and start with the internal clock 7.37Mhz and then switch the external crystal and few seconds later.
What was your final solution? |
|
|
djani
Joined: 19 Dec 2012 Posts: 5
|
|
Posted: Wed Dec 11, 2013 5:34 am |
|
|
HI there,
I dint get this and am having same problem, can some one please put a small explanation code.
Many thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Thu Dec 12, 2013 3:35 am |
|
|
Post your fuses, crystal frequency, what speed you are trying to run, the exact chip, and compiler version.
The original post has several problems, such as 'EC', as well as 'HS2'. These are 'either/or' fuses, not both. So the actual configuration may well have not been 'viable'. The frequency that was being used (64MHz), is also not viable for the PLL4 selection. Look at table 20-3 in the data sheet....
Best Wishes |
|
|
djani
Joined: 19 Dec 2012 Posts: 5
|
startup troubles DSPIC30F4013 |
Posted: Thu Dec 12, 2013 5:07 am |
|
|
Hi there,
resonator=16Mhz clock=32Mhz using (HS/2 PLLx4)
it did give me error in compiler when i tried to use below line.
#use delay(clock=32Mhz,crystal=16Mhz)
Please find my code below. I tried to use watchdog but still cant get the startup time to below 16seconds. Ideally want it to start up straight away.
This works fine when I change the clock to 16MHz (withouth the PLL).
Also starts straight away in Clock=32MHz (with PLL) but only when ICD3 is connected to micro. Never seen this prob before.
MPLAB IDE v8.88 + CCS compiler 4.138 (IDE,PCB,PCM,PCH,PCD)
Code: | #if defined(__PCD__)
#include <30F4013.h>
//#device ICD=TRUE
#device ADC=12
//#fuses HS,NOWDT,NOPROTECT //HS2_PLL4,FRC_PLL4
#fuses HS2_PLL4,WDT,NOPROTECT,NODEBUG //PUT64,NOCKSFSM,NOPUT,NOWRT
#use delay(clock=32Mhz) //(,crystal=16Mhzclock=16MHz)
//#use rs232(UART1, baud=9600)
#endif
// The following initializes the first 4 locations of the data EERPOM
// using the #ROM directive
#if defined(__PCD__)
#rom 0x007FFC00={1,2,3,4}
#endif
//EEPROM Address where TxID is saved
//#define CALIB 0x0034
#define ID_ADDRESS 0x0010
// CAN data buffer (to be transmitted)
unsigned int8 data[5][8]={
0x01,0x00,0x52,0x56,0x30,0x30,0x37,0x00,
0x02,0x00,0x01,0x01,0x01,0x01,0x00,0x00,
0x03,0x00,0x01,0x01,0x01,0x01,0x00,0x00,
0x04,0x00,0x01,0x01,0x01,0x01,0x00,0x00,
0x05,0x00,0x01,0x01,0x01,0x01,0x00,0x00,
};
#include "DEFS.h"
#include "can-dsPIC30.c"
//#include "can-dsPIC30.h"
#include <internal_eeprom.c>
#include <math.h>
#include "adc.c"
unsigned int16 ms;
// Interrupt Timer2
#int_timer2
void isr_timer2(void)
{
ms++;
}
void main(void)
{
// Structure & variables set for use with data received from CAN communication
// struct rx_stat rxstat;
// unsigned int32 rx_id; //The CAN ID(RxID) received on the CAN message
// unsigned int8 rxbuffer[8]; //The CAN data following the CAN ID
// unsigned int8 rx_len;
unsigned int32 tx_id; //The CAN ID used by device. This can be changed by changing the contents of EEPROM.
unsigned int8 index;
/* switch(restart_cause())
{
case RESTART_POWER_UP:
{
data[0][7]= 0x01;
break;
}
case RESTART_BROWNOUT:
{
data[0][7]= 0x02;
break;
}
case RESTART_WATCHDOG:
{
data[0][7]= 0x03;
break;
}
case RESTART_SOFTWARE:
{
data[0][7]= 0x04;
break;
}
case RESTART_MCLR:
{
data[0][7]= 0x05;
break;
}
case RESTART_ILLEGAL_OP:
{
data[0][7]= 0x06;
break;
}
case RESTART_TRAP_CONFLICT:
{
data[0][7]= 0x07;
break;
}
}*/
setup_wdt(WDT_ON);
restart_wdt();
//setup timer2 to interrupt every 1ms if using 16MHz clock
setup_timer2(TMR_INTERNAL,10000); //|TMR_HALT_IDLE, TMR_32_BIT||TMR_32_BIT
SET_TRIS_A(0x0000);
SET_TRIS_B(0x1F3F);
SET_TRIS_C(0x0000);
SET_TRIS_D(0x0000);
SET_TRIS_F(0x00);
// Setup ADC clock & ports to be used
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN8|sAN9|sAN10|sAN11|sAN12|VSS_VDD);
// Get TxID value from the EEPROM
// & Check if the value is valid
write_int16_eeprom(ID_ADDRESS,0x400);
tx_id = read_int16_eeprom(ID_ADDRESS);
if((tx_id>0x00000900) || (tx_id<0x00000100))
{
write_int16_eeprom(ID_ADDRESS,0x0400);
}
// Initialise CAN port
can_init();
// Enable all interrupts - (Timer2)
enable_interrupts(INT_TIMER2);
enable_interrupts(INTR_GLOBAL);
// Loop continuosly
while(TRUE)
{
restart_wdt();
acquire_data(); // Acquire data from the Analog channels
arrange_data(); // Arrange data in the buffer to be transmitted
// In order to Transmit data, put the data on the CAN transmit buffer
for(index=0;index<5;index++)
{
/* The calculation for the delay is = 10000(setup_timer)x4(ms in while loop)x(1/16MHz freq)x4(clock cycles)*/
while( (!can_tbe())|| (ms<160)){}; // every ONE mili seconds, send new data if transmit buffer is empty
ms=0;//reset the count every 1ms or as calculated above.
can_putd(tx_id,&data[index][0], 8, 0, 0, 0); //Send the data out on to the CAN buffer for Transmit.
}
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Thu Dec 12, 2013 8:36 am |
|
|
Seriously 1000* more complicated than it should be to debug a problem like this.
All you should have is a simple 'flash an LED' type program, and you can then see immediately how quickly the processor starts. With lots of extra code, the problem could be that it is waiting for something.....
The flash an LED program will also confirm the actual clock rate.
So:
Code: |
#include <30F4013.h>
#fuses HS2_PLL4,NOWDT,NOPROTECT,NODEBUG,PUT4,NOBROWNOUT,NOMCLR
#use delay(clock=32Mhz)
void main(void)
{
do
{
output_toggle(PIN_F0);
delay_ms(1000);
}
while (TRUE);
}
|
on a 3014 (haven't got a 3013), with just the processor include changed, wakes up only a few mSec after power is applied, and the LED toggles at the right interval.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|