Hello everyone, please excuse my ignorance on this topic but I have really been trying to figure this out and I'm in need of assistance. I am trying to produce a sine wave output with a 16C774. I am using CCS's compiler and they have sine function implemented but I feel that I don't need the accuracy (floating point) that it provides nor the memory it uses. I have looked at some assembly code that Eric Smith developed using a Sine table and I think that it will be the most efficient. What I will be doing is writing the result to an 8-bit D/A converter and sweeping through each of the 256 steps. I think that this resolution is more than enough for my application. Here is my problem, I'm very new to the PIC and especially the compiler. I tried entering the code found here http://www.brouhaha.com/~eric/pic/sine.html and I can't figure out for the life of me how to get it to compile. On this webpage it is not really clear on the input and the output either. Can someone point me in the right direction so that I can get my code to compile? Also, as an aside. In CCS I was having problems at the end of my main function because it put the PIC into sleep mode. I put an empty do-while loop at the end to allow the Interrupts to continue to run. Is this the right way to end in my situation or is there a better way? Thanks, Jeff Frey Please also RTP so that I don't overlook any replies in the PICList. Here is my code: #include "o:\projects\safari\Safari.h" /// The following are manually added definitions #byte PORTB = 6 #define ALL_OUT 0 #define ALL_IN 0xff int angle; #int_rtcc rtcc_isr() { #asm sinetbl: addwf pc retlw 000h,003h,006h,009h,00ch,010h,013h,016h retlw 019h,01ch,01fh,022h,025h,028h,02bh,02eh retlw 031h,033h,036h,039h,03ch,03fh,041h,044h retlw 047h,049h,04ch,04eh,051h,053h,055h,058h retlw 05ah,05ch,05eh,060h,062h,064h,066h,068h retlw 06ah,06bh,06dh,06fh,070h,071h,073h,074h retlw 075h,076h,078h,079h,07ah,07ah,07bh,07ch retlw 07dh,07dh,07eh,07eh,07eh,07fh,07fh,07fh retlw 07fh sine: movwf temp ; save arg btfsc temp,6 ; is arg in the 2nd or 4th quadrant? sublw 0 ; yes, complement it to reduce to 1st or 3rd andlw 07fh ; reduce to 1st quadrant call sinetbl ; get magnitude btfsc temp,7 ; was it 3rd or 4th quadrant? sublw 0 ; yes, complement result return #endasm return; } #int_adcc adc_isr() { } #int_eeprom eeprom_isr() { } #int_timer1 timer1_isr() { } #int_timer2 timer2_isr() { } void main() { angle = 10; setup_adc_ports(A_ANALOG); setup_adc(ADC_CLOCK_DIV_2); setup_spi(FALSE); setup_psp(PSP_DISABLED); setup_counters(RTCC_INTERNAL,RTCC_DIV_2); // setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); // setup_timer_2(T2_DIV_BY_16,10,1); setup_ccp1(CCP_OFF); setup_ccp2(CCP_OFF); enable_interrupts(INT_RTCC); // enable_interrupts(INT_ADC); // enable_interrupts(INT_EEPROM); // enable_interrupts(INT_TIMER1); // enable_interrupts(INT_TIMER2); enable_interrupts(global); set_tris_b(ALL_OUT); // Set all pins on PORTB as Outputs PORTB = 0; // Set all pins on PORTB Low angle = 0; // Initialize angle to 0 degrees do { } while(TRUE); } -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! use mailto:listserv@mitvma.mit.edu?body=SET%20PICList%20DIGEST