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.

could not get the output in Proteus simulation using DSPIC33FJ32GP204

Status
Not open for further replies.

Shanmuga.sndrmv

Newbie level 4
Joined
Dec 29, 2017
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
72
Dear Friends,

I am new to dsPIC33F ICs and trying to workout with Proteus simulation, in this I use dsPIC33FJ32GP204 ICs, I am trying to Blink LED using Proteus simulation, but it is not working. I have used PMD1 (Peripheral module disable register) for Digital port Access.
 

Hi,

Maybe your code is wrong --> show your code
Maybe your schematic is wrong --> shiw your schematic

Klaus
 

dsPIC33F Code and Attached Schematic

Code:
/* Main.c file generated by New Project wizard
 *
 * Created:   Fri Dec 29 2017
 * Processor: dsPIC33FJ32GP204
 * Compiler:  MPLAB XC16
 */

/* Main.c file generated by New Project wizard
 *
 * Created:   Thu Dec 28 2017
 * Processor: dsPIC33FJ32GP204
 * Compiler:  MPLAB XC16
 */

// DSPIC33FJ32GP204 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// FBS
#pragma config BWRP = WRPROTECT_OFF     // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH           // Boot Segment Program Flash Code Protection (No Boot program Flash segment)

// FGS
#pragma config GWRP = OFF               // General Code Segment Write Protect (User program memory is not write-protected)
#pragma config GSS = HIGH               // General Segment Code Protection (High Security Code Protection is Enabled)

// FOSCSEL
#pragma config FNOSC = PRIPLL           // Oscillator Mode (Primary Oscillator (XT, HS, EC) w/ PLL)
#pragma config IESO = OFF               // Internal External Switch Over Mode (Start-up device with user-selected oscillator source)

// FOSC
#pragma config POSCMD = HS              // Primary Oscillator Source (HS Oscillator Mode)
#pragma config OSCIOFNC = OFF           // OSC2 Pin Function (OSC2 pin has clock out function)
#pragma config IOL1WAY = OFF            // Peripheral Pin Select Configuration (Allow Multiple Re-configurations)
#pragma config FCKSM = CSECME           // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are enabled)

// FWDT
#pragma config WDTPOST = PS4096         // Watchdog Timer Postscaler (1:4,096)
#pragma config WDTPRE = PR32            // WDT Prescaler (1:32)
#pragma config WINDIS = OFF             // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software)

// FPOR
#pragma config FPWRT = PWR128           // POR Timer Value (128ms)
#pragma config ALTI2C = OFF             // Alternate I2C  pins (I2C mapped to SDA1/SCL1 pins)

// FICD
#pragma config ICS = PGD1               // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
#pragma config JTAGEN = OFF             // JTAG Port Enable (JTAG is Disabled)


//Definitions
#define SW1    PORTCbits.RC0
#define LED1    PORTBbits.RB3

#define ON    1
#define OFF    0


//User Defined Funtions
void Init_Ports(void);
unsigned int i;


int main (void)
 { 
    Init_Ports();
   // Write your code here
   for(;;)
   {
      LED1 ^=1;    
     for(i=0;i<=65535;i++);
      /*if(SW1)
      {
    LED1    =  ON;     
      }
      else
      {
    LED1    =  OFF;     
      }*/
     
   }
   return 0;
 }   
 
 
 void Init_Ports(void)
 {
    PMD1bits.AD1MD = 1;
    TRISC = 0x00FF;
    PORTC = 0x0000;
    TRISBbits.TRISB3 = 0;
    PORTBbits.RB3 = 0;
} Sch.PNG
 

Re: dsPIC33F Code and Attached Schematic

Code not running in Proteus Simulaion, I am new to dsPIC
 

Re: dsPIC33F Code and Attached Schematic

Even if it will work, resistance value should be reduced 10000 times. But cleaver way is to use digital primitives, not analog once.
 

There are two problems in your code.

Your wait loop is infinite.
Code:
for(i=0;i<=65535;i++);
Try i<65535

RB3 is set as analog input by default, thus reading PORTBbits.RB3 always returns zero.

You can either setup RB3 as digital port through AD1PCFGL or manipulate LATB instead of PORTB.
Code:
#define LED1    LATBbits.LATB3

- - - Updated - - -

To debug the code yourself, you can perform source level debugging in Proteus, importing the xc16 .cof file. But debugging is probably much more comfortable with MPLAB simulator.
 
Code:
AD1PCFGL

not configured. Analog function has to be disabled and Led pin has to be made digital output pin.

dsPIC33 doesn't run at 5V VDD. By default VDD in "configure Power Rails" of Proteus will be 5V. You have to change it to 3.3V or 3.6V for working with dsPIC33.
 
Last edited:

AD1PCFGL not configured. Analog function has to be disabled and Led pin has to be made digital output pin.
LED pin is already configure as output in the code. Default AD1PCFGL=0 doesn't prevent output function, just blocks port read-back.

dsPIC33 doesn't run at 5V VDD. By default VDD in "configure Power Rails" of Proteus will be 5V. You have to change it to 3.3V or 3.6V for working with dsPIC33.
Proteus hardly cares about...
 

There are two problems in your code.

Your wait loop is infinite.
Code:
for(i=0;i<=65535;i++);
Try i<65535

RB3 is set as analog input by default, thus reading PORTBbits.RB3 always returns zero.

You can either setup RB3 as digital port through AD1PCFGL or manipulate LATB instead of PORTB.
Code:
#define LED1    LATBbits.LATB3

- - - Updated - - -

