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.
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.
#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
}
}
}