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.

sawtooth on pic16f877a??????

Status
Not open for further replies.

Eng- jaad

Newbie level 4
Newbie level 4
Joined
Mar 22, 2011
Messages
6
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,316
How to Generate triangular signal in pic 16f877a?
 

if you are dealing with a low frequency you could use MCP41010 single-channel digital potentiometer
MCP41010

I have generated sine waves of 3KHz without problems
 

plz i need code on any program that generate triangular wave from pic16f877a
 
what frequency do you require?
for a low frequency (< 5KHz) you could use a MCP41010 single-channel digital potentiometer otherwise a DAC for a higher frequency.
If may be possible to use PWM but I have never tried it
 

use a dac of 8 bit or 4 bit..make it using R - 2R resistor ladder...
Now program a pic in such a way that a port say PORTB always decrease from a high value say 255 to zero...give required delay in between...Then repeat the steps if PORTB =0...
Then you will get digital data corresponding to sawtooth...

Can use below program ..

#include<pic.h> //for high tech C//
void main()
{
TRISB=0; //set port b as output port//
while(1)
{
PORTB=255; //all bits are high , 0xFF//
loop1: PORTB=PORTB-1; //decrease port b value//
__delay_ms(2); //this is hightech C inbuild delay,may not be applicable for other compiler you are using. so use accordingly or create a delay function using for loop //
if(PORTB>=1){goto loop1;}
}
}

---------- Post added at 14:36 ---------- Previous post was at 14:06 ----------

now you can calculate frequency ...
F = 1/T = 1/(delay in seconds * 255)
 
Last edited:
very thx vinodstanur i will try this
 

now for triangular wave just think what modifications you have to make in above program. These counter programs are basics of pic programming...
For triangular wave you need up count first then if it reaches top value then downcount should start and when it become 0 then repeat the program. Try to write it your own...There upcount downcount etc are basic examples for beginners..
 
Last edited:

plz can y help me???

Dear vinodstanur
The problem is that specialized communications and not computer, so I'm very weak programming
Can you help me to write me a program that generates a triangular signal from pic 16f877a with lcd and pushbutton,if y press button generate triangular signal from two pins and display on lcd " number one "
lcd connected on port d
pushbuton connected on port ra0
very thx
 

friend i am now replying you through my mobile. I cant give you full code for your need. But now i can give you my final LCD program . (copy in my mobile). Try this working code...Its 100%working.

/////////////////////////////////////////////////////////
//16x2 LCD with PIC16F877A ///
//RS= RC4 R/W=ground ///
//EN=RC5 ///
//DATA=PORTB ( LOWER 4 BITS ) ///
//connect RB0 to D4, RB1 to D5, .....RB3 to D7 of LCD ///
/////////////////////////////////////////////////////////
#include <htc.h>
#define _XTAL_FREQ 20e6 // 20MHz
__CONFIG(0x3F3A);
#define RS RC4 #define EN RC5
///////////////////////////////////////////////////////////////////
void LCD_STROBE(void)
{
EN = 1;
__delay_us(0.5); EN = 0;
}
////////////////////////////////////////////////////////////////////
void data(unsigned char c)
{ RS=1;
__delay_us(40); PORTB = ( c >> 4 );LCD_STROBE();
PORTB = ( c );LCD_STROBE(); }
//////////////////////////////////////////////////////////////////
void cmd(unsigned char c)
{ RS=0;
__delay_us(40); PORTB = ( c >> 4 );LCD_STROBE();
__delay_ms(2);
PORTB = ( c );LCD_STROBE();
__delay_ms(2);
}
///////////////////////////////////////////////////////////////// void clear(void)
{ cmd(0x1);
__delay_ms(2);
}
/////////////////////////////////////////////////////////////////
void lcd_init()
{ __delay_ms(20);
cmd(0x03);
__delay_us(200);
cmd(0x03);
__delay_us(200);
cmd(0x03); cmd(0x28 ); // Function set (4-bit
interface, 2 lines, 5*7 Pixels)
cmd(0x0c); // Make cursor invisible
clear(); // Clear screen
cmd(0x6); // Set entry Mode
} ////////////////////////////////////////////////////////////////
void string(const char *q)
{
while(*q)
data(*q++);
} /////////////////////////////////////////////////////////////////
void main()
{__delay_ms(100);
PORTB=0;PORTC=0;TRISB=0;
TRISC=0b11001111;
__delay_ms(15); lcd_init();
////////////////////////////////////////////////////////////////
cmd(0x82);//simply to start display
from 3rd column of first row//
//first row start address is 0x80 and
second row is 0xC0// string("HELLO WORLD");
cmd(0xC0); //NEXT LINE START
ADDRESS//
string("LCD 4-BIT MODE"); ////////////////////////////////////////////////////////////////
while(1);
////////////////////////////////////////////////////////////////
}

---------- Post added at 19:48 ---------- Previous post was at 19:45 ----------

but i think the delay function will work only in hightech c professional version...If you have only the light version then you need to use some good working delay routines...Will get it from google search...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top