CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

wake-up PIC12f615 don't Work
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 18, 2017 12:44 pm     Reply with quote

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-

View user's profile Send private message Send e-mail

sleep
PostPosted: Wed Jan 18, 2017 1:42 pm     Reply with quote

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: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 18, 2017 3:07 pm     Reply with quote

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-

View user's profile Send private message Send e-mail

sleep 1 time
PostPosted: Thu Jan 19, 2017 4:00 am     Reply with quote

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-

View user's profile Send private message Send e-mail

pic12f615 sleep don't work
PostPosted: Sun Jan 22, 2017 4:44 am     Reply with quote

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: 19535

View user's profile Send private message

PostPosted: Sun Jan 22, 2017 4:52 am     Reply with quote

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-

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 22, 2017 5:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 22, 2017 11:30 am     Reply with quote

Can you post the manufacturer and part number of your Hall sensor ?
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 22, 2017 11:44 am     Reply with quote

12F615
I/SN1524
4DG
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

hall sensor
PostPosted: Sun Jan 22, 2017 11:45 am     Reply with quote

HALL, For debug i put a push button with 100nF.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 22, 2017 11:57 am     Reply with quote

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-

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 22, 2017 12:00 pm     Reply with quote

yes exactly just this configuration, if necessary I can put the external pull-up
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 22, 2017 12:02 pm     Reply with quote

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-

View user's profile Send private message Send e-mail

PostPosted: Sun Jan 22, 2017 12:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 22, 2017 12:34 pm     Reply with quote

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();
  }
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
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