??? 01/11/06 01:54 Modified: 01/11/06 02:01 Read: times |
#107014 - MAX186 Responding to: ???'s previous message |
Kevin, I'm not sure if you're clear on the use of SCLK - effectively the SCLK is like cranking the handle to send/receive a bit at a time - the speed of the SCLK is not critical (there are upper limits though) to the MAX186. This is unlike asynchronous serial that has fixed timing.
Following is some 'c' code I wrote many years ago that uses the max186 and bit bangs the SPI. Pretty much your assembler code would follow the same structure. Hopefully this helps. [PRE] int GetAdc(char input) /* returns value of adc input sampled 8 times */ { register char a , b , cmd186 , e; register unsigned int c,d; switch(input) /* max186 has funny input bit addressing */ { case 0: cmd186=0x8f; break; case 1: cmd186=0xcf; break; case 2: cmd186=0x9f; break; case 3: cmd186=0xdf; break; case 4: cmd186=0xaf; break; case 5: cmd186=0xef; break; case 6: cmd186=0xbf; break; case 7: cmd186=0xff; break; default: cmd186=0; /* has the command & input# for the max186 */ } d=0; /* zero the accumulator */ e=0; while (e < 8) { ADC_CS=0; /* select the max186 */ b=cmd186; /* copy cmd so we can shift it .. */ for (a=0;a<8;a++) /* shift the cmd out to max186 */ { if ((b & 0x80) !=0 ) DIN=1; else DIN=0; b=b<<1; SCLK=1; SCLK=0; } for (a=0;a < 40;a++); /* wait at least 10 uS for conversion */ c=0; for (a=0;a<12;a++) /* grab the 12 bit result from the max186 */ { c=c<<1; /* pre shift */ SCLK=1; SCLK=0; /* clock the next data bit */ if (DOUT == 1) c|=0x0001; /* into the var */ } ADC_CS=1; d+=c; /* accumulate the samples */ e++; /* next sample */ } return(d); } [/PRE] |
Topic | Author | Date |
max186 clarification | 01/01/70 00:00 | |
Clock | 01/01/70 00:00 | |
meaning | 01/01/70 00:00 | |
no almost there | 01/01/70 00:00 | |
I'm using | 01/01/70 00:00 | |
and the reason you asked is? | 01/01/70 00:00 | |
two reasons | 01/01/70 00:00 | |
aha | 01/01/70 00:00 | |
possibly. can you handle the overhead o | 01/01/70 00:00 | |
bb SPI | 01/01/70 00:00 | |
what is "BB SPI" | 01/01/70 00:00 | |
(B)it (B)anged SPI | 01/01/70 00:00 | |
MAX186 | 01/01/70 00:00 | |
thanks | 01/01/70 00:00 | |
Something to check![]() | 01/01/70 00:00 | |
setb clrb | 01/01/70 00:00 | |
muchos gracias (much thanks) | 01/01/70 00:00 |