Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Timer0 breakpoint

Status
Not open for further replies.

jab99407

Member
I have question in context of debugging. On which line should I set breakpoint so that I can know how much time period Timer0 generate
Code:
#include<pic.h>
int Count=0;
void main(void)
{
    TMR0=0;        //TMR0 Initiation
    T0CS=0;        //Choosing to work with internal clk
    T0SE=0;        //Reacting on Low2High edge
    PSA=0;         //Choosing to work with a Prescaler
    PS0=1;
    PS1=1;         //Prescaler value divides 256
    PS2=1;
    while(1)
    {
        while(!T0IF);        //Stays here 256 times and then T0IF=1
        T0IF=0;              //Resetting the overflow flag
        Count++;             //Increasing by 1
        if(Count==15)
        {
            Count=0;          //when count reaches 15 - Resetting to 0
        }
     }
 }
 
I would place the breakpoint anywhere in the loop, then you can measure the time of the timer overflow AND the extra line of code.

But!!! The breakpoint at the line Count=0; will be the 15 timer overflows if that's the time taken you mean..
 
I would place the breakpoint anywhere in the loop, then you can measure the time of the timer overflow AND the extra line of code.

But!!! The breakpoint at the line Count=0; will be the 15 timer overflows if that's the time taken you mean..

Ian Rogers

There are two options Step Over Step Into What's basic difference between them ? https://microchipdeveloper.com/mplabx:debug-toolbar

When do you use step into and step over option in debugging ?

if I set breakpoint at line 46 and use step into button. What line the program will execute ?

C:
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)


#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ

#include <xc.h>

volatile unsigned int count = 0;

void main(void)
{
   //Make all PORTD pins low
   PORTA = 0x00;
   PORTB = 0x00;
   PORTC = 0x00;
   PORTD = 0x00;
   PORTE = 0x00;

// Configured PORT pins as Output
   TRISA = 0x00;
   TRISB = 0x00;
   TRISC = 0x00;
   TRISD = 0x00;
   TRISE = 0x00;

    // Timer0 with internal instruction clock  and 64 as prescalar
    OPTION_REG = 0b00000101;

    TMR0 = 0;                   // Load the time value
    GIE = 0;                    //Clear Global Interrupt
    TMR0IF = 0;                 // clear timer interrupt flag updated line
    TMR0IE = 1;                 //Enable timer interrupt bit

    while(1)
    {
      if( TMR0IF == 1 )
       {
          count++;
          TMR0IF=0;       // Clear timer interrupt flag
       }
    }
    return;
}
 
Step over is to miss out functions.. if you know the function works you step over.. ie math routines..
Step into is to just accept these functions work as expected...
Step out is when you entered a function by mistake... Stepping out takes you back to the calling code.

if I set breakpoint at line 46 and use step into button. What line the program will execute ?
What!! There is no line numbers..

If you place a breakpoint at:-
count++;
then step over OR into the next line will be TMR0IF = 0;
If you do it at:-
TMR0IF = 0; the next execution is count++;
 
Set a breakpoint anywhere in the loop set timer0 to zero when it breaks, press F5 and see what it contains when it hits the breakpoint again.

Mike.
Edit, I'm going to have a wild guess at 64*256 or 16384. Just a guess. It won't, of course, contain that but will contain zero (+instructions past the check) but 16384 instruction cycles will have been executed.
Edit2, you seem to have your prescaler at 256 so 65536 cycles.
Edit3, actually, you seem to have both prescalers.
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top