|
|
View previous topic :: View next topic |
Author |
Message |
marceleza
Joined: 24 May 2006 Posts: 6 Location: S㯠Paulo - Brazil
|
Problem with timer 1 in PIC18F2450 |
Posted: Mon Dec 14, 2009 10:48 am |
|
|
Hello!
I made this code:
Code: |
#INCLUDE <18F2450.h>
//#fuses HS,NOWDT,NOPUT,NOPROTECT,BROWNOUT,BORV43,MCLR,NODEBUG,NOLVP,NOUSBDIV
#FUSES NOWDT
#FUSES WDT128
#FUSES HSPLL
#FUSES NOPROTECT
#FUSES NOBROWNOUT
#FUSES BORV20
#FUSES PUT
#FUSES NOVREGEN
#FUSES STVREN
#FUSES NODEBUG
#FUSES NOLVP
#FUSES NOWRT
#FUSES NOLPT1OSC
#FUSES IESO
#FUSES FCMEN
#FUSES NOPBADEN
#FUSES BBSIZ2K
#FUSES NOWRTC,NOWRTB,NOEBTR,NOEBTRB,NOCPB,MCLR,NOXINST,PLL3,NOUSBDIV,CPUDIV2
#device adc=10 // ad 10 bits
#use delay(clock=10000000)
#zero_ram
#int_timer1
void espera(void);
VOID main()
{
setup_oscillator(OSC_STATE_EXT_RUNNING); //
setup_adc_ports (AN0_TO_AN2); //
setup_adc (ADC_CLOCK_DIV_8); //
setup_ccp1 (ccp_off); //ccp desligado
setup_timer_0 (rtcc_div_2 | rtcc_8_bit | rtcc_internal ); //tempo de 204us era rtcc div2
setup_timer_1 (T1_DIV_BY_1 | T1_internal );
set_timer0 (0);
// set_timer1 (0);
disable_interrupts(int_timer0);
enable_interrupts(INT_TIMER1);
disable_interrupts(int_ext);
disable_interrupts(int_rb);
disable_interrupts(INT_rda);
EXT_INT_EDGE(H_TO_L);
#INT_TIMER1 // tempo de duracao das telas
void espera() //
{
byte temp;
temp++;
}
|
But the timer don´t work in mpsim. I am using the mplab 8.33 and ccs 4.064.
The timer count only in 8 bits, don't generate the overflow!
Thanks |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Dec 14, 2009 11:20 am |
|
|
Try adding:
enable_interrupts(GLOBAL);
If global is not enabled then NO interrupt will happen.
Ronald |
|
|
Ttelmah Guest
|
|
Posted: Mon Dec 14, 2009 11:40 am |
|
|
Also, on not seeing 16bts in use, CCS sets up the timer to operate in 16bit R/W mode. To 'see' the top byte update, you have to perform a read from the low byte, which then latches the high byte value into the top byte. Generally you will need to add an instruction to your code, to read the low byte, before the simulator will update the high byte.
Best Wishes |
|
|
marceleza
Joined: 24 May 2006 Posts: 6 Location: S㯠Paulo - Brazil
|
|
Posted: Mon Dec 14, 2009 12:17 pm |
|
|
ok, thanks for the answer, but I don't understand how to do this.
In real operation (pic in board), the counter will work?
best regards
marcelo |
|
|
|
|
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
|