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

Adding int8 slow down timing?

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



Joined: 14 May 2007
Posts: 33

View user's profile Send private message

Adding int8 slow down timing?
PostPosted: Fri May 25, 2007 7:31 am     Reply with quote

i use CCP compare to make 50hz square wave, the problem is if i insert the line ATT_MOT ... the signal lenght became very long (7 Hz), without this line all goes well
there are solution? optimization? or bug?
i tried many things, but when i try to add 1 to att_mot the timings became incorrect
i check frequency with proteus 7.1 sp2

i use 16f877 16mhz
ATT_MOT is int8
PCWH 4.033

thanks

#int_ccp1
void interr_ccp1() {
if (ATT_STEP) {
bit_set(PORTA_D, ATT_MOT);
ATT_TIME = MOTORI[ATT_MOT].POS_TIME;
CCP_1 = 10000;
set_timer1(0);
ATT_STEP = FALSE;
} else {
bit_clear(PORTA_D, ATT_MOT);
CCP_1 = 10000;
ATT_MOT = ++ATT_MOT % 8; <<<<----- slow down!!
set_timer1(0);
ATT_STEP = TRUE;
}
}

void main() {
int8 car;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
setup_timer_2(T2_DISABLED,0,1);

port_b_pullups(FALSE);

set_tris_a(0b00000000);
set_tris_b(0b00000000);
set_tris_c(0b10000000);// 0 = output
set_tris_d(0b00000000);
set_tris_e(0b00000000);


CCP_1=0;
set_timer1(0);
clear_interrupt(INT_CCP1);
setup_ccp1(CCP_COMPARE_INT);
enable_interrupts(INT_CCP1);

disable_interrupts(INT_TIMER0);
disable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
....
fastlink30



Joined: 14 May 2007
Posts: 33

View user's profile Send private message

PostPosted: Fri May 25, 2007 10:48 am     Reply with quote

the problem is ++ without that all is ok, but how can i solve?
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri May 25, 2007 3:21 pm     Reply with quote

for an INT8

ATT_MOT = ++ATT_MOT % 8; <<<<----- slow down!!

can be re written as

++ATT_MOT;
bit_Clear(ATT_MOT,3);

This assumes that this is the only place that the value will be incremented.

Also try

++ATT_MOT;
ATT_MOT=ATT_MOT%8;
fastlink30



Joined: 14 May 2007
Posts: 33

View user's profile Send private message

PostPosted: Sat May 26, 2007 1:42 am     Reply with quote

thank you for your reply but not solved! :(

already tried this
att_mot++;
ATT_MOT %= NUM_MOTORI;

the problem is the addiction if i leave the ++ all goes ok, if i try to do:

att_mot += 1; or
att_mot = att_mot+1;

the problem is always the same! if i look ASM

.................... CCP_1 = CICLE_LEN - ATT_TIME;
0141: MOVF 2C,W
0142: SUBWF 29,W
0143: MOVWF 15
0144: MOVF 2A,W
0145: MOVWF 16
0146: MOVF 2D,W
0147: BTFSS 03.0
0148: INCFSZ 2D,W
0149: SUBWF 16,F
.................... att_mot++;
014A: INCF 2B,F
.................... ATT_MOT %= NUM_MOTORI;
014B: MOVLW 07
014C: ANDWF 2B,F

if seem correct (i don't know exactly pic assembler)

what can be the problem? memory bank?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 26, 2007 2:52 am     Reply with quote

The reason the rate of the output signal is lower is because you're
now changing 8 pins, instead of just one pin.
The original output frequency for just one pin was 50 Hz. When you
change the code so that pin is only updated one time in 8, compared
to before, the new frequency for that pin will become 50 Hz / 8 = 6.5 Hz.
That's because each pin is updated only 1/8th as often as before.
fastlink30



Joined: 14 May 2007
Posts: 33

View user's profile Send private message

PostPosted: Sun May 27, 2007 12:50 am     Reply with quote

thank for the reply

sorry for stupid question! Embarassed
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