element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum reproducing sine wave accurately
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 6 replies
  • Answers 4 answers
  • Subscribers 469 subscribers
  • Views 988 views
  • Users 0 members are here
  • cortex-m0 mcu
Related

reproducing sine wave accurately

gnsh
gnsh over 6 years ago

I am using a cortex M0 microcontroller. i am giving a  sine wave input of 1 Hz. this input signal is given to a 12 bit adc and this converted data is given to uart This uart data Im plotting through a serial plotter. image

 

 

how to get a smooth sine wave? from the uart data.

Attachments:
SINEWAVE.c.zip
  • Sign in to reply
  • Cancel

Top Replies

  • michaelkellett
    michaelkellett over 6 years ago +4 suggested
    So many things could be wrong that it's hard to know where to start suggesting. What does you code do, and where did it come from. How fast are you sampling, how is the data being presented to the UART…
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to michaelkellett +3 suggested
    I found this function in the attachment: int32_t adc_sine(void) { int32_t u32Result; unsigned char buffer[20]; ADC_Open(ADC, ADC_INPUT_MODE_SINGLE_END, ADC_OPERATION_MODE_CONTINUOUS, ADC_CH_1_MASK);…
  • shabaz
    shabaz over 5 years ago in reply to Jan Cumps +3
    He's using sprintf with %d, so not sending the number, but an ASCII representation. I don't know what his serial plotter is doing, but maybe it is mashing up the characters into nonsense words or long…
Parents
  • michaelkellett
    0 michaelkellett over 6 years ago

    So many things could be wrong that it's hard to know where to start suggesting.

     

    What does you code do, and where did it come from.

     

    How fast are you sampling, how is the data being presented to the UART (binary, text ???)

     

    What hardware and programming/debugging tools are you using.

     

    The amplitude of the samples may be a clue: The 12 bit ADC will give readings from 0 - 4097, but your plot is showing data in the range 7.5E8 to 9.5E8 - that's not right.

     

    MK

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 5 years ago in reply to michaelkellett

    I found this function in the attachment:

     

    int32_t  adc_sine(void)
    {
    int32_t u32Result;
    unsigned char buffer[20];
    
      ADC_Open(ADC, ADC_INPUT_MODE_SINGLE_END, ADC_OPERATION_MODE_CONTINUOUS, ADC_CH_1_MASK);
    
    
        // Set reference voltage to AVDD
        ADC_SET_REF_VOLTAGE(ADC,ADC_REFSEL_INT_VREF);
    //    // Power on ADC
        ADC_POWER_ON(ADC);
    
    
        ADC_START_CONV(ADC);
    
    
       // while (u8ADF == 0);
    
    
        u32Result = ADC_GET_CONVERSION_DATA(ADC, 1);
    
    
    sprintf(buffer,"%d,",u32Result);
    UART_Write(UART1,buffer,strlen(buffer));
    //UART_Write(UART1,u32Result,1);
    
    
    
    
    return u32Result;
    
    
    }

     

    The code does not show the main loop. But I think it's calling adc_sine continuously

     

    It's initialising , setting the reference of the ADC each time and kicking it off in continuous mode.

    It says it samples continuously, but a single sample is taken then formatted into a string and  sent out to the serial bus (commented out test code says at speed 9600).

    It's going to be too slow. I think it's too slow without the UART write too.

     

    Everything before this line should not be in the loop:

    u32Result = ADC_GET_CONVERSION_DATA(ADC, 1);

     

     

    The writing to the UART should be made efficienter too. Maybe gather a series of samples in a uint32_t buffer (controlled by a timer tick?), then writing when done sampling (I don't know if the display has time as horizontal axis, or measurement count ...)

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • shabaz
    0 shabaz over 5 years ago in reply to Jan Cumps

    He's using sprintf with %d, so not sending the number, but an ASCII representation. I don't know what his serial plotter is doing, but maybe it is mashing up the characters into nonsense words or long words. Also could be an endian issue or anything. Hardly any info : (

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 5 years ago in reply to Jan Cumps

    Just out of curiosity I tried seeing what ASCII digits and dots and the comma he's got in that string (it is "%d, ") would look like decoded as an integer.

    Any 4 of those range of ASCII characters, seems to give values of the order of 10^8. e.g. "12, " gives 8e8. I wonder if his serial plotter is trying to interpret the stream as a load of 32-bit ints, or something like that..

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • shabaz
    0 shabaz over 5 years ago in reply to Jan Cumps

    Just out of curiosity I tried seeing what ASCII digits and dots and the comma he's got in that string (it is "%d, ") would look like decoded as an integer.

    Any 4 of those range of ASCII characters, seems to give values of the order of 10^8. e.g. "12, " gives 8e8. I wonder if his serial plotter is trying to interpret the stream as a load of 32-bit ints, or something like that..

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube