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

Help sorting this code.

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



Joined: 01 Mar 2010
Posts: 12

View user's profile Send private message

Help sorting this code.
PostPosted: Sat Jan 15, 2011 4:41 pm     Reply with quote

Hello everyone,

I have this code from this web site and am in need of some help sorting this out to compile.

Here is the code.
Code:
 
//***************************************************************************
//******
//****** Digital ignition for 2 stroke engines. SPORTDEVICES 4/3/2005
//******
//****** NOTE: use compiler: PCW v2.619
//******
//****** Digital parts: PIC16F84a, XTAL 4MHz
//****** Complete schematic: www.sportdevices.com/ignition/ignition.htm
//****** To ask any question: [email protected]
//******
//******
//****************************************************************************

#include  <16F84a.H>
#fuses XT,NOWDT,PUT
#use fast_io(a)
#use delay(clock=4000000)

//setup values
#define prescaler 7 //2^7=128
#define delay_multiple 8 //8 us, min 3 us
#define low_rpm_pulse true //does it generate pulses at low rpm?
#define low_rpm_multiple 40 //us, to calculate degrees at low rpm (8 * 2.5 = 40)
#define scr_pulse 500 //scr spark time, microseconds
#define pulse_polarity 0 //0-activates low
#define min_rpm 200 //min rpm value, if lower the program starts again
#define min_period 31
//********
#define max_period 60000000/(2^prescaler)/min_rpm

int const ignition0[64]=
{48,49,51,52,54,56,57,59,60,62,64,65,67,68,70,72,73,75,76,78,80,81,83,84,
86,88,89,91,92,94,96,97,99,100,102,104,105,142,145,147,149,151,153,155,157,
160,162,164,166,168,170,172,174,177,179,181,183,185,187,189,192,194,196,198};

/*int const ignition1[64]=
{22,23,25,27,29,31,33,35,37,39,41,44,46,49,51,54,56,59,62,65,68,70,73,77,80,83,86,89,
93,96,100,103,106,108,110,112,115,117,119,122,124,127,129,131,134,136,139,141,144,146,
149,151,154,157,159,162,165,167,170,173,175,178,181,184};*/

//Note: Delay values are calculated in multiples of 4 microseconds
//first value is for 15121 RPM (TMR0 count=31) and last value is for 4987 RPM (TMR0 count=94)

#define pickup PIN_B0 //pin 6
#define thyristor PIN_A2 //pin 1
#define LED PIN_A4 //pin 1
#define curve_sel PIN_B2 //pin 8

#byte TMR0=0×01
#byte PORTA=0×05
#byte PORTB=0×06
#byte INTCON=0×0b
#byte OPTION_REG=0×81

int tmr0h,perl,perh;
int16 per;

#define copy16(a,b) #asm \
movf a,w \
movwf b \
movf &a+1,w \
movwf &b+1 \
#endasm

#int_global
void int_tmr0()
{
tmr0h++;
bit_clear(INTCON,2);
}

#inline
void wait_pulse()
{
#if pulse_polarity==0
while (!input(pickup)); //wait line goes high
while (input(pickup)); //wait line goes low
#else
while (input(pickup)); //wait line goes low
while (!input(pickup)); //wait line goes high
#endif

perl=TMR0; perh=tmr0h;
TMR0=0; tmr0h=0;
}

#inline activate_SCR()
{
output_high(LED); // led off
output_high(thyristor);
delay_us(scr_pulse);
output_low(thyristor);
}

void main(){
int retardo;
boolean first=true;

INTCON=0xa0; //T0IE=1
OPTION_REG=prescaler-1; //PULLUP on, 2^prescaler=128
set_tris_a(0×01);
set_tris_b(0×05); //pin b2 input (curve selector), PIN B0 input (pickup)

output_low(LED);
delay_ms(50);
output_high(LED);
delay_ms(100);

while (true)
{

//first pulse is not processed because the period can not be calculated until the second pulse
if(first) { wait_pulse(); first=false; }

wait_pulse();

copy16(perl,per);

if ((per>=min_period)&&(per=max_period) first=true; //if rpm is too slow, engine is stoped

#if low_rpm_pulse
else
if (per>=min_period+sizeof(ignition0))
{
//do delay
perl++;
perh++;
loop2: #endasm
delay_cycles(low_rpm_multiple-3);
#asm
decfsz perl,f
goto loop2
decfsz perh,f
goto loop2
#endasm

activate_SCR();
}
#endif
}

} //while
} //main


and here is the web site http://www.sportdevices.com/ignition/ignition.htm#CDI

If someone is willing to help that would be great. If it is too much to ask I understand. Thanks.

Regards
Charlie
_________________
Regards
Charlie M
necati



Joined: 12 Sep 2003
Posts: 37
Location: istanbul

View user's profile Send private message

cdi
PostPosted: Sat Jan 15, 2011 6:19 pm     Reply with quote

