View previous topic :: View next topic |
Author |
Message |
saturn66661
Joined: 26 Feb 2014 Posts: 3 Location: United States
|
I can't make 12F615 work |
Posted: Wed Feb 26, 2014 7:12 pm |
|
|
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
|
|
Posted: Wed Feb 26, 2014 7:18 pm |
|
|
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
|
|
Posted: Wed Feb 26, 2014 7:28 pm |
|
|
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
|
|
|
saturn66661
Joined: 26 Feb 2014 Posts: 3 Location: United States
|
|
Posted: Wed Feb 26, 2014 8:42 pm |
|
|
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. |
|
|
|