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 support@ccsinfo.com

I can't make 12F615 work

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
saturn66661



Joined: 26 Feb 2014
Posts: 3
Location: United States

View user's profile Send private message

I can't make 12F615 work
PostPosted: Wed Feb 26, 2014 7:12 pm     Reply with quote

This is the 1st time I wrote code to do something. I'd like to
control PWM duty cycle using external interrupt. I adopt 12F615
which is cheap. The code pass compile and program in chip
successfully. After I put it in prototype PCB, I found nothing happened.
The code:
Code:

#include <12F615.h>
// fuses setup
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES IOSC4 //INTOSC speed 4 MHz
#FUSES MCLR //Master Clear pin used
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#USE delay(clock=4000000)
// PWM enable, turn on 50% duty for 1 sec. Pin_A4 pull high and variables init
int1 flip=1, deltacyc=0;
int8 i;
int16 cycle=0;
//Main
void main(void)
{
  output_high(PIN_A4);
  setup_ccp1(CCP_PWM);
  setup_ccp1(CCP_SHUTDOWN_ON_COMP_INT0);
  setup_ccp1(CCP_P1A_A5);
  setup_timer_2(T2_DIV_BY_4, 64, 1);
  set_pwm1_duty(500L);
  delay_ms(999);
  set_pwm1_duty(0);
  sense: delay_ms(1);
  //if (flip)
       ext_int_edge(L_TO_H);
  //else
       ext_int_edge(H_TO_L);   
   clear_interrupt(INT_EXT);
   enable_interrupts(global);
   enable_interrupts(INT_EXT);
 while(deltacyc)
 {
  for(i=0;i<6;++i)
   {
    delay_ms(500);
    cycle+=deltacyc*200;
    while(cycle>1000)
      cycle=0;
    set_pwm1_duty(cycle);
    }
   }
goto sense;
}

//External interrupt setup
#int_ext
void edge_handler(void)
{
   if (flip)
   {
       deltacyc=1;
       flip=0;
   }
   else
   {
       deltacyc=0;
       flip=1;
   } 
}

After it failed, I use PICDEM2 PLUS w/877A on it and wrote a similiar code
and it works.
The code:
Code:

#include <16F877A.h>
// fuses setup
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES HS //HS speed 4 MHz
//#FUSES MCLR //Master Clear pin used
#FUSES NOBROWNOUT //No brownout reset
#FUSES PUT //Power Up Timer
#FUSES NOLVP //No LVP
#USE delay(clock=4000000)
// PWM enable, turn on 50% duty for 1 sec. Pin_A4 pull high and variables init
int1 flip=1, deltacyc=0;
int8 i;
int16 cycle=0;
//Main
void main(void)
{
  //output_high(PIN_B1);
 // delay_ms(999);
  //output_low(PIN_B1);
  setup_timer_2(T2_DIV_BY_1,249,1); 
  setup_ccp1(CCP_PWM);
  set_pwm1_duty(500L);
  delay_ms(999);
  set_pwm1_duty(0);
  sense: delay_ms(1);
 //if (flip)
       ext_int_edge(L_TO_H);
   //else
       ext_int_edge(H_TO_L);   
   clear_interrupt(INT_EXT);
   enable_interrupts(global);
   enable_interrupts(INT_EXT);
 while(deltacyc)
 {
  //output_high(PIN_B1);
  //delay_ms(999);
  //output_low(PIN_B1);
  for(i=0;i<51;++i)
   {
    //output_high(PIN_B2);
    //delay_ms(200);
    //output_low(PIN_B2);
    delay_ms(80);
    cycle+=deltacyc*20;
    while(cycle>1000)
      cycle=0;
    set_pwm1_duty(cycle);
    }
   }
output_high(PIN_B3);
delay_ms(999);
output_low(PIN_B3);
goto sense;
while(1);
}

//External interrupt setup
#int_ext
void edge_handler(void)
{
   if (flip)
   {
       deltacyc=1;
       flip=0;
       //output_high(PIN_B1);
       //delay_ms(10);
       //output_low(PIN_B1);
   }
   else
   {
       deltacyc=0;
       flip=1;
       //output_high(PIN_B2);
       //delay_ms(10);
       //output_low(PIN_B2);
   } 
}

Can someone help me to check it? Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 26, 2014 7:18 pm     Reply with quote

Quote:

setup_ccp1(CCP_PWM);
setup_ccp1(CCP_SHUTDOWN_ON_COMP_INT0);
setup_ccp1(CCP_P1A_A5);

This code above is wrong. There is no sequential setup of PWM.
You must combine the parameters in one call to setup_ccp1().
The 12F615.h file says:
Quote:

// The following should be used with the ECCP unit only (or these in)

I would have said: OR these together with |.
or Combine these parameters with the bitwise OR symbol: |
saturn66661



Joined: 26 Feb 2014
Posts: 3
Location: United States

View user's profile Send private message

PostPosted: Wed Feb 26, 2014 7:28 pm     Reply with quote

Thanks for the prompt reply.
I did try to put all 3 in one command. It can't be recognized.
If I put 2 in one command, it can be recognized but still didn't work.
Because it is 8-pin chip, it seems quite difficult to do pin assignments
using CCS. Should I insert ASM code in it in order to solve this issue?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 26, 2014 8:18 pm     Reply with quote

Post your CCS compiler version. It's given at the top of the .LST file.
Example of version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
saturn66661



Joined: 26 Feb 2014
Posts: 3
Location: United States

View user's profile Send private message

PostPosted: Wed Feb 26, 2014 8:42 pm     Reply with quote

Sorry. I am program newb. I don't even know where to find it. I wrote the program just after read some posts in this forum ( it really help ).
I use MPLAB V8.92 with CCS plug in.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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