Hi,

I haven't reworked my code based on the recommendations yet, but I would
like to make a reply on some comments.

If my application only requires me to use one a/d channel, with the input of
the signal being non-periodic (changes relatively slowly, i.e. change from
2.5 V to 3 V and stay there for at least a few seconds), would the
acquisition time that I set in ADCON2 matter (I don't think so)?

Also, what would be the benefit of using an ISR for a/d sampling rather than
polling for ADCON0bits.GO to clear?

Thanks,

Stanley

On 10/28/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> Stanley Lee wrote:
> > The project folder that I have so far is in
> > http://www.mediafire.com/?c1444jbnizc b/c the message would get
> > otherwise too large to be posted. What I'm trying to do right now is get
> > the a/d conversion module working, and see the output on a combination
> > of LEDs, through USART to the computer on terminal or something, through
> > looking at the PWM variation or outputting to a LCD display. I'm
> > following the guidelines as described in section 19 of the PIC18F2620
> > manual. I have some questions about the code below:
>
> I would suggest using the sdcc adc libs to do this. Just include adc.h
> and do a
> adc_open(channel_num_to_read, ADC_FOSC_64, ADC_CFG_05A_0R, ADC_FRM_RJUST
> | ADC_INT_OFF);
> There is a bug in the sdcc adc lib which forces you to manually set
> ADCON2bits.ACQT0 = 1;
> ADCON2bits.ACQT1 = 1;
> ADCON2bits.ACQT2 = 1;
> TRISA = 0xff;   // input
> (see also my patch
>
> https://sourceforge.net/tracker/?func=detail&atid=300599&aid=1776197&group_id=599
> for a pic18f2550)
> adc_conv();     // start initial sampling
>
> later in your programm do:
> while(1) {
>     if (!ADCON0bits.GO) {
>       // read result
>       adc = adc_read();         // read value
>       adc_setchannel(next_channel_to_read);     // set to next channel
>       adc_conv();               // restart sampling
>    }
> }
> >
> > 1. For ADCON2, I have picked the minimum acquisition time and the
> > fastest clock, which is Fosc/4. Would anyone know about the
> > implications, pros and cons of picking different acquisition time and
> > a/d clock source?
> If i understood this correct the ACQ and ADC_CLOCK (TAD) are different
> things. The Tad defines how fast each bit of the 10-bit adc is sampled,
> thus it defines the maximum time for a complete conversion, which is 11
> times tad.
> The acq defines (in tad units) how long the internal capacitor is
> charged before the conversion is actually started. The length of the acq
> depends on the frequency of the signal you want to convert. The higher
> the acq the more the actual read value is averaged.
> The acq is a fine thing if you read out different channels successively.
> Without this you would always need to wait a specific time after
> changing the channel and starting a conversion to give the internal
> capacitor the chance to charge with the analog value.
>
> >
> > 2. For the a/d input acquisition time, I have a delay loop that involves
> > using a while loop that has a delay of 27 us rather than the minimum
> > time suggested in section 19.1 of 2.4 us. Could there be any
> > implications of doing what I did in my code?
> This is no prob if you don't read out the value before the ADCONbits.GO
> bit is cleared. See also my code above.
>
> >
> > 3. For using the a/d interrupt functionality, I infer that I would write
> > an ISR that is dependent on ADIF interrupt flag bit. I'm not sure where
> > I can find the interrupt number for a/d interrupt as I would need it to
> > complete my ISR properly. Can anyone help me on this? I was having
> > trouble finding it in the SDCC manual.
> you need to enable the adc interrupt by using ADC_INT_ON when doing the
> adc_open. Then use an isr like (it reads all 13 cahnnels) :
> int adc_value[13];
> unsigned chardc_channel;
>
> void low_isr(void) interrupt 2 {
>   PORTCbits.RC1 = 1;
>   // adc isr
>   if (PIR1bits.ADIF) {
>     adc_value[adc_channel] = adc_read();
>     // set next channel
>     if (adc_channel == 12) adc_channel = 0;
>     else adc_channel++;
>     adc_setchannel(adc_channel);
>     // reset interrupt
>     PIR1bits.ADIF = 0;
>     adc_conv();         // restart sampling, don't omit this
>   }
>   PORTCbits.RC1 = 0;
> }
>
>
> >
> > 4. Maybe be a bit of a silly question. I'm planning to add up the high
> > and low result bits into a single result integer and return it to the
> > function calling the a/d sampling function. What would be the limit for
> > how large an integer type can be?
>
> the maximum value for an unsinged integer is 2^16-1 for a singed integer
> its half of that. Since the adc only has 10-bits. The maxmimum value is
> 2^10-1. So you can use an unsigned integer.
>
> jan
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Sdcc-user mailing list
> Sdcc-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sdcc-user
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to