Dspic30f2010 Reset Problem

Discussion in 'Embedded Systems and Microcontrollers' started by rmrps, Nov 30, 2012.

  1. rmrps

    Thread Starter New Member

    Feb 24, 2012
    17
    0
    Hi Friends I am using dspic30f2010 microcontroller with 12.288Mhz i want to sense the ac voltage this is my code in that i am using timer interrupt for sense the analog input the problem is the devise get reset please give me the suggestion where to change the code also give me the suggestion some other methods to sense the ac voltage thanks in advance

    Code ( (Unknown Language)):
    1.  
    2. int main(void)
    3. {
    4.  
    5. TRISB=0xFF;
    6. TRISE=0x00;
    7. Lcd_Initialize() ;
    8.  
    9. ADCON1 = 0;
    10. ADCON2 = 0;
    11. ADCON3 = 0x9;
    12. ADPCFG = 0x0;
    13. ADCHS = 0x07;
    14. ADCON1bits.ADON = 1;
    15.  
    16. R_Ph_Rms_Vol=0;
    17. Phase_interrupt =0;
    18.  
    19. T1CON=0;
    20. TMR1=0;
    21. PR1=16000;
    22. IFS0bits.T1IF=0;
    23. IPC0bits.T1IP=4;
    24. IEC0bits.T1IE=1;
    25. T1CONbits.TCS = 0;
    26. T1CON=0x8000;
    27.  
    28. while(1)
    29. {
    30.  
    31. if(Time_Update==1)
    32. {
    33.  
    34. for(R_i=0;R_i<20;R_i++)
    35. {
    36. R_Ph_Voltage[R_i] = R_Ph_Voltage[R_i]-512;
    37. R_Ph_Ana_Vol[R_i] = (R_Ph_Voltage[R_i]*5.0)/1023.0;    
    38. R_Ph_Ana_Vol[R_i] = R_Ph_Ana_Vol[R_i] * R_Ph_Ana_Vol[R_i];
    39. }
    40. R_Ph_Rms_Vol = 0;
    41.  
    42. for(R_i=0;R_i<20;R_i++)
    43. {
    44. R_Ph_Rms_Vol = R_Ph_Rms_Vol + R_Ph_Ana_Vol[R_i];    
    45. }
    46. R_Phase = R_Ph_Rms_Vol;     R_Phase = sqrt(R_Phase/20.0);
    47. R_Phase = R_Phase *284.00;
    48. Phase1 = (int)R_Phase;
    49.  
    50. R_Ph_Rms_Vol=0;
    51. Phase_interrupt =0;
    52.  
    53. k=Phase1;
    54. l=k/1000; Status1[6] = l + 48; k=k%1000;
    55. l=k/100; Status1[7] = l + 48; k=k%100;
    56. l=k/10; Status1[8] = l + 48; k=k%10;
    57. Status1[9] = k + 48;
    58.  
    59. Lcd_Command(0x80);
    60. for(l=0;l<=18;l++)
    61. {
    62. Lcd_Send_data(Status1[l]);
    63. }    
    64. Time_Update = Time_Update & 0x01;
    65.  
    66. }
    67. }
    68. return (0);
    69.  
    70. }
    71.  
    72.  
    73. void __attribute__((interrupt,auto_psv)) _T1Interrupt(void)
    74. {
    75. IFS0bits.T1IF = 0;
    76. if(Phase_interrupt!=20)
    77. {
    78. R_Ph_Voltage[Phase_interrupt] = Read_Adc(0);
    79. Phase_interrupt++;
    80. }
    81. }
    82.  
    83. int Read_Adc(int channel)
    84. {
    85. unsigned char Delay=0;
    86. if(channel > 0x000F) return(0);
    87. ADCHS = channel;
    88. ADCON1bits.SAMP = 1;
    89. for(Delay = 0; Delay < 5; Delay++);
    90. IFS0bits.ADIF = 0;
    91. ADCON1bits.SAMP = 0;
    92. while(!IFS0bits.ADIF);
    93. return(ADCBUF0);
    94. }
    95.  
     
    Last edited by a moderator: Nov 30, 2012
Loading...