|
|
View previous topic :: View next topic |
Author |
Message |
artohautala
Joined: 17 Nov 2011 Posts: 187
|
why wdt is not sparking in this code |
Posted: Wed Jul 25, 2018 2:57 am |
|
|
HI,
I'm wondering why watchdog timer not work here in my code:
Code: |
#include <18F4525.h>
#device ADC=10
#fuses HS,NOLVP,WDT,PUT
//#use delay(clock = 16000000, restart_wdt)
#use delay(clock = 16000000)
#byte PORTA = 0x80
#byte PORTB = 0x81
#byte PORTC = 0x82
#byte PORTD = 0x83
#byte PORTE = 0x84
#define secs (pin_D7) // CS/load pin for seconds
#define ten_secs (pin_D6) // CS/load pin for ten seconds
#define mins (pin_D5) // CS/load pin for minutes
#define ten_mins (pin_D4) // CS/load pin for ten minutes
#define hours (pin_D3) // CS/load pin for hours
#define ten_hours (pin_D2) // CS/load pin for ten hours
#define CLK (pin_D1) //clock pin to MAX7219
//these: devided two parts because of data errors!
#define Data_In (pin_D0) //data in pin all exept seconds ! to MAX7219
#define Data_In_Secs (pin_C4) //data in pin seconds ! to MAX7219
#define CLK_From_Owen (pin_B0) //clock pin from owen
#define Display_Off PIN_B2
#define Set_Run PIN_B1
#define Minus_Button PIN_B5 //active low
#define Plus_Button PIN_B4 //active low
#define Set_Button PIN_B3 //active low
void lamp_test(void);
void pixel_test(void);
void send_data (int16 data,int8 digit);
void clock_7219(void); //send clock pulse to MAX7219, clock pin = CLK = D1
void zero_rows(int8 digit); //make all rows empty
void init_max7219(void);
void show_numbers(int8 number, int8 digit);
void update_digits(void); //update Globals G_ten_hours...G_secs
void turn_display_off(void);
void turn_display_on(void);
void Set_Time(void);
void Main_Init(void);
void count_from_clock(void); //interrupt function
void Auto_Bright(void);
void Max_Bright(void);
unsigned int G_ten_hours,G_hours,G_ten_mins,G_mins,G_ten_secs,G_secs,G_Digit_Update;
int1 G_Sec_Done;
int1 G_Set_Pressed;
//*********************************************************************************************
void main(void){
int1 forever = TRUE;
int8 digit;
delay_ms(201);
SETUP_WDT(WDT_DIV_32);
SETUP_WDT(WDT_ON);
SETUP_WDT(WDT_DIV_32);
init_max7219();
Main_Init();
G_Sec_Done = FALSE;
G_Set_Pressed = FALSE;
delay_ms(500);
show_numbers(0, 1); //digit 1 is seconds
delay_ms(3000);
//HERE WDT IS NOT RESTARTED ANYWAY STILL WDT IS NOT SPARKING ???????????????????????
while(1){
show_numbers(5, 1); //digit 1 is seconds NUMBER IS 5
delay_ms(500);
show_numbers(8, 1); //digit 1 is seconds
delay_ms(500);
}
//*********************************************************************************************
void init_max7219(void) {
int8 digit;
for(digit = 1; digit <= 6; ++digit){
send_data (0x0C00,digit); //shutdown
send_data (0x0C01,digit); //shutdown, normal operation
send_data (0x0900,digit); //no decode mode
send_data (0x0B06,digit); //enable columns 0...6
send_data (0x0A0F,digit); //intensity max. (= 0f)
zero_rows(digit); //this: clears all rows
send_data(0x0C01,digit); //shutdown, normal operation
send_data(0x0F00,digit);
send_data(0x700,digit); //lamp test OFF
}
}
//*********************************************************************************************
void Main_Init(void){
int8 digit;
setup_port_a( AN0 );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
setup_timer_2(T2_DIV_BY_16, 127, 1); //this is for PWM 1 & PWM 2
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_ccp2(CCP_PWM); // Configure CCP2 as a PWM
set_pwm1_duty(100);
set_pwm2_duty(100);
//check if these G_ten_hours,G_hours,G_ten_mins,G_mins,G_ten_secs,G_secs; are OK after boot:
if(G_ten_hours > 2)
G_ten_hours = G_hours = G_ten_mins = G_mins = G_ten_secs = G_secs = 0;
if(G_ten_hours <= 2){
if(G_hours > 9)
G_ten_hours = G_hours = G_ten_mins = G_mins = G_ten_secs = G_secs = 0;
}
if(G_ten_mins > 5)
G_ten_hours = G_hours = G_ten_mins = G_mins = G_ten_secs = G_secs = 0;
if(G_mins > 9)
G_ten_hours = G_hours = G_ten_mins = G_mins = G_ten_secs = G_secs = 0;
if(G_ten_secs > 5)
G_ten_hours = G_hours = G_ten_mins = G_mins = G_ten_secs = G_secs = 0;
if(G_secs > 9)
G_ten_hours = G_hours = G_ten_mins = G_mins = G_ten_secs = G_secs = 0;
//show all digits:
for(digit = 1; digit <=6 ; ++digit) zero_rows(digit);
show_numbers(G_secs, 1); //digit 1 is seconds
show_numbers(G_ten_secs, 2); //digit 2 is ten_seconds
show_numbers(G_mins, 3); //digit 3 is minutes
show_numbers(G_ten_mins, 4); //digit 4 is ten_minutes
show_numbers(G_hours, 5); //digit 5 is hours
show_numbers(G_ten_hours, 6); //digit 8 is ten_hours
setup_timer_0 (RTCC_EXT_L_TO_H | RTCC_DIV_32) ;
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
}
//***********************************************************************************************************
|
I'm very pleased if someone help me !
all the best
-arto- |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Wed Jul 25, 2018 3:07 am |
|
|
A question. How are you testing this?.
If with a debugger, you need to be aware that ICD, automatically disables the watchdog....
Then second, you have 'restart_wdt' selected in the delay setup. This means that whenever the code is executing delays, it'll automatically reset the watchdog. Result if it is looping and using delays, the watchdog will never trigger.
This is an example of why this 'feature' should not be used. It results in restart_wdt instructions being placed into the code that can accidentally be reached, so the watchdog becomes useless...... |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Wed Jul 25, 2018 3:26 am |
|
|
Ttelmah wrote: | A question. How are you testing this?.
If with a debugger, you need to be aware that ICD, automatically disables the watchdog....
Then second, you have 'restart_wdt' selected in the delay setup. This means that whenever the code is executing delays, it'll automatically reset the watchdog. Result if it is looping and using delays, the watchdog will never trigger.
This is an example of why this 'feature' should not be used. It results in restart_wdt instructions being placed into the code that can accidentally be reached, so the watchdog becomes useless...... |
I know I have to restart wdt but it's commented out in the top of my code for test purposes...
<This is an example of why this 'feature' should not be used. It results in restart_wdt instructions being placed into the code that can accidentally be reached, so the watchdog becomes useless......>
I don't see what you mean ...? how to fix the problem ?
now i'm looking my display and it seems to me that watchdog is working but it takes very long time !
thank you |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Wed Jul 25, 2018 3:30 am |
|
|
Ttelmah wrote: | A question. How are you testing this?.
If with a debugger, you need to be aware that ICD, automatically disables the watchdog....
Then second, you have 'restart_wdt' selected in the delay setup. This means that whenever the code is executing delays, it'll automatically reset the watchdog. Result if it is looping and using delays, the watchdog will never trigger.
This is an example of why this 'feature' should not be used. It results in restart_wdt instructions being placed into the code that can accidentally be reached, so the watchdog becomes useless...... |
I'm testing it PICKIT2 in circuit programmer. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Wed Jul 25, 2018 3:51 am |
|
|
The whole point of a watchdog, is that the restart should _only_ be reachable if the code is actually working right. You need a 'test' routine, which checks the status of everything the code is meant to do, and only resets the watchdog, if every part of the code is actually functioning correctly. Otherwise the watchdog is largely pointless...
<https://www.embedded.com/design/debug-and-optimization/4402288/Watchdog-Timers>
Look particularly at the section 'Sanity checks'.
Misuse of watchdogs is a very common fault.
Your problem is simple. WDT. You don't want this fuse. Selecting the watchdog in hardware, overrides the setup_wdt instruction. Yours is being hardware programmed to enabled, with the longest possible timeout. To software configure the WDT you need the NOWDT fuse (on some chips you have to use the WDT_SW fuse). |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Jul 25, 2018 4:57 am |
|
|
also...
your slection for adc_clock speed appears to be in error.
Table 19-1 of the datasheet shows what are valid adc_clock sources vs PIC speeds.
I'm assuming you let some 'wizard' automatically configure it for you... well the 'wizard' is wrong. The only time 'internal' is used is when the PIC is asleep according to the Note (3) under the table.
While you won't see any ADC problems during 'simulation' or possibly 'ICD' operations, you will when the PIC operates in the Real World. |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Wed Jul 25, 2018 5:08 am |
|
|
temtronic wrote: | also...
your slection for adc_clock speed appears to be in error.
Table 19-1 of the datasheet shows what are valid adc_clock sources vs PIC speeds.
I'm assuming you let some 'wizard' automatically configure it for you... well the 'wizard' is wrong. The only time 'internal' is used is when the PIC is asleep according to the Note (3) under the table.
While you won't see any ADC problems during 'simulation' or possibly 'ICD' operations, you will when the PIC operates in the Real World. |
Thanks for your good answer ... I'm not using that adc anymore it was for
other version of my program so it is not valid anymore...
BTW this works :
#fuses HS,NOLVP,WDT16,PUT
so it must be that WDT16 !
thank you
|
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Wed Jul 25, 2018 5:10 am |
|
|
temtronic wrote: | also...
your slection for adc_clock speed appears to be in error.
Table 19-1 of the datasheet shows what are valid adc_clock sources vs PIC speeds.
I'm assuming you let some 'wizard' automatically configure it for you... well the 'wizard' is wrong. The only time 'internal' is used is when the PIC is asleep according to the Note (3) under the table.
While you won't see any ADC problems during 'simulation' or possibly 'ICD' operations, you will when the PIC operates in the Real World. |
I found this useful : #fuses HS,NOLVP,WDT16,PUT
so it must be WDT16 it's working no fine |
|
|
artohautala
Joined: 17 Nov 2011 Posts: 187
|
|
Posted: Wed Jul 25, 2018 5:18 am |
|
|
artohautala wrote: | temtronic wrote: | also...
your slection for adc_clock speed appears to be in error.
Table 19-1 of the datasheet shows what are valid adc_clock sources vs PIC speeds.
I'm assuming you let some 'wizard' automatically configure it for you... well the 'wizard' is wrong. The only time 'internal' is used is when the PIC is asleep according to the Note (3) under the table.
While you won't see any ADC problems during 'simulation' or possibly 'ICD' operations, you will when the PIC operates in the Real World. |
I found this useful : #fuses HS,NOLVP,WDT16,PUT
so it must be WDT16 it's working now fine |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Wed Jul 25, 2018 6:18 am |
|
|
No. That's now turning it on in hardware at the time you want. Not the same thing. Means you can never turn it off, or change the interval. |
|
|
|
|
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
|