Program can produce a noise

Just to let you to know. The program can produce a noise itself, the first Plott is AC voltmeter only, on second is added sine wave generator, input of AC voltmeter is connected to ground.

What program?
Is there a question here?

Obviously yes.
That's why you always have to read the documentation of the micro you use, to avoid this type of surprises.

Regards

I've been wondering about that ringing in my ears.

1 Like

… answer the door then.

1 Like

A program can also produce music! In 1965, you could put a portable AM radio on top of an IBM 1440 computer and run a specific program and the radio would play Waltzing Matilda.

1 Like

This program, no question just statement, very often people have a problem with noise ......
The strange is that PA4 is on the ground and noise still present.


#include <LiquidCrystal.h>
#include "EmonLib.h"
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);

#define SAMPLES 102

#define DEBOUNCE_DELAY 100

#define DEBOUNCE_IDLE 0
#define DEBOUNCE_ACTIVE 1

#include <libmaple/dma.h>
#include <EEPROM.h>

double Voltage = 0;

struct debounce_info
{
  int start, state;
  int16 shift;
} left, right, up, down;

dma_tube_config dma_cfg, dma_cfg2;

int flag1 = 0;
int flag2 = 0;

int out1 = PB7;


int val1[SAMPLES];


int16 shift = 0;

int amp = 35;
int cnt = 0;
int time_track = 0;
float stp = 6.2831 / SAMPLES;
int ret = 17;

timer_dev *dev1 = PIN_MAP[out1].timer_device;

uint8 cc_channel1 = PIN_MAP[out1].timer_channel;


void fun()
{
  flag1++;
}

void fun2()
{
  flag2++;
}

void timer_conf()
{

  timer_dma_set_base_addr(dev1, TIMER_DMA_BASE_CCR2);
  timer_dma_set_burst_len(dev1, 1);
  timer_dma_enable_req(dev1, cc_channel1);
  timer_set_reload(dev1, 102);
  timer_set_prescaler(dev1, 0);

}

void dma_conf()
{
  dma_init(DMA1);
  /* T4C2 DMA C4 */
  dma_cfg.tube_dst = &(dev1->regs.gen->DMAR);
  dma_cfg.tube_dst_size = DMA_SIZE_32BITS;
  dma_cfg.tube_src = val1;
  dma_cfg.tube_src_size = DMA_SIZE_32BITS;

  dma_cfg.tube_nr_xfers = SAMPLES;
  dma_cfg.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;

  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM4_CH2;
  dma_cfg.target_data = 0;

  ret = dma_tube_cfg(DMA1, DMA_CH4, &dma_cfg);

  /* T1C1 DMA C2 */

  dma_cfg.tube_dst_size = DMA_SIZE_32BITS;
 
  dma_cfg.tube_src_size = DMA_SIZE_32BITS;

  dma_cfg.tube_nr_xfers = SAMPLES;
  dma_cfg.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC | DMA_CFG_CMPLT_IE;

  dma_cfg.tube_req_src = DMA_REQ_SRC_TIM1_CH1;
  dma_cfg.target_data = 0;

  ret = dma_tube_cfg(DMA1, DMA_CH2, &dma_cfg);
}

void dma_start()
{
  dma_attach_interrupt(DMA1, DMA_CH4, fun);

  dma_enable(DMA1, DMA_CH4);
  timer_resume(dev1);

  dma_attach_interrupt(DMA1, DMA_CH2, fun2);

  dma_enable(DMA1, DMA_CH2);

}

void init_wave()
{
  int i;
  for (i = 0; i < SAMPLES; i++)
  {
    val1[i] = 50 + amp * sin(stp * i);

  }
}

void get_wave(int16 shift)
{
  int i;
  for (i = 0; i < SAMPLES; i++)
  {
  }
}

void setup() {
  int i;
  pinMode(out1, PWM);

 Serial.begin(115200);
  lcd.begin(16, 2);

  timer_conf();
  dma_conf();
  dma_start();

  init_wave();
  EEPROM.read(0, (uint16*)&shift);
  get_wave(shift);

}

void loop() {
   Voltage = getVPP();

  Serial.print(" Amps RMS = "); Serial.print( Voltage);
  Serial.println();

}


float getVPP()
{
  float result;
  int readValue;             //value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;          // store min value here, 4095.0
  //int minValue = 4095.0;

  uint32_t start_time = millis();
  while ((millis() - start_time) < 10)
    //while((millis()-start_time) < 100)  //sample for 1 Sec
  {

    readValue = analogRead(PA4);
    //readValue = analogRead(PB0);

    if (readValue > maxValue)
    {
      maxValue = readValue;
    }
    if (readValue < minValue)
    {
      minValue = readValue;
    }
  }
  result = (maxValue - minValue);

  return result;
}

I see that PA4 is connected to the display module. LCDs need an oscillator signal to allow
the segments to darken. Maybe that is what the noise is.

1 Like

So what you actually mean is that the program produces 'noise' not 'a noise', there is a big difference between those words. I am assuming you are not a native English speaker.

All digital electronic circuits produce noise. That is why we use, or should use, methods to remove this noise from a system. This is called decoupling and you can read about it here:-
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

1 Like

I removed LCD = noise the same

Decoupling has nothing to do here, input is on ground.

I see what's puzzling you.
You are wondering why it isn't 0 if he input is grounded, correct?

A part of decoupling is to remove ground noise, sometimes called ground bounce. This can also be caused by poor ground layout, like you would get if you did not used a star ground wiring system.

yes

The difference between plots is only in the program.

Yes I know. It is a pity you can't understand me. Do you choose this misunderstanding or is it real?

I comment all lines with LCD and noise decreased by 50%

Yes, so what?

regardless of grounding, noise is also produced by the program itself.

Is this for an STM32 processor?