cancel
Showing results for 
Search instead for 
Did you mean: 

Facing issue with SARADC in SPC58EC80E5 Evaluation kit using AUTODEVKITSTUDIO

Pooja1
Associate II

Hello Max VIZZINI ,

I'm using SPC58EC80E5 evaluation kit in that im working on SARADC , PB[1] i'm taking as ADC pin and connected 10k potentiometer to it.im getting continous 8192 adc value even after rotating the potentiometer , im using 12 bit ADC  and checking the ADC values in CAN bus, i shared related configuration check it and please help me to solve this issue.

 

 

#include "components.h"
#include "saradc_lld.h"
#include "saradc_lld_cfg.h"
#include "can_lld.h"
#include "can_lld_cfg.h"
#include "osal.h"

#define ADC_CHANNEL 66U

static uint16_t adc_value;
CANTxFrame txmsg;

int main(void)
{
componentsInit();

/* Start ADC */
saradc_lld_start(&SARADC12D1, &saradc_config_saradcconf);

/* Start CAN */
can_lld_start(&CAND2, &can_config_mcanconf);

/* CAN frame setup */
txmsg.IDE = CAN_ID_STD;
txmsg.SID = 0x123;
txmsg.RTR = 0;
txmsg.DLC = 2;

while (1)
{
/* Start ADC conversion */
saradc_lld_start_conversion(&SARADC12D1);

/* Wait for conversion */
while (SARADC12D1.saradc->ICDR[ADC_CHANNEL].B.VALID == 0U)
{
}

/* Read ADC value */
adc_value = saradc_lld_readchannel(&SARADC12D1, ADC_CHANNEL);

// if (adc_value == SARADC_INVALID_DATA)
// {
// continue;
// }

/* Send ADC value over CAN */
txmsg.data8[0] = (adc_value >> 8) & 0xFF;
txmsg.data8[1] = adc_value & 0xFF;

can_lld_transmit(&CAND2, 0, &txmsg);

osalThreadDelayMilliseconds(100);
}
}

 

CAN is working properly , im transmiting data in while(1) infinet loop but im receiving only 4 times 8192 in the CAN.

 

 

 

 

 

 

 

 

 

 

 

1 REPLY 1
SRomeo
ST Employee

Hi Pooja,
Let me guide you through the implementation of an ADC demo application:

  1. After creating a new SPC5 Application and added every propaedeutic component, click on "SPC58ECxx Low level Drivers Component RLA"
    SRomeo_2-1776235896235.png
  2. And Check the SARADC Enable box from the "Enabled Drivers" window
    SRomeo_3-1776235938047.png
  3. Now open the PinMap Editor SRomeo_4-1776236056262.png
  4. Select the ADC pin you wish to use (i.e. PB1, pin 56) and allocate it.
    SRomeo_10-1776237699509.png

     


    When allocating the function (ADC SAR 12bit S) and the CHANNEL (66 in our case) will be shown.
  5. If you miss them, by left clicking once again on the pin you should be able to check the SARADC it belongs and its channel from the Outline pane:
    SRomeo_11-1776238071356.png
  6.  

    Now click on "SARADC" in the Outline window 
    SRomeo_9-1776237340030.png 
  7. Check the SARADC B 12B Supervisor box to enable it.
    SRomeo_8-1776237291545.png
  8. Click on the green cross to add a new saradc configuraiton:SRomeo_12-1776238166555.png
  9. Double click it and the Application Configuration pane will show
  10.  Scroll down up to Channel configuration and add a new configuration clicking the green cross:SRomeo_13-1776238335124.png
  11. Double click it compile the Channel number edit box with the correct channel number (66)
  12. Now you have to add a name for a callback:
    SRomeo_14-1776238919076.png
    (This will automatically be declared by the system with the name "<ConfigurationName>_<CallbackName>"once you click on generate, but needs to be defined somewhere in order to be called)
  13. Let's write so a simple callback on our main:
    SRomeo_15-1776239356202.png
  14. Now, Save generate and compile and your project is ready. 

    Warning, remember that "value" will contain raw 12 bit data. You need to convert it in float in order to use it.

If you have difficulties implementing from scratch a working ADC application, you may import one of the prebuild AutoDevKit projects.
Considering you are using a board embedded with a SPC58EC80E, the best demo candidate is:
"SPC58ECxx_RLA SARADC Test Application for DiscoveryPlus"

BR
Simone
AEK_Team