View previous topic :: View next topic |
Author |
Message |
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
wake-up PIC12f615 don't Work |
Posted: Sat Jan 14, 2017 6:10 am |
|
|
After putting the micro in sleep I would like to wake him up (Wake-up from Sleep on Pin Change), but I can not.
Is there someone who has already had this problem ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Jan 14, 2017 11:17 am |
|
|
You need to show us your program ! We cannot say WHY it doesn't work, only guess as to the 30 or 40 things possibly wrong.... |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
|
Posted: Sat Jan 14, 2017 2:17 pm |
|
|
Code: | #FUSES
#FUSES INTRC //Internal RC Osc
#FUSES PUT //Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES IOSC8 //INTOSC speed 8MHz
#FUSES NOBROWNOUT //No brownout reset
//#FUSES NOWRT //Program memory not write protected
#use delay(int=8000000,RESTART_WDT)
#use pwm(CCP1,TIMER=2,FREQUENCY=20000,DUTY=100)
#ZERO_RAM // Allo Start_UP azzera la RAM
#CASE // Case sensitive ( As s'à may )
#WORD OPTION_REG = 0x81
#bit GPPU = OPTION_REG.7
#WORD WPU_REG = 0x95
#BIT WPU5 = WPU_REG.5
/**
* Legge il sensore di Hall
* antirimbalzo presente
*/
uint8 old_HALL=0;
uint8 stato=1;
void read_Puls(void)
{
if(READ_HALL==0){
if(old_HALL==1){
if(stato==0){
set_pwm1_duty(100); // OFF
output_high(PIN_A5);
stato=1;
delay_ms(100);
enable_interrupts(GLOBAL);
sleep();
}
else if(stato==1){
set_pwm1_duty(0); // 100%
stato=2;
delay_ms(100);
}
else if(stato==2){
set_pwm1_duty(50); // 50%
stato=0;
delay_ms(100);
}
old_HALL=0;
}
}
else{
old_HALL=1;
}
}
void main()
{
GPPU=1;
WPU5=0;
Set_PORT(); // Init delle porte
while(1)
{
//set_pwm1_duty(20);
read_Puls();
}
}
/**
* Inizializza tutte le periferiche PORTE di sistema
*
* @param
* @return
*/
void Set_PORT(void)
{
set_tris_a (0x00 // porta A (0 = outoput; 1 = input)
| 0x01 // 0 - RA0 - SEL_2
| 0x02 // 1 - RA1 - SEL_3
// | 0x04 // 2 - RA2 - PWM
| 0x08 // 3 - RA3 -
| 0x10 // 4 - RA4 - SEL_1
| 0x20 // 5 - RA5 - HALL
// | 0x40 // 6 - RA6 -
// | 0x80 // 7 - RA7 -
);
output_a (0x00// porta A (Set=1 or 0)
// | 0x01 // 0 - RA0 -
// | 0x02 // 1 - RA1 -
// | 0x04 // 2 - RA2 - YELLOW
// | 0x08 // 3 - RA3 -
// | 0x10 // 4 - RA4 - GREEN
// | 0x20 // 5 - RA5 - BLU
// | 0x40 // 6 - RA6 -
// | 0x80 // 7 - RA7 -
);
port_a_pullups(0x37);
enable_interrupts(INT_RA|INT_RA5);
enable_interrupts(GLOBAL);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sat Jan 14, 2017 2:33 pm |
|
|
1) Learn to use the code buttons.
2) When debugging you should simplify down to just the part that does not work.
3) You are setting 'TRIS' to make all the pins outputs. Not going to get an interrupt on change with that.....
4) You don't want to 'enable_interrupts(GLOBAL)' for a wake up.
You must _never_ have both an interrupt enabled, and the global enable set without an interrupt handler.
To wake, disable_interrupts(GLOBAL); then enable the interrupt you want to wake (just INT_RA5). You don't need to have INT_RA as well. I don't see your 'main' anywhere.
So:
Code: |
int1 dummy;
output_float(PIN_A5); //set A5 tris to 1
disable_interrupts(GLOBAL); //so no handler is needed
dummy=input(PIN_A5); //ensure this pin is read
clear_interrupts(INT_RA); //This is where 'RA' without the mask is used
enable_interrupts(INT_RA5); //now enable on the one pin
sleep;
delay_cycles(1); //The instruction after a sleep should be a NOP
|
|
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
thank Ttelmah |
Posted: Sun Jan 15, 2017 3:48 am |
|
|
Thank you.
I plugged in my code your suggestion and now I can wake up the microcontroller correctly. I had made life much more difficult, and not being able to debug on a Micro so small was really hard to find a solution.
Thank you.
Code: | delay_ms(100);
clear_interrupt(INT_RA); //This is where 'RA' without the mask is used
enable_interrupts(INT_RA5); //now enable on the one pin
delay_ms(100);
sleep();
delay_cycles(1); //The instruction after a sleep should be a NOP |
|
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
pic goes in sleep only the first time |
Posted: Tue Jan 17, 2017 2:08 am |
|
|
Ok now I have another problem, the pic goes to sleep only the first time, probably something prevents him from setting the condition of subsequent sleep, but do not know what can be. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Tue Jan 17, 2017 8:23 am |
|
|
please post your NEW program so we can debug for you.. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Tue Jan 17, 2017 9:50 am |
|
|
Obvious thing glaring in what he posted, is he removed the 'read' of the port.
The interrupt cannot be cleared, until the port is read. This is why I put a dummy read before I clear the interrupt, so the interrupt can be cleared..... |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
Sleep only when you first turn on |
Posted: Tue Jan 17, 2017 11:39 am |
|
|
Last night I made several tests but unfortunately I'm not going into sleep wineskin the first time
Code: |
void main()
{
Set_PORT(); // Init delle porte
while(1)
{
if(Stato_Sleep==1){
disable_interrupts(GLOBAL); //so no handler is needed
temp8=input(PIN_A5); //ensure this pin is read
clear_interrupt(INT_RA); //This is where 'RA' without the mask is used
enable_interrupts(INT_RA5); //now enable on the one pin
sleep();
delay_cycles(1); //The instruction after a sleep should be a NOP
Stato_Sleep=0;
}
read_Puls();
}
}
/**
* Inizializza tutte le periferiche PORTE di sistema
*
* @param
* @return
*/
void Set_PORT(void)
{
set_tris_a (0x00 // porta A (0 = outoput; 1 = input)
// | 0x01 // 0 - RA0 - SEL_2
// | 0x02 // 1 - RA1 - SEL_3
// | 0x04 // 2 - RA2 - PWM
// | 0x08 // 3 - RA3 -
// | 0x10 // 4 - RA4 - SEL_1
| 0x20 // 5 - RA5 - HALL
// | 0x40 // 6 - RA6 -
// | 0x80 // 7 - RA7 -
);
output_a (0x00// porta A (Set=1 or 0)
// | 0x01 // 0 - RA0 -
// | 0x02 // 1 - RA1 -
// | 0x04 // 2 - RA2 -
// | 0x08 // 3 - RA3 -
// | 0x10 // 4 - RA4 -
// | 0x20 // 5 - RA5 -
// | 0x40 // 6 - RA6 -
// | 0x80 // 7 - RA7 -
);
output_float(PIN_A4); //set A5 tris to 1
port_a_pullups(PIN_A4);
port_a_pullups(PIN_A5);
}
uint8 Stato_Sleep=0;
/**
* Legge il sensore di Hall
* antirimbalzo presente
*/
uint8 old_HALL=0;
uint8 stato=1;
void read_Puls(void)
{
if(READ_HALL==0){
if(old_HALL==1){
if(stato==0){
set_pwm1_duty(100); // SPENTO
stato=1;
delay_ms(200);
Stato_Sleep=1;
/*
disable_interrupts(GLOBAL); //so no handler is needed
clear_interrupt(INT_RA); //This is where 'RA' without the mask is used
enable_interrupts(INT_RA5); //now enable on the one pin
sleep();
delay_cycles(1); //The instruction after a sleep should be a NOP
*/
}
else if(stato==1){
set_pwm1_duty(0); // 100%
stato=2;
delay_ms(100);
}
else if(stato==2){
set_pwm1_duty(50); // 50%
stato=0;
delay_ms(100);
}
old_HALL=0;
}
}
else{
old_HALL=1;
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Tue Jan 17, 2017 11:59 am |
|
|
We are back to Port A5 having it's TRIS set as an output again.....
output_float(PIN_A4); //set A5 tris to 1
Er. You are setting A4 not A5. Remark is wrong for what it does.... |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
|
Posted: Tue Jan 17, 2017 2:25 pm |
|
|
I made the correction, but still is not working, I think he's escaping me something
output_float(PIN_A5); //set A5 tris to 1
port_a_pullups(PIN_A4);
port_a_pullups(PIN_A5); |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
|
Posted: Tue Jan 17, 2017 4:52 pm |
|
|
The first thing I did was read the data sheet of the pic12f615 and in fact in my first post I set the parameters as indicated by the text
#WORD OPTION_REG = 0x81
#bit GPPU = OPTION_REG.7
#WORD WPU_REG = 0x95
#BIT WPU5 = WPU_REG.5
and I set the two parameters, but without good results
Then I used the tools made available to the development tool
pcwwiz.exe
where I set the processor and set the pull-up and I simply copied the code, trusting the tools |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 17, 2017 5:32 pm |
|
|
You didn't read the CCS manual. There is a function to do this:
Code: | port_a_pullups(0x30); // Enable pullups on pins GP4 and GP5 |
It produces this code in the .LST file:
Code: | ........ port_a_pullups(0x30);
0010: MOVLW 30
0011: BSF STATUS.RP0
0012: MOVWF WPU
0013: BCF OPTION_REG.GPPU |
You have to read the CCS manual and the data sheet. |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
last test sleep |
Posted: Wed Jan 18, 2017 12:20 pm |
|
|
I'm sorry but they are very demoralized, even with the latter nothing definitive test. Unfortunately my compiler generates different code.
Code: | .................... // output_float(PIN_A5); //set A5 tris to 1
.................... port_a_pullups(0x20); // Enable pullups on pins GP5
000A: BSF 03.5
000B: MOVWF 15
000C: BCF 01.7
000D: BCF 03.5
000E: GOTO 079 (RETURN)
|
|
|
|
|