Re: BL4S100 delay rutine and conversion analog to digital
Scott Henion <[email protected]>
| Newsgroups | gmane.comp.hardware.rabbit-semiconductor |
|---|---|
| Message-ID | <[email protected]> |
On 8/20/2012 8:55 PM, Nestor Hernandez wrote:
>
> Hello,
> This is the first time I use a bl4s100. I created a program to made
> data acquisition of 50 point, between each point there is a delay of
> 100 ms. The delay time is calculate using this equation Td=
> Mc*(13*Ni+6)*(32*No+6), where Mc is the time per machine cycle, and Ni
> and No represent immediate values load into HL and BC, respectively.
> The program compile and run well, the problems is on conversion analog
> to digital does not work and the delay time neither. Someone could
> help me, in order to make this program work well. Is there any other
> way to create a delay routine of 100 ms?
> Thanks in advance,
>
> I add the program
> #use "BL4S1xx.LIB"
> main ()
> {
> int tiempo,i,a;
> auto char buffer[10];
> auto float Volts1,Volts2,A1,A2,*a1,*a2;
> auto float Volts_A1[50],Volts_A2[50];
>
> brdInit();
>
> printf("\nPRESS ENTER TO START\n");
> gets(buffer);
>
> for ( i = 0; i <50; i++)
> {
> Volts1=anaInVolts(1,1);
> Volts2=anaInVolts(2,1);
> A1=(10*Volts1);
> A2=(0.5*Volts2)-1,1389;
> a2=&A2;
> a1=&A1;
> Volts_A1[i]=*a1;
> Volts_A2[i]=*a2;
>
> #asm
> PUSH AF;
> PUSH BC;
> PUSH HL;
> LD BC,0x17h;
> OUTER: LD HL,0x19Fh;
> INNER: DEC HL;
> LD A,H;
> OR L;
> JP NZ, INNER;
> DEC BC;
> LD A,B;
> OR C;
> JP NZ,OUTER;
> POP HL;
> POP BC;
> POP AF;
> #endasm
> printf("%f\t %f\t
> %d\n",Volts_A1[i],Volts_A2[i], i);
> }
> }
I seem to remember there is a init function to set up the A/D.
As for a delay:
void delayMS((unsigned long millisecs)
{
unsigned long stime=MS_TIMER;
while ((MS_TIMER-stime)<millisecs)
;
}
You can put stime=MS_TIMER at the start of your for loop. Then the while
loop at the end. That will make each loop 100ms.
Also, printf's will slow things way down.
--
------------------------------------------
Scott G. Henion, Consultant
Web site: http://SHDesigns.org
------------------------------------------