|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19217
|
|
Posted: Fri Feb 12, 2021 7:20 am |
|
|
No, if you are from 5.049, that was when the CCS code did not work.
This is why sleep_full is not working for you.
Stick with the assembler for this. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Fri Feb 12, 2021 7:28 am |
|
|
Changed to 5.008 and it sleeps, at least with the small test program.
5.008 does not check anything. Just sleeps!
The problem is that even with the assembly "some times" it does not sleep. That is why I started searching for the problem in the first case.
Code: |
--- E:\WORK\herado\mine\code\V13test\v1.c ------------------------------------------------------
1:
0000 040210 goto 0x000210
2: #include <24FJ64GA004.h>
3:
4: #FUSES NOWDT //Watch Dog Timer
5: #FUSES NOPROTECT //Code not protected from reading
6: #FUSES FRC_PLL //Internal osc + PLL
7: #FUSES NOIESO //Internal External Switch Over mode disabled
8: #FUSES NOPR //Pimary oscillator disabled
9: #FUSES OSCIO //OSC2 is general purpose output
10: #FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
11: #FUSES NOWRT //Program memory not write protected
12: #FUSES NODEBUG //No Debug mode for ICD
13: #BUILD (stack=1024)
14:
15: #use delay(int=32M)
0200 E00000 cp0.w 0x0000
0202 AF2042 btsc.b 0x0042,#1
0204 370004 bra 0x00020e
0206 093E7B repeat #15995
0208 000000 nop
020A E90000 dec.w 0x0000,0x0000
020C 3AFFFC bra nz, 0x000206
020E 060000 return
16:
17: #use fast_io(A)
18: #use fast_io(B)
19: #use fast_io(C)
20:
21: #word LATA=getenv("SFR:LATA")
22: #word LATB=getenv("SFR:LATB")
23: #word LATC=getenv("SFR:LATC")
24:
25: #word TRISA=getenv("SFR:TRISA")
26: #word TRISB=getenv("SFR:TRISB")
27: #word TRISC=getenv("SFR:TRISC")
28:
29: #word PORTA=getenv("SFR:PORTA")
30: #word PORTB=getenv("SFR:PORTB")
31: #word PORTC=getenv("SFR:PORTC")
32:
33: #bit Led1=LATA.8
34: #bit Led2=LATA.1
35:
36: void Main(){
0210 A8E081 bset.b 0x0081,#7
0212 EF2744 clr.w 0x0744
0214 EFA32C setm.w 0x032c
0216 22400F mov.w #0x2400,0x001e
0218 227FF0 mov.w #0x27ff,0x0000
021A B7A020 mov.w 0x0000,0x0020
021C 000000 nop
021E 22400F mov.w #0x2400,0x001e
0220 227FF0 mov.w #0x27ff,0x0000
0222 B7A020 mov.w 0x0000,0x0020
0224 000000 nop
37:
38: TRISA=0b0000000000000001;
0226 200014 mov.w #0x1,0x0008
0228 881604 mov.w 0x0008,0x02c0
39: TRISB=0b1010001110100000;
022A 2A3A04 mov.w #0xa3a0,0x0008
022C 881644 mov.w 0x0008,0x02c8
40: TRISC=0b0000000010000011;
022E 200834 mov.w #0x83,0x0008
0230 881684 mov.w 0x0008,0x02d0
41:
42: Led1=1;
0232 A802C5 bset.b 0x02c5,#0
43: delay_ms(100);
0234 200640 mov.w #0x64,0x0000
0236 020200 call 0x000200
44: Led1=0;
023A A902C5 bclr.b 0x02c5,#0
45: delay_ms(100);
023C 200640 mov.w #0x64,0x0000
023E 020200 call 0x000200
46:
47: SLEEP(SLEEP_FULL);
0242 FE4000 pwrsav #0
48:
49: delay_cycles(1);
0244 000000 nop
50: reset_cpu();
0246 FE0000 reset
51: }
52:
0248 FE4000 pwrsav #0
|
_________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19217
|
|
Posted: Fri Feb 12, 2021 7:49 am |
|
|
You'll have to use the assembler. 5.049, was bang when the CCS code had
problems. It was working OK a couple of versions before this, and then
OK again a couple of versions later. 5.051 doesn't have the extra tests,
nor does 5.048.
The tests were just a code 'fault'. If you look, they make no sense, with
tests being skipped by other tests, and the variables being tested are
not ones that make any sense at all. It was a known bug at the time. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19217
|
|
Posted: Fri Feb 12, 2021 8:39 am |
|
|
do try getting rid of the delay between clearing the interrupts and trying to
sleep. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Mon Feb 15, 2021 1:36 am |
|
|
Hello again!
Back to version 5.049 and to the simple program below.
When I press the "Down Button" the Led1 flashes 100mS and then the CPU sleeps.
Again 1/10 times I press the button, the LED flashes and then flashes again as if it skipped sleep.
Here I have no serials no rtc, no timers, no spi, no adc.
What could be causing this?
Is this the proper way to wake from sleep?
Code: |
#include <24FJ64GA004.h>
#FUSES NOWDT //Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES FRC_PLL //Internal osc + PLL
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOPR //Pimary oscillator disabled
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#BUILD (stack=1024)
#use delay(int=32M)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#word LATA=getenv("SFR:LATA")
#word LATB=getenv("SFR:LATB")
#word LATC=getenv("SFR:LATC")
#word TRISA=getenv("SFR:TRISA")
#word TRISB=getenv("SFR:TRISB")
#word TRISC=getenv("SFR:TRISC")
#word PORTA=getenv("SFR:PORTA")
#word PORTB=getenv("SFR:PORTB")
#word PORTC=getenv("SFR:PORTC")
#bit Led1=LATA.8
#bit Led2=LATA.1
#bit BTN1=PORTB.8 //CN22 up button
#bit BTN2=PORTB.7 //CN23 down button
#INT_CNI
Void CNIISR(){
}
void Main(){
TRISA=0b0000000000000001;
TRISB=0b1010001110100000;
TRISC=0b0000000010000011;
Led1=1;
delay_ms(100);
Led1=0;
delay_ms(100);
enable_interrupts( INTR_CN_PIN | PIN_B7); //Down button
#asm
pwrsav #0
#endasm
delay_cycles(1);
reset_cpu();
}
|
_________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19217
|
|
Posted: Mon Feb 15, 2021 1:43 am |
|
|
Glaring thing is that your interrupt on change handler must read the port
bit on which the change interrupt is set. Otherwise It'll keep resetting. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Mon Feb 15, 2021 1:58 am |
|
|
I added a 500mS flash to Led2 so I know when the CPU woke, before resetting.
Proper sequence should be:
1) press the Button. ->wake CPU
2) Led2 500mS Flash
3) CPU reset
4) Led1 500mS Flash
5) Sleep
The above of course works.
About 1 of 20 cycles this happens:
1) press the Button. ->wake CPU
2) Led2 500mS Flash
3) CPU reset
4) Led1 500mS Flash
5) Led1 500mS Flash
6) Cycle continues normally
As if the sleep command causes a reset. Or the reset command is prefetched way too early or something.
Please look:
Code: |
#include <24FJ64GA004.h>
#FUSES NOWDT //Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES FRC_PLL //Internal osc + PLL
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOPR //Pimary oscillator disabled
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#BUILD (stack=1024)
#use delay(int=32M)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#word LATA=getenv("SFR:LATA")
#word LATB=getenv("SFR:LATB")
#word LATC=getenv("SFR:LATC")
#word TRISA=getenv("SFR:TRISA")
#word TRISB=getenv("SFR:TRISB")
#word TRISC=getenv("SFR:TRISC")
#word PORTA=getenv("SFR:PORTA")
#word PORTB=getenv("SFR:PORTB")
#word PORTC=getenv("SFR:PORTC")
#bit Led1=LATA.8
#bit Led2=LATA.1
#bit BTN1=PORTB.8 //CN22 up button
#bit BTN2=PORTB.7 //CN23 down button
#INT_CNI
Void CNIISR(){
}
void Main(){
TRISA=0b0000000000000001;
TRISB=0b1010001110100000;
TRISC=0b0000000010000011;
Led1=1;
delay_ms(500);
Led1=0;
delay_ms(500);
enable_interrupts( INTR_CN_PIN | PIN_B7); //Down button
#asm
pwrsav #0
#endasm
Led2=1;
delay_ms(500);
Led2=0;
delay_ms(500);
reset_cpu();
}
|
As for reading the CN PIN, I will add it but in the first case, the RTC woke up the CPU and I had the same problems. This is just a test program to simplify and isolate the problem. _________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19217
|
|
Posted: Mon Feb 15, 2021 3:54 am |
|
|
Do some diagnostics. Isolate 'why' the CPU says it is resetting. So something
like:
Code: |
#include <24FJ64GA004.h>
#FUSES NOWDT //Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES FRC_PLL //Internal osc + PLL
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOPR //Pimary oscillator disabled
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#BUILD (stack=1024)
#use delay(int=32M)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#word LATA=getenv("SFR:LATA")
#word LATB=getenv("SFR:LATB")
#word LATC=getenv("SFR:LATC")
#word TRISA=getenv("SFR:TRISA")
#word TRISB=getenv("SFR:TRISB")
#word TRISC=getenv("SFR:TRISC")
#word PORTA=getenv("SFR:PORTA")
#word PORTB=getenv("SFR:PORTB")
#word PORTC=getenv("SFR:PORTC")
#bit Led1=LATA.8
#bit Led2=LATA.1
#bit BTN1=PORTB.8 //CN22 up button
#bit BTN2=PORTB.7 //CN23 down button
#INT_CNI
Void CNIISR(){
int8 dummy;
dummy=input(PIN_B7);
}
const int16 rtimes[500,1000,1000,1000,1000,1000,500,2000,
2000,2000,2000,2000,2000,2000,3000,3000};
void Main(){
int8 reason();
int16 time=500;
reason=restart_cause();
TRISA=0b0000000000000001;
TRISB=0b1010001110100000;
TRISC=0b0000000010000011;
if (reason>15)
reason=15; //trap impossible reason
time=rtimes[reason];
Led1=1;
delay_ms(time);
Led1=0;
delay_ms(time);
//now the flash time will reflect the restart_cause
reason=input(PIN_B7);
clear_interrupt(INTR_CN_PIN); //ensure interrupt wakes off
enable_interrupts( INTR_CN_PIN | PIN_B7); //Down button
#asm
pwrsav #0
#endasm
Led2=1;
delay_ms(500);
Led2=0;
delay_ms(500);
reset_cpu();
}
|
Then the flash time will tell you why the chip is resetting. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Mon Feb 15, 2021 4:03 am |
|
|
From PIC24HJXXXGPX06/X08/X10 Family Silicon Errata:
Quote: |
When the VREGS bit (RCON<8>) is set to a logic
‘0’, the device may reset, and higher sleep current
may be observed.
Work around
Ensure that the VREGS bit (RCON<8>) is set to a
logic ‘1’ for device Sleep mode operation.
|
So:
Code: |
RCON|=0x100;
#asm
pwrsav #0
#endasm
|
Yes my CPU is FJ and not HJ but solved my problem. _________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19217
|
|
Posted: Mon Feb 15, 2021 4:42 am |
|
|
I always say to check errata, but finding that a documented erratum
for another chip applies is not good. Report this to MicroChip. |
|
|
georpo
Joined: 18 Nov 2008 Posts: 278 Location: Athens, Greece.
|
|
Posted: Mon Feb 15, 2021 5:06 am |
|
|
I wasted many hours on this. And as usual not being my fault. I consider the problem solved and not bother anymore.
Ttelmah once again sincerely thanks for the support. _________________ George. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19217
|
|
Posted: Mon Feb 15, 2021 7:18 am |
|
|
and (of course), you had the 'double' issue, with a compiler fault and the
chip problem as well.... |
|
|
|
|
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
|