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.

Can't access registers of dsPIC by name

Status
Not open for further replies.
Each interrupt has its own vector.

The interrupt routine called _INT1Interrupt() will catch INT1 interrupts only. It will not catch timer interrupts.
 
Right. I changed to this:
Code:
void _ISR _T1Interrupt(void)
{
   if(IEC0bits.T1IE && IFS0bits.T1IF)
   {
      counter++;  //Increment Over Flow Counter
      if(counter==30)
      {
         LATBbits.LATB0 = ~LATBbits.LATB0; // togle bit
         counter=0;  //Reset Counter
      }
      IFS0bits.T1IF = 0; // clear flag
   }
}

But the led still won't blink :((
 
You need to read the chapter on the Interrupts in the datasheet. This is an ancient PIC, so I'm not sure about it, but with newer ones the Interrupts with 0 priority are effectively disabled, and INTCON1.15 doesn't enable/disable interrupts.
 
You need to read the chapter on the Interrupts in the datasheet. This is an ancient PIC, so I'm not sure about it, but with newer ones the Interrupts with 0 priority are effectively disabled, and INTCON1.15 doesn't enable/disable interrupts.
According to the datasheet yes bit 15 of intcon1 is the GIE.
https://www.ic72.com/pdf_file/d/357620.pdf page 92
I will try setting a higher priority level for the timer1 interrupt when I get home and hope it'll work.
 
Yes you were right apparently bit15 of intcon1 does not enable global interrupts it enables nesting of interrupts.
I have downloaded all documentation of dsPIC30f2010 from microchip's site and I can't find any GIE bit specified in any of them. Is it possible that this device does not have a GIE bit?
 
There's no GIE. You need to read the section on the interrupt. They're much more complex than on PIC16/18.
Yes I know that now I read that obsolete document and in that, bit 15 of intcon1 was GIE and it confused me. I guess they changed the hardware.
Anyway this is the last version of the code which still doesn't work :(.

Code:
/* 
 * File:   main.c
 * Author: Paul
 *
 * Created on May 16, 2016, 11:22 AM
 */


#include "header.h"
#include <xc.h>

int counter;


void main()
{
    T1CONbits.TCKPS = 0x03; // prescaler is divide by 256
    T1CONbits.TCS = 0; // timer clock source is from TOSC

    IEC0bits.T1IE = 1; // enable timer1 interrupt
    // enable pher inter

    IPC0bits.T1IP2 = 1; // tmr1 inter priority = 5
    IPC0bits.T1IP1 = 0;
    IPC0bits.T1IP0 = 1;

    IFS0bits.T1IF = 0; // clear flag

    T1CONbits.TON = 1; // start the timer!

    TRISBbits.TRISB0 = 0; // b0 as output(led's here)

    while(1){}
}

void __attribute__((__interrupt__)) _T1Interrupt(void)
{
   if(IEC0bits.T1IE && IFS0bits.T1IF)
   {
      counter++;  //Increment Over Flow Counter
      if(counter==30)
      {
         LATBbits.LATB0 = ~LATBbits.LATB0; // togle bit
         counter=0;  //Reset Counter
      }
      IFS0bits.T1IF = 0; // clear flag
   }
}
 
Nothing I can spot right away except for some small stuff such as initializing PR1 register. I would suggest coming in small steps to figure out what's not working.

Setp 1. Light the LED in main and make sure it works.

Step 2. Make sure the timer runs. Set TMR1 to zero. Then read it in the infinite loop and as soon as it becomes non-zero, light the LED.

Step 3. Make sure the interrupt flag gets set. Read IFS0bits.T1IF in the infinite loop. As soon as it becomes 1, light the LED.

See which one of these fail.

Also, I would still suggest replacing all of the contents of "header.h" with the config description generated by MPLAB X.
 
XC16 requires function prototypes... before the main()
void __attribute__((__interrupt__, auto_psv))_T1Interrupt(void);
and for interrupt ....
void __attribute__((__interrupt__, auto_psv))_T1Interrupt(void)
{
your code
}

cantafford... I found the best way to learn was to check out example code either in the XC16 compiler guide , or a www search.
 
Nothing I can spot right away except for some small stuff such as initializing PR1 register. I would suggest coming in small steps to figure out what's not working.

Setp 1. Light the LED in main and make sure it works.

Step 2. Make sure the timer runs. Set TMR1 to zero. Then read it in the infinite loop and as soon as it becomes non-zero, light the LED.

Step 3. Make sure the interrupt flag gets set. Read IFS0bits.T1IF in the infinite loop. As soon as it becomes 1, light the LED.

See which one of these fail.

Also, I would still suggest replacing all of the contents of "header.h" with the config description generated by MPLAB X.

Is it possible that the code fails because I have no loaded anything into the PR1(period interrupt) register?
 
If its the same code as your other thread, then I have it working...
C:
/*
  * File:  main.c
  * Author: Paul
  *
  * Created on May 16, 2016, 11:22 AM
  */


  #include "header2.h"
  #include <xc.h>
  #define _ISRFAST __attribute__((interrupt, shadow))

  void _ISRFAST _T1Interrupt(void);

  int counter;


  int main()
  {
  TRISBbits.TRISB0 = 0;
  T1CONbits.TCKPS = 0x03; // prescaler is divide by 256
  T1CONbits.TCS = 0; // timer clock source is from TOSC

  IEC0bits.T1IE = 1; // enable timer1 interrupt
  // enable pher inter

  IPC0bits.T1IP2 = 1; // tmr1 inter priority = 0
  IPC0bits.T1IP1 = 0;
  IPC0bits.T1IP0 = 1;
  IFS0bits.T1IF = 0;
   

  T1CONbits.TON = 1; // start the timer!

  TRISBbits.TRISB0 = 0; // b0 as output(led's here)

  while(1){}
  }

  void _ISRFAST _T1Interrupt(void)
  {
  if(IEC0bits.T1IE && IFS0bits.T1IF)
  {
  counter++;  //Increment Over Flow Counter
  if(counter==30)
  {
  LATBbits.LATB0 = ~LATBbits.LATB0; // togle bit
  counter=0;  //Reset Counter
  }
  IFS0bits.T1IF = 0; // clear flag
  }
  }
 
Edit: The led blinks but not once per second as I wanted.

It was my mistake I have calculated the period of how much it stays on/off wrong.
 
Last edited:
Yes I edited it, it is working. The mistake was mine I have done the calculations wrong. Both yours and Ian's solutions were good.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top