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.

unable to generate squarewave

Status
Not open for further replies.

abhi4u_84

Newbie level 1
Joined
Jul 27, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,293
hi there i require help on PIC16F917, i am an amature for PIC . i have never done programing. its my MSc progect to generate an square wave using Interrupt. i have written some code but its not working accordingly. i want to generate an square wave of 100 Khz-1 Mhz. but i am able to get only 21 Khz fixed frequency. i am not even able to vary the period need your help
My code:

#include<stdio.h>
#include<htc.h>


//Main Interrupt Service Routine (ISR)

void interrupt ISR()
{
int i;
OSCCON=0x70;
//Check if it is TMR2 Overflow ISR
if(TMR2IE && TMR2IF)
{

//TMR2 Overflow ISR
// counter++;
//if(counter==10)
{
//Toggle RB1
//if(RB1==0)
RB1 =~ RB1;

//else
// ; RB1=0;

// counter=0; //Reset Counter
//}

//Clear Flag
TMR2IF=0;
TMR2=255;

}

}
// T2CON=0x00;
}

void main(void)
{
IRCF2=1;
IRCF1=1;
IRCF0=1;
int i,a;
OSCCON=0X70; // 8 Mhz 8
TRISA=0X03; // input port 1 & 2
TRISB=0X00; //output port
ANSEL=0x03; //selecting channel 1 & 2;
ADCON1=0X50; // fosc/ 16
ADCON0=0X81; // right justified
INTCON=0xC0; // enabling PEIE & GIE
T2CON=0x04; //timer 2 on
TMR2IE=1;
TMR2=0;
PR2=0xFF;
T2CON=0x04; //timer 2 on
//while(1)
while(!TMR2IF);
{
interrupt isr();
}
}
 

Have you tried like this?

#include<stdio.h>
#include<htc.h>

void interrupt ISR()
{
int i;
OSCCON=0x70;
//Check if it is TMR2 Overflow ISR
if(TMR2IF)
{
RB1 =~ RB1;

//Clear Flag
TMR2IF=0;
TMR2=255;
}
}

void main(void)
{
IRCF2=1;
IRCF1=1;
IRCF0=1;
int i,a;
OSCCON=0X70; // 8 Mhz 8
TRISA=0X03; // input port 1 & 2
TRISB=0X00; //output port
ANSEL=0x03; //selecting channel 1 & 2;
ADCON1=0X50; // fosc/ 16
ADCON0=0X81; // right justified
INTCON=0xC0; // enabling PEIE & GIE
T2CON=0x04; //timer 2 on
TMR2IE=1;
TMR2=0;
PR2=0xFF;
T2CON=0x04; //timer 2 on
//while(1)
while(1);
}

---------- Post added at 03:29 ---------- Previous post was at 03:24 ----------

Try PWM generation also. search PWM generation using PIC16F917
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top