This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Question about using ADC on Hercules

Other Parts Discussed in Thread: TMS570LS1224, HALCOGEN

Hi

I have a small question

To use the ADC on the TMs570LS1224 can I just use this lines?

adcInit();

/* start adc conversion */
adcStartConversion(adcREG1,adcGROUP1);
/* ... wait and read the conversion count */
while((adcIsConversionComplete(adcREG1,adcGROUP1))==0);
ch_count = adcGetData(adcREG1, adcGROUP1,&adc_data[0]);

ch_count = ch_count; 
/* conversion results : */
/* adc_data[0] -> should have conversions for Group1 channel1 */
/* adc_data[1] -> should have conversions for Group1 channel2 */

id = adc_data[0].id;
value = adc_data[0].value;

Second 

On Halcogen I need to select the channels I want to work with, I see there is an option to start the conversion once an event has occured. But I only need to start the conversion when I tell it to do. 

This lines does that?

adcStartConversion(adcREG1,adcGROUP1);


I have seen the example for that but... amm Im not prety sure about some thing, because it uses a gio to start the conversion...

So... can I start it without an event??

and the last

how can I tell it to read the singal on pinX?? and retrieve that data??

thanks!

  • Miguel,

    Conversion groups can be even triggered, or for Group1 and Group2 you can choose to configure the conversion group so that it is software triggered. Look at HalCoGen, and see how on the ADCx Group Event tab there isn't any 'Hardware/Software' block in the trigger path but for 'ADCx Group 1' and 'ADCx Group 2' on the trigger path the last step is selection between a hardware/software trigger.

    If you select software trigger, then to trigger the conversion you write to the group's channel select register. This will then start it converting all of the channels that you've told it to with that write to the channel select register.
  • So I could select software trigger, call "adcStartConversion(adcREG1,adcGROUP1)" and then the conversion starts right?

    this lines come from the example on Halcogen.
    What ch_count do? get the data from channel 0??
    and id and value??? what do those lines do??


    ch_count = adcGetData(adcREG1, adcGROUP1,&adc_data[0]);

    ch_count = ch_count;
    /* conversion results : */
    /* adc_data[0] -> should have conversions for Group1 channel1 */
    /* adc_data[1] -> should have conversions for Group1 channel2 */

    id = adc_data[0].id;
    value = adc_data[0].value;


    thanks Anthony!
  • Miguel,

    It's documented in the file ..

    /** @fn uint32 adcGetData(adcBASE_t *adc, uint32 group, adcData_t * data)
    * @brief Gets converted a ADC values
    * @param[in] adc Pointer to ADC module:
    * - adcREG1: ADC1 module pointer
    * - adcREG2: ADC2 module pointer
    * @param[in] group Hardware group of ADC module:
    * - adcGROUP0: ADC event group
    * - adcGROUP1: ADC group 1
    * - adcGROUP2: ADC group 2
    * @param[out] data Pointer to store ADC converted data
    * @return The function will return the number of converted values copied into data buffer:
    *

    And should also appear in the online doc.. See '@return'...
  • I already read the file but no reference on .id and .value...  or ch_count....

    thanks

  • so... I was trying to understand the code and:

            ch_count = adcGetData(adcREG1, adcGROUP1,&adc_data[0]);
               
            ch_count = ch_count; 

    If I get it right, ""adc_data is similar to RX_Data_Master on the SPI example. The ADC stores the information from the conversions inside that array and then I can get that value with 

            id    = adc_data[0].id;
            value = adc_data[0].value;

    I will assume that [0] means on channel 0. For what I read, ID is the channel number, which I already know because I wrote 0, and .value has the data from that channel right?

    if I change 0 to any other number, corresponging a channel, I will get the data from that pin right?

    What disturbs me is the ch_count... why is that equal to the conversion and then ch_count=ch_count?? 

    thanks!!

  • Miguel I think that [0] is the first result not the channel #.

    So start conversions with channel 0 and [0] is channel 0. But start at channel 5 and [0] is the result of channel 5...

    I cant' really comment on ch_count=ch_count; also seems to not make sense.
  • Hi Anthony

    look: 

    /** -  Get conversion data and channel/pin id */
            for (i = 0U; i < count; i++)
            {
              buf        = adc->GxBUF[group].BUF0;
    		  /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
              ptr->value = (uint16)(buf & 0x3FFU);
              ptr->id    = (uint32)((buf >> 10U) & 0x1FU);
              /*SAFETYMCUSW 567 S MR:17.1,17.4 <APPROVED> "Pointer increment needed" */
    		  ptr++;
            }

    this is from adc.c

    It goes to all the values of "count", which I asume is the number of channels activated. And then It gives me the id and the value, which I assume is something like what you said. If I have 5 channels, it could start converting the 3rd and put it on [0]. Apparently the ch_count=ch_count is because a return, which is "return count"

    But Im not sure about this... don't you have any other example??

    thanks!

  • Anthony

    hope you're doing great.

    One quick question about peripherics on this MCU. The ADC can work in parallel to the main loop??

    I make myself clear. Can I enter an interrupt by timer and start the conversion and then come back later? something like this:

    if(rtiNOTIFICATION_COMPARE1)	//every 378ms
    	{
    
    		adcStartConversion(adcREG1,adcGROUP1);
     		
     		if((adcIsConversionComplete(adcREG1,adcGROUP1))==0)
     			return 0;
    			
    
    			/* ... wait and read the conversion count <------Get out from interrupt and do something else */
    
       		if((adcIsConversionComplete(adcREG1,adcGROUP1))==1)
      		{
       			ch_count = adcGetData(adcREG1, adcGROUP1,&adc_data[0]);
    
       			ch_count = ch_count;
    
       			/* conversion results :                                       */
    
      		 	/* adc_data[0] -> should have conversions for Group1 channel1 */
    
           		/* adc_data[1] -> should have conversions for Group1 channel2 */
    
       			id_ch_0=adc_data[0].id;
    
       			value_ch_0=adc_data[0].value;
    
    
       			id_ch_3=adc_data[1].id;
    
       			value_ch_3=adc_data[1].value;
    
    
       			id_ch_5=adc_data[2].id;
    
       			value_ch_5=adc_data[2].value;
    
    
       			id_ch_7=adc_data[3].id;
    
       			value_ch_7=adc_data[3].value;
       		}
       
       
    }

    
    

    So here, the first time, I start the conversion from ADC channels and go back to the main loop to do something else, like reading SPI, process data or whatever. The second time I get to the interrupt, the data should be ready so I just read it from there. I need the data every 378ms so... I don't know what can I do...

    Or Im wrong??

    I want to think that the GetData function clear the FIFO right??

    thanks