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

16F877 timer2 (thanks Tomy for I2C)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Renato and Davide
Guest







16F877 timer2 (thanks Tomy for I2C)
PostPosted: Thu Nov 15, 2001 4:24 am     Reply with quote

---------------------------------------------------------------
For Tomy: a lot of thanks for I2C help. The mistake was the PIC wizard instraction: setup_spi (FALSE); ours code is correct without setup_spi (FALSE).
---------------------------------------------------------------

* We have now a problem with timer2. We have set timer2 in this way:

setup_timer_2(T2_DIV_BY_16,125,1);

We need an interrupt timer every 1 ms but we have seen thet if we write:

setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_wdt(WDT_2304MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,125,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
enable_interrupts(INT_EEPROM);
enable_interrupts(INT_TIMER2);
enable_interrupts(INT_RDA);
enable_interrupts(INT_ADC);
enable_interrupts(INT_SSP);
enable_interrupts(global);

we have an interrupt every 13 ms.

The ASM code for setup_wdt(WDT_2304MS) and setup_timer_2(T2_DIV_BY_16,125,1) is:
.................... setup_wdt(WDT_2304MS);
0D43: MOVLW 0F
0D44: MOVWF 77
0D45: MOVLW 07
0D46: BCF 03.5
0D47: CLRF 01
0D48: MOVLW 81
0D49: MOVWF 04
0D4A: BCF 03.7
0D4B: MOVF 00,W
0D4C: ANDLW C0
0D4D: IORLW 0F
0D4E: MOVWF 00
0D4F: CLRWDT
0D50: MOVLW 81
0D51: MOVWF 04
0D52: MOVF 00,W
0D53: ANDLW C0
0D54: IORWF 77,W
0D55: MOVWF 00
.................... setup_timer_1(T1_DISABLED);
0D56: CLRF 10
.................... setup_timer_2(T2_DIV_BY_16,125,1);
0D57: MOVLW 00
0D58: BCF 03.0
0D59: RLF 00,W
0D5A: MOVWF 77
0D5B: RLF 77,F
0D5C: RLF 77,F
0D5D: MOVLW F8
0D5E: ANDWF 77,F
0D5F: MOVF 77,W
0D60: MOVWF 78
0D61: IORLW 06
0D62: MOVWF 12
0D63: MOVLW 7D //The mistake seems to be here
0D64: BSF 03.5
0D65: MOVWF 12


*********************************************

If we traslate setup_timer_2 instraction in first position:

setup_timer_2(T2_DIV_BY_16,125,1);
setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,WDT_2304MS);
setup_wdt(WDT_2304MS);
setup_timer_1(T1_DISABLED);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
enable_interrupts(INT_EEPROM);
enable_interrupts(INT_TIMER2);
enable_interrupts(INT_RDA);
enable_interrupts(INT_ADC);
enable_interrupts(INT_SSP);
enable_interrupts(global);

we have an interrupt every 8 ms.

******************************************

if we comment setup_wdt(WDT_2304MS);

we have an interrupt every 5 ms.

********************************************

- WHAT WE HAVE TO DO TO HAVE ONE INTERRUPT EVERY 1 ms WITH
TIMER2 ?

IDE Version = 2.32
PCB Version = 3.043
PCM Version = 3.043
Thank you for the support. Best regards
___________________________
This message was ported from CCS's old forum
Original Post ID: 1118
Tomi
Guest







Re: 16F877 timer2 (thanks Tomy for I2C)
PostPosted: Thu Nov 15, 2001 11:41 am     Reply with quote

I think you have found a compiler error. To manually override the problem, try this instead of the "setup_timer_2(T2_DIV_BY_16,125,1);" line:
*0x12 = 6; // post-scaler 1:1, timer2 enabled, prescaler=16
*0x92 = 0x7D; // load 125 to PR2


:=--------------------------------------------------------------The mistake was the PIC wizard instraction

I never use wizards: I like to keep the control in my hand.

Brg,
Tomi
___________________________
This message was ported from CCS's old forum
Original Post ID: 1129
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