To debug the code yourself, you can perform source level debugging in Proteus, importing the xc16 .cof file. But debugging is probably much more comfortable with MPLAB simulator.

Thanks FvM.

You are right. for loop state is infinite, so that it is not running.
 

dsPIC33FJ32GP204 Timer1 is configured using datasheet but not working

Today I Configured, Timer1 using datasheet in dsPIC for 1ms. but not working. Below is my code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* Main.c file generated by New Project wizard
 *
 * Created:   Fri Dec 29 2017
 * Processor: dsPIC33FJ32GP204
 * Compiler:  MPLAB XC16
 */
 
/* Main.c file generated by New Project wizard
 *
 * Created:   Thu Dec 28 2017
 * Processor: dsPIC33FJ32GP204
 * Compiler:  MPLAB XC16
 */
 
// DSPIC33FJ32GP204 Configuration Bit Settings
 
// 'C' source line config statements
 
#include <xc.h>
 
// FBS
#pragma config BWRP = WRPROTECT_OFF     // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH           // Boot Segment Program Flash Code Protection (No Boot program Flash segment)
 
// FGS
#pragma config GWRP = OFF               // General Code Segment Write Protect (User program memory is not write-protected)
#pragma config GSS = HIGH               // General Segment Code Protection (High Security Code Protection is Enabled)
 
// FOSCSEL
#pragma config FNOSC = PRIPLL           // Oscillator Mode (Primary Oscillator (XT, HS, EC) w/ PLL)
#pragma config IESO = OFF               // Internal External Switch Over Mode (Start-up device with user-selected oscillator source)
 
// FOSC
#pragma config POSCMD = HS              // Primary Oscillator Source (HS Oscillator Mode)
#pragma config OSCIOFNC = OFF           // OSC2 Pin Function (OSC2 pin has clock out function)
#pragma config IOL1WAY = OFF            // Peripheral Pin Select Configuration (Allow Multiple Re-configurations)
#pragma config FCKSM = CSECME           // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are enabled)
 
// FWDT
#pragma config WDTPOST = PS4096         // Watchdog Timer Postscaler (1:4,096)
#pragma config WDTPRE = PR32            // WDT Prescaler (1:32)
#pragma config WINDIS = OFF             // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software)
 
// FPOR
#pragma config FPWRT = PWR128           // POR Timer Value (128ms)
#pragma config ALTI2C = OFF             // Alternate I2C  pins (I2C mapped to SDA1/SCL1 pins)
 
// FICD
#pragma config ICS = PGD1               // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
#pragma config JTAGEN = OFF             // JTAG Port Enable (JTAG is Disabled)
 
 
//Definitions
#define SW1 PORTCbits.RC0
#define SW2 PORTCbits.RC1
#define SW3 PORTCbits.RC2
#define SW4 PORTCbits.RC3
 
 
#define LED1    LATBbits.LATB0
#define LED2    LATBbits.LATB1
#define LED3    LATBbits.LATB2
#define LED4    LATBbits.LATB3
 
#define ON  1
#define OFF 0
 
 
//User Defined Funtions
void Init_Ports(void);
void Init_Timer1(void);
void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void);
 
unsigned int i;
 
 
int main (void)
 { 
    Init_Ports();
    Init_Timer1();
   // Write your code here
   for(;;)
   {
      if(SW1)LED1   =  ON;  
      else LED1 =  OFF;  
     
      if(SW2)LED2   =  ON;  
      else LED2 =  OFF;  
     
      if(SW3)LED3   =  ON;  
      else LED3 =  OFF;  
     
      if(SW4)LED4   =  ON;  
      else LED4 =  OFF;  
   }
   return 0;
 }   
 
 
 void __attribute__((__interrupt__, no_auto_psv)) _T1Interrupt(void)
 {
    static unsigned int T1_Cnt = 0;
   if(IFS0bits.T1IF)
     {
    IFS0bits.T1IF = 0;
    if(T1_Cnt > 100)
    {
       T1_Cnt = 0;
       LED1 = ~LED1;
    }
     else T1_Cnt++;
     }   
 }
 
 void Init_Ports(void)
 {
    PMD1bits.AD1MD = 1;
    TRISC = 0x00FF;
    PORTC = 0x0000;
    TRISB = 0x0000;
    PORTB = 0x0000;
    LATB = 0x00;
 }
 
 void Init_Timer1(void)
 {
   PMD1bits.T1MD = 0;   
   INTCON1bits.NSTDIS = 0; 
   T1CONbits.TCKPS1 = 0;
   T1CONbits.TCKPS0 = 0;
   T1CONbits.TSIDL = 0;
   T1CONbits.TCS = 0;  
   T1CONbits.TGATE = 0; 
   T1CONbits.TSYNC = 0; 
   PR1 = 2500;
   IFS0bits.T1IF = 0;
   IEC0bits.T1IE = 1;   
   IPC0bits.T1IP2 = 1;
   IPC0bits.T1IP1 = 1;
   IPC0bits.T1IP0 = 1;
   T1CONbits.TON = 1;
 }

 
Last edited by a moderator:

Re: dsPIC33FJ32GP204 Timer1 is configured using datasheet but not working

Buttons need debouncing.

You are controlling LED1 from two places that in from main loop and also Timer ISR. If it is turned ON in Timer1 ISR then immediately it is turned OFF in the main loop's first else condition and so you will not see Led toggling.
 

Buttons need debouncing.

Debounce is needless in this case where the only function of the input reading is to mirror the current state of the key toward the LED, no counting being made, so this is unrelated to the issue itself.

Anyway, as long as the OP saves words and does not tell exactly what is "not working", the rest will be guesswork.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top