Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 20, 2024, 01:59:40 13:59


Login with username, password and session length


Pages: [1]
Print
Author Topic: to pic mastres  (Read 3416 times)
0 Members and 1 Guest are viewing this topic.
aamir
Hero Member
*****
Offline Offline

Posts: 505

Thank You
-Given: 37
-Receive: 229


« on: June 08, 2006, 09:40:27 09:40 »

Hello
 
 
I am beginner to Pic Microcontoller .I am using timer1 to count 8 clik pulses using
 
 
interrupts and then toggle RB0 to output Frequency at RB0 should be 32 KiloHz
 
 
 
but it is 14 KiloHz only what is wrong wit code. Pic is 16f877A. frequency at TICK is
 
256KiloHz.
 
 
 
#include "D:\Timer\Timer.h"
#bit TimerOn = 0x10.0
#bit TimerFlag = 0x0C.0
#byte TimerLow = 0x0E
#BYTE TimerHigh = 0x0F
#bit Clk = 0x6.0
unsigned char Flag = 0;
void Check(void);
#use fast_io(B)
#int_TIMER1
TIMER1_isr()
{
Clk = ~Clk;or //output_toggle(Pin_b0);
set_timer1(0xFFFF);
Flag = 1;
}
 
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
TimerOn = 0;
SET_TRIS_B(0xF0 );
SET_TRIS_D(0xFF );
TimerFlag = 0;
Clk = 1;
 
set_timer1(0xFFFF);
//TimerHigh = 0xFF;
//TimerLow = 0xFF;
 
Check();
Flag = 0;
TimerOn = 1;
//while(Clk);
do
{
do
{
}while(!Flag);
 
Flag = 0;
 
}while(1);
}
void Check(void)
{
int i;
for(i = 1 ;i<10;i++)
{
output_toggle(PIN_B1);
delay_ms(100);
}
}
« Last Edit: June 08, 2006, 09:42:57 09:42 by aamir » Logged
telfo2007
Newbie
*
Offline Offline

Posts: 16

Thank You
-Given: 8
-Receive: 0


« Reply #1 on: November 21, 2007, 10:07:17 22:07 »

it could be a problem with your clock configuration. For example I used to begin with CCS compiler like this...


#include <18F4620.h>  <-- procesor type
//#device *=16

#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES HS                       //High speed Osc (> 4mhz)
#fuses INTRC_IO
//#FUSES PLL                       //High speed Osc * 4 (> 4mhz)
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPUT                    //No Power Up Timer
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOXINST

#use delay(clock=32000000)

I hope it helps you.
Bye
Logged
drovik
Newbie
*
Offline Offline

Posts: 9

Thank You
-Given: 1
-Receive: 5


« Reply #2 on: November 22, 2007, 12:54:38 12:54 »

May be PWM solve you problem Huh
Logged
vibrex2007
Newbie
*
Offline Offline

Posts: 9

Thank You
-Given: 2
-Receive: 0


WWW
« Reply #3 on: November 22, 2007, 07:47:25 19:47 »

What version of CCS do you have?
Logged

BLK
Guest
« Reply #4 on: January 03, 2008, 04:01:02 16:01 »

the clock is 256 divide with 32 = 8, divide with 2 is 4
                    setup_timer_1(T1_EXTERNAL|T1_DIV_BY_4);
for intrerupt use fast code :
            #int_global
             isr()
or #int_xxx FAST


#include <16F877A.h>
#use delay (clock=20000000)
#bit TimerOn = 0x10.0
#bit TimerFlag = 0x0C.0
#byte TimerLow = 0x0E
#BYTE TimerHigh = 0x0F
#bit Clk = 0x6.0
unsigned char Flag = 0;
void Check(void);
#use fast_io(B)

#int_global
isr()
{
   TimerFlag = 1;
   Clk = ~Clk; //output_toggle(Pin_b0);
   Flag = 0;
   set_timer1(0xFFFF);   
   TimerFlag = 0;
}
 
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_4);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
TimerOn = 0;
SET_TRIS_B(0xF0 );
SET_TRIS_D(0xFF );
TimerFlag = 0;
Clk = 1;
 
set_timer1(0xFFFF);

// Check();
Flag = 0;
TimerOn = 1;
do{
   do{ }while(!Flag);
 
   Flag = 0;
  }while(1);
}

void Check(void)
{
   int i;   
   for(i = 1 ;i<10;i++)
      {
         output_toggle(PIN_B1);
         delay_ms(1);
      }
}
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC