View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 18, 2017 12:44 pm |
|
|
If I take it (.LST file format) off Symbolic mode and put it in CCS mode
I get this code shown below. My guess is that your compiler does the
same, except you didn't post the MOVLW 20.
Code: | .................... port_a_pullups(0x20);
0010: MOVLW 20
0011: BSF 03.5
0012: MOVWF 15
0013: BCF 01.7
.................... |
This is with CCS vs. 5.065 for the 12F615. |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
sleep |
Posted: Wed Jan 18, 2017 1:42 pm |
|
|
ok the code is correct but my program still does not work
I do not know what to go and touch |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Wed Jan 18, 2017 3:07 pm |
|
|
You might have made a small change that you don't see, so please post your entire program. Perhaps 'new eyes' will see what's wrong.
Jay |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
sleep 1 time |
Posted: Thu Jan 19, 2017 4:00 am |
|
|
I compressed the source in a single file even if inelegant
Code: | //------------------------
// INCLUDE DI SISTEMA .H
#include<12F615.h>
// DI SISTEMA
//#include"./GENERAL/Htypes.h" // Define generali
#define uint8 unsigned int8
#define sint8 signed int8
#define uint16 unsigned int16
#define sint16 signed int16
#define uint32 unsigned int32
#define sint32 signed int32
//#include "./GENERAL/Setup.h"
#FUSES INTRC //Internal RC Osc
#FUSES NOPUT //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 NOWDT
//#use delay(int=8000000,RESTART_WDT)
#use delay(int=8000000)
#use pwm(CCP1,TIMER=2,FREQUENCY=20000,DUTY=100)
#ZERO_RAM // Allo Start_UP azzera la RAM
#CASE // Case sensitive ( As s'à may )
#define SEL_1 PIN_A4
#define SEL_2 PIN_A0
#define SEL_3 PIN_A1
#define HALL PIN_A5
#define PWM PIN_A2
////////////////////////////////////////////////////////////////////////////////
// GLOBAL DEFINITIONS
////////////////////////////////////////////////////////////////////////////////
#define READ_SEL_1 input(SEL_1)
#define READ_SEL_2 input(SEL_2)
#define READ_SEL_3 input(SEL_3)
#define READ_HALL input(HALL)
/*
===============================================================================
--- VARIABILI GLOBALI ---
allocate nel relativo modulo C
(che devono essere visibili in altri moduli)
===============================================================================
*/
void Set_PORT(void);
//#include"./PULSANTI/pulsanti.h" // Gestione pulsanti
void read_Puls(void);
//#include"./PULSANTI/pulsanti.c" // Gestione pulsanti
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;
}
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;
}
}
uint8 temp8=0;
void main()
{
Set_PORT(); // Init delle porte
while(1)
{
if(Stato_Sleep==1){
disable_interrupts(GLOBAL); //so no handler is needed
port_a_pullups(0x20); // Enable pullups on pins GP4 and GP5
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_A5); //set A5 tris to 1
port_a_pullups(0x20); // Enable pullups on pins GP5
// port_a_pullups(PIN_A4);
// port_a_pullups(PIN_A5);
} |
|
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
pic12f615 sleep don't work |
Posted: Sun Jan 22, 2017 4:44 am |
|
|
Compared to published code I have done many tests yet, but I have not gotten any better result, if anyone has any suggestions I feel happy. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Sun Jan 22, 2017 4:52 am |
|
|
I'd suggest adding a delay here:
Code: |
port_a_pullups(0x20); // Enable pullups on pins GP4 and GP5
delay_us(10);
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
|
The interrupt becomes set, if the input changes, from when it was last read. You turn on the pullups, then immediately read the port. If the pin takes a couple of uSec to go 'high', the interrupt will then trigger a moment later, and so the sleep will immediately wake.
You are also only turning the pullup 'on', on A5.
0b00100000 is what you are outputting. Your 'comment' says enabling pullups on A4 and A5.
You've got to start being accurate in what you type. and debugging by testing one step at a time. |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
|
Posted: Sun Jan 22, 2017 5:21 am |
|
|
pin I use is the A5.
I tested your suggestion is the behavior is abnormal, the system will not feel the transitions on pin A5 thus remains blocked everything not in sleep mode
Code: | while(1)
{
if(Stato_Sleep==1){
disable_interrupts(GLOBAL); //so no handler is needed
port_a_pullups(0x20); // Enable pullups on pins GP5
delay_us(10);
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();
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 22, 2017 11:30 am |
|
|
Can you post the manufacturer and part number of your Hall sensor ? |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
|
Posted: Sun Jan 22, 2017 11:44 am |
|
|
12F615
I/SN1524
4DG |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
hall sensor |
Posted: Sun Jan 22, 2017 11:45 am |
|
|
HALL, For debug i put a push button with 100nF. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 22, 2017 11:57 am |
|
|
So your Hall sensor substitute circuit looks like this ?
Code: | ___ Switch
To _|_|_
PIC -----------------o o------
pin | |
A5 --- 100 nF --- GND
--- cap -
|
--- GND
-
|
And the PIC provides the pull-up ? |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
|
Posted: Sun Jan 22, 2017 12:00 pm |
|
|
yes exactly just this configuration, if necessary I can put the external pull-up |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Sun Jan 22, 2017 12:02 pm |
|
|
hmm..re: .. Hall sensor, yes we need the part number !
It is possible it requires more power than the PIC pin can supply with 'internal pullup' enabled. Or it might require 5 volts which the PIC cannot deliver. Only the sensor's datasheet will tell.
Jay |
|
|
Roberto da Rivoli
Joined: 09 Feb 2004 Posts: 37 Location: TURIN -Italy-
|
|
Posted: Sun Jan 22, 2017 12:09 pm |
|
|
I tested various types of hall since it served a lot senzibilità me, the hall sensor is not receiving power from the pic port but directly from 5Volt, absorbs about 8 mA but not from the pic.
These are two models tested
EW550 difficult to find
TLE4906L available from Farnell |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 22, 2017 12:34 pm |
|
|
But currently you are using a switch, not the Hall sensor.
Your code below is looking for the switch to be pushed. It's looking for
the button push. The idle state of the switch is a logic 1, and the pressed
down state is a logic 0.
Code: |
void read_Puls(void)
{
if(READ_HALL==0){
if(old_HALL==1){
|
Also as a comment, your port init routine should look like the code below.
You are using CCS standard i/o mode and not #fast_io() mode.
So output_a() sets both TRISA to 0x00, and PORTA to 0x00.
You don't need a separate TRIS statement.
Code: | void Set_PORT(void)
{
output_a(0x00); // Set all i/o pins to be low-level outputs
output_float(PIN_A5); // But set pin A5 (GP5) as an input
port_a_pullups(0x20); // Enable pullups on pin A5 (GP5)
}
|
Now we get to the routine below. We get into the if() statement if we got a
button press. You have some delays in your read_Puls() routine, but
it's possible for the button to still be in a down state (logic 0) when we
enter the code below.
So the PIC will execute the sleep() while the button is still down.
But then you remove your finger from the button and the PIC will see
the positive transition on Pin A5 (logic 0 to logic 1). Because the
interrupt-on-change works on both edges, you will get an interrupt and
the PIC will wake-up. So it will appear that the PIC never goes to sleep.
Some PICs have the ability to select the edge (+ or -) to use with
interrupt-on-change, but the 12F615 does not. It always interrupts on
either edge. This could be a possible source of your problem of it
not going to sleep.
Code: |
while(1)
{
if(Stato_Sleep==1){
disable_interrupts(GLOBAL); //so no handler is needed
port_a_pullups(0x20); // Enable pullups on pins GP4 and GP5
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();
} |
|
|
|
|