Welcome, Guest
Username: Password: Remember me

TOPIC: Reduce noise with sleep function

Reduce noise with sleep function 2 years 1 month ago #1034

  • ucfanrg
  • ucfanrg's Avatar
  • OFFLINE
  • New Member
  • Posts: 12
  • Thank you received: 7
  • Karma: 2
Hi there,

I've stopped the project for while because I am stuck with an issue that prevents me from moving forward, and it's the annoying hiss you hear from the Microcontroller.

I Understand that when the Microcontroller is running, you get a lot of noise from all the component around. There is a way to fix this on AVR system (like the Arduino UNO) because it has a sleep function that lets the ADC run but shuts down the CPU and the clocks, and when the ADC is ready, it wakes up.

I am struggling to find a good tutorial about Sleep function with interrupts on ARM Cortex M3.

Do you guys have any experience with that?
The administrator has disabled public write access.

Reduce noise with sleep function 2 years 1 month ago #1036

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Moderator
  • Posts: 695
  • Thank you received: 146
  • Karma: 41
Hi, it is a good idea, I did not know about it, I have been checking around and there are some talks in the Arduino DUE forum:
forum.arduino.cc/index.php?topic=181543.0

I will try to see if I can make something to run.

Anyway try to use a good power supply (not just a USB connection), it makes a huge difference.
The administrator has disabled public write access.

Reduce noise with sleep function 2 years 1 month ago #1037

  • ucfanrg
  • ucfanrg's Avatar
  • OFFLINE
  • New Member
  • Posts: 12
  • Thank you received: 7
  • Karma: 2
Hi, here is the code for the arduino UNO, I don't have the circuitry but maybe you could test it on your side?

Source : www.gammon.com.au/adc
#include <avr/sleep.h>    // Sleep Modes

// when ADC completed, take an interrupt 
EMPTY_INTERRUPT (ADC_vect);
 
// Take an ADC reading in sleep mode (ADC)
float getReading (const byte port)
  {
  ADCSRA = bit (ADEN) | bit (ADIF);  // enable ADC, turn off any pending interrupt
  ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2);   // prescaler of 128
  ADMUX = bit (REFS0) | (port & 0x07);  // AVcc   
 
  noInterrupts ();
  set_sleep_mode (SLEEP_MODE_ADC);    // sleep during sample
  sleep_enable();  
 
  // start the conversion
  ADCSRA |= bit (ADSC) | bit (ADIE);
  interrupts ();
  sleep_cpu ();     
  sleep_disable ();
 
  // awake again, reading should be done, but better make sure
  // maybe the timer interrupt fired 
  while (bit_is_set (ADCSRA, ADSC))
    { }
 
  return ADC;
  }  // end of getReading
 
  void setup ()
    {
    int reading = getReading (0);
 
    Serial.begin (115200);
    Serial.println ();
    Serial.println (reading);
    }  // end of setup
 
void loop () { }
The administrator has disabled public write access.
The following user(s) said Thank You: Ray
Time to create page: 0.224 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio