Help on PIC18F25XX Programming to generate Sine wave

Status
Not open for further replies.

blue_blur

New Member
Hi all, i am new to PIC microcontroller. i am currently doing my school project and need to use the PIC18f25XX microcontroller and MPLAB IDE C18 compiler to generate different kind of waveform by passing through a DAC.

so far i just be able to generate a constant Voltage of 1v to 5v. however when i try to use the sin() function to generate the sine wave, i could only saw noise at the osilloscope.

Hope those who are good in the area can help me, thanks.
 
Just to have you started in thinking a little about your problem, consider this:

Your DAC, to output a sine waveform needs to have an input consisting of the sin function values. That concept, doesn't ring any bell to you?
 
Just to have you started in thinking a little about your problem, consider this:

Your DAC, to output a sine waveform needs to have an input consisting of the sin function values. That concept, doesn't ring any bell to you?


ya, is true. when i just insert with the respective sin value into the code, i am able to get the sine waveform. however just when i tried to use the SIN() function to generate those values, the problem appear. so i not very sure with part is wrong.
 
thanks. i post my source code here. hope can get some correction so that i can proceed with my project.

#include <p18f2520.h>
#include <delays.h>
#include <math.h>
#include <stdio.h>

#pragma config OSC = INTIO67 // use internal oscillator and bits 6 & 7 of PORTA can be used as IO pins

#define PI 3.14159


void main (void)
{
int i;
char y, mode = 0;

TRISC = 0x00; // 0x00 = binary 0000000, PORTC is set as output pin


while(1)
{

//DC voltage of 1V to 5V
/*PORTC=0x9A; //generate a dc voltage of +1V
Delay10TCYx(10);
PORTC=0xB3; //generate a dc voltage of +2V
Delay10TCYx(10);
PORTC=0xCD; //generate a dc voltage of +3V
Delay10TCYx(10);
PORTC=0xE6; //generate a dc voltage of +4V
Delay10TCYx(10);
PORTC=0xFF; //generate a dc voltage of +5V
Delay10TCYx(10);*/


//for loop to generate sinewave
for (i=0; i<=359; i++)
{
y=5.0*sin(i/180.0*PI)/5.0*128+128;
PORTC=y; //
Delay10TCYx(10); ; // delay of 400us
}
}
}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…