??? 10/08/04 06:51 Read: times Msg Score: -1 -1 Message Not Useful |
#78987 - DAC algorithm with ADuC814 |
Many thanks everyone. Sorry for late posting.
Current my DAC code is here. The DAC system started working but it still doesn't work correctly. 12 bits serial data (high 4bits and low 8bits, 8-N-1, 9600bps) comes alternately from another ADuC814. For receiving separeted 12bits digital date serially (0000XXXX for high 4bits and XXXXXXXX for low 8bits) from SBUF, I could write the following code. What I have to do is to make a confirmation that now receiving data is High or Low. I pick up the first 5 even number of data and check if these all are 0000XXXX, then this even part is high byte and the next one should be low byte XXXXXXXX. Accurate rate is 1 - (1/16)^5 = 99.9999%. When these 5 don't match the state of high byte, then these are all low byte and high byte comes next. After judgement is over, DAC should work without any problems but... in this case it doesn't so much well. DAC0 pin outputs quite a different shape of wave. Any problems in coding? -------------------------------------------------- #include <stdio.h> #include <ADuC814.h> void daouth(int i) { // update high byte DAC0H = i; } void daoutl(int i) { // update low byte DAC0L = i; } void main(void) { int i, a[5]; ADCCON1 = 0x80; // turn on the internal reference DACCON = 0x0D; // DAC outputs update as soon as the DAC low byte are written. DAC0H = 0x00; // initialize DAC high byte DAC0L = 0x00; // initialize DAC low byte SCON = 0x52; // 8bits UART, enable serial receive TMOD = 0x22; // 8bits auto-reload timer/counter TH1 = 0xF7; // F7 for 9600 band TR1 = 1; // run timer1 PCON = 0x80; // double UART baud rate while(1) { i = 0; while(i<10) { if(RI) { if(!(i%2)) a[i/2] = SBUF; i++; RI = 0; } } if(a[0]&0x0F==a[0] && a[1]&0x0F==a[1] && a[2]&0x0F==a[2] && a[3]&0x0F==a[3] && a[4]&0x0F==a[4]) { while(1) { if(RI) { P1 ^= 0x02; daouth(SBUF); RI = 0; } if(RI) { P1 ^= 0x02; daoutl(SBUF); RI = 0; } } } else { while(1) { if(RI) { P1 ^= 0x02; daoutl(SBUF); RI = 0; } if(RI) { P1 ^= 0x02; daouth(SBUF); RI = 0; } } } } } -------------------------------------------------- |
Topic | Author | Date |
DAC algorithm with ADuC814 | 01/01/70 00:00 | |
RE: DAC algorithm with ADuC814 | 01/01/70 00:00 | |
RE: DAC algorithm with ADuC814 | 01/01/70 00:00 | |
RE: DAC algorithm with ADuC814 | 01/01/70 00:00 | |
RE: DAC algorithm with ADuC814![]() | 01/01/70 00:00 |