Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC18f97j60 and reading the contents of counter0

Status
Not open for further replies.

Bluestar88

Member level 3
Member level 3
Joined
Oct 17, 2014
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
447
I am doing Counter0 (T0Ck1) of PIC18f97j60 and I want to read the number of pulses which inters to it.
For this purpose, I Initialized the timer0 in counter mode and I produced PWM1 (from pin ECCP1) in Mikroc Program and I connected ECCPI to T0CK1 with a wire. But when I reade TMR0L is it 130 all of the times and It doesn't change. My code is here. I expect the TMR0L increments with rising time not fixed in 130. Please Help me. I am really confused.
Code:
unsigned short current_duty=128;
char receive;

 char buffer[16];
      volatile char count=0;



void main() {
        ADCON1 = 0x0B ;         // ADC convertors will be used with AN2 and AN3
        CMCON  = 0x07 ;         // turn off comparators

        PORTA = 0 ;
        TRISA = 0xfc ;          // set PORTA as input for ADC
                                // except RA0 and RA1 which will be used as
                                // ethernet's LEDA and LEDB
                                
      TRISA.RA4 = 1;     //make RA4/TOCKI an input
     // T0CON = 0X28;        //Counter 0, 16-bit mode, no prescaler
      TMR0H = 0;
      TMR0L = 0;       //set count to 0

      //  PORTB = 0 ;
        TRISB = 0xff ;          // set PORTB as input for buttons



        // PORTC = 0;                          // set PORTC to 0
        // TRISC = 0;                          // designate PORTC pins as output


        PORTD = 0 ;
        TRISD = 0 ;             // set PORTD as output



         UART1_Init(9600);
         Delay_ms(100);                  // Wait for UART module to stabilize

         PWM1_Init(500);                    // Initialize PWM1 module at 5KHz



  while(1)
                  {

                    PORTD.RD4=1;
                    PORTD.RD5=1;
                    PWM1_Start();                       // start PWM1
                    PWM1_Set_Duty(current_duty);        // Set current duty for PWM1
                  
                    T0CON.TMR0ON = 1;       //turn on T0
                    T0CON.T08BIT= 1;         //8bit
                    T0CON.T0CS=1;            // Timer0 Clock Source Select bit
                    T0CON.T0SE=1;            //Timer0 Source Edge Select bit
                    T0CON.PSA=1;             // Timer0 Prescaler Assignment bit
                    
   
                   UART1_Write(TMR0L);

                   
                    }
                    }

            

                }

}
 

I don't know what 'PWM1_Start() and the like functions do but I would take all of that code out of the main 'while' loop.
While it should not affect the operation of the timer, you should also take all of the code that initialises the timer out of the main loop as well. Also the best practice is to turn off the timer, set it up completely and then turn it on again.
As to why you always get "130" I must admit I'm not sure but a little bit of time with the debugger should show you. Also I would simplify the code to just using Timer 0 and possibly an internal clock source to start with and then add in the other parts later.
Susan
 
Can you please let others know what the actual problem was and how you solved it?
Susan
 

Yeah, Sure.
I had a problem in hardware. I didn't connect PWM to 42 Pin of pic18f97j60. The output of timer0 is 42 pin of pic18f97j60.

- - - Updated - - -

Yeah, Sure.
I had a problem in hardware. I didn't connect PWM to 42 Pin of pic18f97j60. The output of timer0 is 42 pin of pic18f97j60.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top