//***************************************************************************
//******
//****** Digital ignition for 2 stroke engines. SPORTDEVICES 4/3/2005
//******
//****** NOTE: use compiler: PCW v2.619
//******
//****** Digital parts: PIC16F84a, XTAL 4MHz
//****** Complete schematic: www.sportdevices.com/ignition/ignition.htm
//****** To ask any question: [email protected]
//******
//******
//****************************************************************************

#include <16F84a.H>
#fuses XT,NOWDT,PUT
#use fast_io(a)
#use delay(clock=4000000)

//setup values
#define prescaler 7 //2^7=128
#define delay_multiple 8 //8 us, min 3 us
#define low_rpm_pulse true //does it generate pulses at low rpm?
#define low_rpm_multiple 40 //us, to calculate degrees at low rpm (8 * 2.5 = 40)
#define scr_pulse 500 //scr spark time, microseconds
#define pulse_polarity 0 //0-activates low
#define min_rpm 200 //min rpm value, if lower the program starts again
#define min_period 31
//********
#define max_period 60000000/(2^prescaler)/min_rpm

int const ignition0[64]=
{48,49,51,52,54,56,57,59,60,62,64,65,67,68,70,72,73,75,76,78,80,81,83,84,
86,88,89,91,92,94,96,97,99,100,102,104,105,142,145,147,149,151,153,155,157,
160,162,164,166,168,170,172,174,177,179,181,183,185,187,189,192,194,196,198};

/*int const ignition1[64]=
{22,23,25,27,29,31,33,35,37,39,41,44,46,49,51,54,56,59,62,65,68,70,73,77,80,83,86,89,
93,96,100,103,106,108,110,112,115,117,119,122,124,127,129,131,134,136,139,141,144,146,
149,151,154,157,159,162,165,167,170,173,175,178,181,184};*/

//Note: Delay values are calculated in multiples of 4 microseconds
//first value is for 15121 RPM (TMR0 count=31) and last value is for 4987 RPM (TMR0 count=94)

#define pickup PIN_B0 //pin 6
#define thyristor PIN_A2 //pin 1
#define LED PIN_A4 //pin 1
#define curve_sel PIN_B2 //pin 8

#byte TMR0=0x01
#byte PORTA=0x05
#byte PORTB=0x06
#byte INTCON=0x0b
#byte OPTION_REG=0x81

int tmr0h,perl,perh;
int16 per;

#define copy16(a,b) #asm \
movf a,w \
movwf b \
movf &a+1,w \
movwf &b+1 \
#endasm

#int_global
void int_tmr0()
{
tmr0h++;
bit_clear(INTCON,2);
}

#inline
void wait_pulse()
{
#if pulse_polarity==0
while (!input(pickup)); //wait line goes high
while (input(pickup)); //wait line goes low
#else
while (input(pickup)); //wait line goes low
while (!input(pickup)); //wait line goes high
#endif

perl=TMR0; perh=tmr0h;
TMR0=0; tmr0h=0;
}

#inline
activate_SCR(){
output_high(LED); // led off
output_high(thyristor);
delay_us(scr_pulse);
output_low(thyristor);
}

void main(){
int retardo;
boolean first=true;

INTCON=0xa0; //T0IE=1
OPTION_REG=prescaler-1; //PULLUP on, 2^prescaler=128
set_tris_a(0x01);
set_tris_b(0x05); //pin b2 input (curve selector), PIN B0 input (pickup)

output_low(LED);
delay_ms(50);
output_high(LED);
delay_ms(100);

while (true){

//first pulse is not processed because the period can not be calculated until the second pulse
if(first){wait_pulse();first=false;}

wait_pulse();

copy16(perl,per);

if((per>=min_period)&&(per=max_period)) first=true; //if rpm is too slow, engine is stoped

#if low_rpm_pulse
else
if (per>=min_period+sizeof(ignition0)){
//do delay
perl++;
perh++;
#asm
loop2:
#endasm
delay_cycles(low_rpm_multiple-3);
#asm
decfsz perl,f
goto loop2
decfsz perh,f
goto loop2
#endasm
activate_SCR();
}
#endif
} //while
} //main
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Jan 16, 2011 3:13 am     Reply with quote

I think the lesson is, if copying code, do it accurately....

90% of the failures, are simply that the times character has been substituted for the x character.

There is a fault in this line, in both versions of the code:

if((per>=min_period)&&(per=max_period)) first=true; //if rpm is too slow, engine is stopped

'=' if the C assignment operation, not the test for equality. Suggests the code as posted never worked, or if it did, had intermittent faults....

There is also one missing opening bracket in the original.

Best Wishes
Charliem



Joined: 01 Mar 2010
Posts: 12

View user's profile Send private message

PostPosted: Sun Jan 16, 2011 5:30 am     Reply with quote

Thank you for all the help.
_________________
Regards
Charlie M
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