Hello,
I am switching On and OFF LED'S with Delay's.i am not getting why my controller is reseeting after every 9.18 msec.
here is my code
i am using Default internal clock and WDT is switched OFF
void main(void) |
{ | |
WDOG_CNT = 0xC520; // write the 1st unlock word | ||
WDOG_CNT = 0xD928; | ||
WDOG_CS1 = 0x00; // Disable WDT Timer | ||
PORT_PTAOE = 0x0F; | // Define PortA all Pin As output | |
PORT_PTBOE = 0xFF; | ||
PORT_PTAD = 0x00; | // Initialise the PORTA | |
PORT_PTBD = 0x00; | // Initialise The PORTB | |
while(1){ | |
PORT_PTAD = 0x0F; // Initialise the PORTA | |||
PORT_PTBD = 0xFF; | |||
Delay(); | |||
PORT_PTAD = 0x00; // Initialise the PORTA | |||
PORT_PTBD = 0x00; | |||
Delay(); | |||
} | |||
} |
void Delay () |
{ |
unsigned int i; | |||
for (i=0;i<2500;i++) | |||
{ | |||
; | |||
} | |||
} |
Solved! Go to Solution.
Hello,
Great!!! I'm pleased you have found the answer and I did say in my initial post that some devices require a particular mechanism to disable the watchdog. I would have checked this for you had I have been able to see the reference manual but as it's a pre-production device I couldn't find it!!
Happy programming :-)
Thanks,
Ian
Hello,
As there is nothing wrong with your LED toggling code I would ask if you are sure you have turned the watchdog off as I believe different devices can have different ways of doing this? Have you also checked the relevant register to see what caused the reset? There could be an unhandled interrupt vector or an interrupt mask that isn't cleared?
Hope this helps.
Ian
Hello Mr. Legg,
Actually i tried both, means with n without WDT and i am getting the same result.Actually i am also not sure wether it's Reset or something else but it seems like reset. :smileysad:
Hello,
If you have LEDs on every output pin that you are toggling then you need to consider the maximum current the device can supply and whether or not you are exceeding it. Also make sure you have decoupling caps very near to the supply rails. I wonder if the rapid toggling of the LEDs is too much for your power supply or you are triggering the low voltage detection in the chip?
Can you add debugging code to see if you end up in an interrupt handler or if you pass through reset again etc? Have you tried keeping the watchdog enabled and obviously writing to it before it times out as that would rule it out as the cause?
Thanks,
Ian
Hello Mr. Legg,
I checked the max current for each port and it's 100mA for 5v n 50mA for 3v supply.in my case i am using led fwd 2.2v with 420 ohm register in series with each portpin.(Port A0-A3 and Port B0-B3). so max current is around 56 mA.(It's in limit).but i didn't use capacitor near to vdd and vss as you said.(i will do that).
One more thing : every time i programme µC, it ask me to switch off the power supply to the controller and switch on to reset µC and than it flshes the code.
in debugging it's giving me GDI protocol fatal error : Debugger is not connected to PE device at _RESET_WATCHDOG().(After enable this function in code in single step Debugging)
in Debugging code i haven't added anything extra , it's same as the above code.
Thank you
Hello,
Ok and I trust you are using a 5v supply? You could also make the delay longer so that the LEDs toggle at a slower speed and that is easier on the power supply.
I'm assuming you are using the PE debugger so it itself should take care of the reset via its connection to the BDM pin. Do you also have something else connected to this pin?
Sorry my comment was to add extra debugging code and that way you could determine the source of the reset or interrupt etc etc.
Thanks,
Ian
Hi Legg,
You are Absolutely right regarding your Debugger and supply voltage assumption.Now i connected 10kohm pullup between reset pin and supply voltage n the capacitor also.But still m getting same problem.i mean delay is not more than 9.2 msec even though i am changing the value of int. variable to 65535 .it's giving me only appx. 9.2 msec max value of delay. with internal Frequency of appx. 8Mhz. :smileysad:
Hello,
Have you calculated what the watchdog timeout period would be with an 8MHz (presumably bus clock as opposed to cpu clock)?
Sadly I can't help much further as I've no experience of this particular device but as I said before I would add logging code to try and track down what is happening up to 9.2ms and after a presumed reset.
Thanks,
Ian
Hi Mr. Legg,
I found the Answer ...Here is a piece of code which change the value of WDT reset value
/* Initialize watchdog with ~1-kHz clock source, ~1s time-out */
DisableInterrupts; // disable global interrupt
WDOG_CNT = 0xC520; // write the 1st unlock word
WDOG_CNT = 0xD928; // write the 2nd unlock word
WDOG_TOVAL = 1000; // setting timeout value
WDOG_CS2 = WDOG_CS2_CLK_MASK; // setting 1-kHz clock source
WDOG_CS1 = WDOG_CS1_EN_MASK; // enable counter running
EnableInterrupts; // enable global interrupt
as soon as i put in my code it has started working fine...i got this in data sheet :smileyhappy:
Anyways may be it's helpful for others and thanks a lot once again.
Hello,
Great!!! I'm pleased you have found the answer and I did say in my initial post that some devices require a particular mechanism to disable the watchdog. I would have checked this for you had I have been able to see the reference manual but as it's a pre-production device I couldn't find it!!
Happy programming :-)
Thanks,
Ian
Hi Legg,
No Problem , i will find out myself, but have calculated delay period of Reset for Default and it's appx. 4 msec and it's clock is 1 khz istant of 8 Mhz. I am wondering that instant of 4 msec how it's coming to 9.2 msec.
Thank you very much for your reply , will find out myself.