View previous topic :: View next topic |
Author |
Message |
maaply
Joined: 23 Mar 2010 Posts: 8 Location: malaysia
|
WDT not working |
Posted: Tue Mar 23, 2010 6:57 pm |
|
|
Hi,
I implemented WDT in my code. It is not working. Someone can help me to find, what I am doing wrong? My code is below,
Code: |
#include <16F723.h>
#device adc = 8
#FUSES WDT /* Watch Dog Timer */
#FUSES INTRC_IO /* Internal RC Osc, no CLKOUT */
#FUSES PUT /* Power Up Timer */
#FUSES MCLR /* Master Clear pin enabled */
#FUSES NOPROTECT /* Code not protected from reading */
#FUSES BROWNOUT /* Reset when brownout detected */
#FUSES BORV25 /* Brownout reset at 2.5V */
#FUSES PLLEN
#FUSES NODEBUG /* No Debug mode for ICD */
#FUSES NOVCAP
#use delay(clock=2000000, PLLEN)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
setup_wdt(WDT_2304MS);
output_a = 0xFF;
delay_ms(1000);
output_a=0x00;
while();
}
|
I should get LED blink connected on port A, but its not blinking !
In debugger code rotating in while loop?
What's wrong in this code ?
Please help me.
Thanks _________________ maaply |
|
|
robomaniac
Joined: 16 Jul 2009 Posts: 19 Location: Sherbrooke, Québec, Canada
|
|
Posted: Tue Mar 23, 2010 8:07 pm |
|
|
Code: | void main()
{
setup_wdt(WDT_2304MS);
output_a = 0xFF;
delay_ms(1000);
output_a=0x00;
while();
} |
That will make the LED blink once since the while is blocking. I guest you want to see the LED blink all the time because the WDT is doing it job.
First thing first. Port A is in Input per default so you have to
Code: | // Constants used for SETUP_ADC() are:
#define ADC_OFF 0 // ADC Off
SETUP_ADC(ADC_OFF );
SETUP_ADC_PORTS(NO_ANALOGS); |
Then you could use those build in CCS function like
Code: | #define GREEN_LED PIN_A2
output_high(GREEN_LED);
output_low(GREEN_LED); |
First thing I would test if you can blink/light up a LED on portB or portC.
That will ensure you that the delay is really 1000ms.
When that works try on portA. When that works, implement the WDT.
good luck _________________ Jérôme Demers
www.jeromedemers.com |
|
|
maaply
Joined: 23 Mar 2010 Posts: 8 Location: malaysia
|
|
Posted: Tue Mar 23, 2010 9:54 pm |
|
|
Thanks Robomaniac,
I tried with PORT B and PORT D also, but not working. My code is below.
Code: |
#include <16F727.h>
#device adc=8
#FUSES WDT //Watch Dog Timer
//#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES INTRC_IO /* Internal RC Osc, no CLKOUT */
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT_NOSL //Brownout enabled during operation, disabled during SLEEP
#FUSES BORV19
#FUSES PLLEN
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOVCAP
#use delay(clock=2000000,PLLEN)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_wdt(WDT_2304MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_vref(FALSE);
// TODO: USER CODE!!
setup_wdt(WDT_2304MS);
set_tris_b(0x00 );
output_b(0x00);
delay_ms(1000);
output_b(0xff);
while(1);
}
|
This code was generated by CCS project wizard.
Thanks. _________________ maaply |
|
|
robomaniac
Joined: 16 Jul 2009 Posts: 19 Location: Sherbrooke, Québec, Canada
|
|
Posted: Tue Mar 23, 2010 11:07 pm |
|
|
When you use
you need
http://www.ccsinfo.com/downloads/PCDReferenceManual.pdf
page 155 of PDF
Quote: | This directive affects how the compiler will generate code for input and output
instructions that follow. This directive takes effect until another #use xxx_IO
directive is encountered. The fixed method of doing I/O will cause the compiler
to generate code to make an I/O pin either input or output every time it is used.
The pins are programmed according to the information in this directive (not the
operations actually performed). This saves a byte of RAM used in standard I/O.
When linking multiple compilation units be aware this directive only applies to
the current compilation unit. |
When you use fast IO, you need to tell the compiler that A1 is Input and B3 is output, etc. Normally CCS can handle all that without telling him.
But that is just for info and probably will not make your code work.
try this code, it is working right now on my breadboard!
Change the include to 16F727
Code: | #include <16lf722.h>
#fuses INTRC_IO,NOWDT
#use delay(INTERNAL=8Mhz)
#define GREEN_LED PIN_C2
void main(void)
{
while(true)
{
output_toggle(GREEN_LED);
delay_ms(500);
}
} |
Try to make your PIC work in the first place.
I will try the WTD right now never coded that yet! _________________ Jérôme Demers
www.jeromedemers.com |
|
|
robomaniac
Joined: 16 Jul 2009 Posts: 19 Location: Sherbrooke, Québec, Canada
|
|
Posted: Tue Mar 23, 2010 11:22 pm |
|
|
Got the Watch dog working!!
Code: | #include <16lf722.h>
#fuses INTRC_IO
#FUSES WDT //Watch Dog Timer
#use delay(INTERNAL=8Mhz)
#define GREEN_LED PIN_C2
void main(void)
{
setup_wdt(WDT_2304MS);
output_high(GREEN_LED);
delay_ms(500);
output_low(GREEN_LED);
while(true);
} |
So you remove the line saying "#FUSES WDT" and it does not blink anymore!
Nice! _________________ Jérôme Demers
www.jeromedemers.com |
|
|
maaply
Joined: 23 Mar 2010 Posts: 8 Location: malaysia
|
|
Posted: Tue Mar 23, 2010 11:54 pm |
|
|
Dear Robomaniac,
Yes have that line. refer my code, #fuses wdt is there in first line. I tried your code with PIC16F727, NOT working.
Thanks, _________________ maaply |
|
|
robomaniac
Joined: 16 Jul 2009 Posts: 19 Location: Sherbrooke, Québec, Canada
|
|
Posted: Wed Mar 24, 2010 12:01 am |
|
|
maaply wrote: | Yes have that line. refer my code, #fuses wdt is there in first line. |
I was just saying remove #fuses to prove to myself that the WDT was working. I was not refering at your code and telling you what to do.
so if it is not working... hardware problems? Got the cathode to ground and anode to pin of PIC?
Can you make a LED blink with your hardware? _________________ Jérôme Demers
www.jeromedemers.com |
|
|
maaply
Joined: 23 Mar 2010 Posts: 8 Location: malaysia
|
|
Posted: Wed Mar 24, 2010 12:08 am |
|
|
Yes I can blink LED, without WDT. Just with some delay,
Code: |
while(1)
{
output_a(0xFF);
delay_ms(1000);
output_a(0x00);
delay_ms(1000);
}
|
So the problem is start on WDT. I interfaced some other HW using SPI, I2C, UART without any problem.
When I try to implement WDT, there is no effect. _________________ maaply |
|
|
robomaniac
Joined: 16 Jul 2009 Posts: 19 Location: Sherbrooke, Québec, Canada
|
|
Posted: Wed Mar 24, 2010 12:14 am |
|
|
Ok then try something very small for the WTD timer:
Code: | like setup_wdt(WDT_18MS); |
If that does not work, then there is probably something in the datasheet saying something smart. _________________ Jérôme Demers
www.jeromedemers.com |
|
|
maaply
Joined: 23 Mar 2010 Posts: 8 Location: malaysia
|
|
Posted: Wed Mar 24, 2010 12:52 am |
|
|
Yes, I tried all the values given in device.h file.
Code: |
#define WDT_18MS 8
#define WDT_36MS 9
#define WDT_72MS 10
#define WDT_144MS 11
#define WDT_288MS 12
#define WDT_576MS 13
#define WDT_1152MS 14
#define WDT_2304MS 15
|
Nothing is made it work.
Thanks. _________________ maaply |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 24, 2010 12:54 pm |
|
|
Quote: | I implemented WDT in my code. It is not working |
Post your compiler version. It's a 4-digit number in this format: x.xxx
It's given at the top of the .LST file, which will be in your project
directory after a successful compilation. |
|
|
maaply
Joined: 23 Mar 2010 Posts: 8 Location: malaysia
|
|
Posted: Wed Mar 24, 2010 6:37 pm |
|
|
CS PCM C Compiler, Version 4.082, 45061 24-Mar-10 14:54 _________________ maaply |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 25, 2010 9:52 pm |
|
|
Compiler vs. 4.082 is buggy in the startup code for the internal oscillator.
Also, the setup_oscillator() function is buggy in that version. Try the
program shown below, which uses a substitute routine, called
my_setup_oscillator(). It should setup the internal oscillator to 8 MHz
correctly. It should also do a 2 second WDT timeout period.
I don't have a 16F727 to test this in hardware, but I think it should work.
Code: |
#include <16F727.h>
#fuses INTRC_IO, PLLEN, WDT
#use delay(clock=8000000)
#byte OSCCON = 0x90
#define my_setup_oscillator(x) OSCCON=x
//=======================================
void main(void)
{
my_setup_oscillator(OSC_8MHZ);
setup_wdt(WDT_2304MS);
output_high(PIN_C2);
delay_ms(500);
output_low(PIN_C2);
while(1);
} |
|
|
|
maaply
Joined: 23 Mar 2010 Posts: 8 Location: malaysia
|
|
Posted: Sun Mar 28, 2010 7:52 pm |
|
|
Thanks PCM programmer,
Quote: | #use delay(clock=2000000,PLLEN) |
my internal oscillator works fine with the above setting.
I tried your code. its not working. _________________ maaply |
|
|
maaply
Joined: 23 Mar 2010 Posts: 8 Location: malaysia
|
|
Posted: Sun Mar 28, 2010 8:01 pm |
|
|
Dear all,
I tried to set WDT in " configuration bit " menu in mplab IDE. I enable the WDT. ( by selecting WDT - ON ). almost out all the code is working.
Ok. if i want to enable WDT, by direct Register method. which reg i wand to modify ?
Please help me.
Thanks,
[/b] _________________ maaply |
|
|
|