Author Topic: Microcontroller output waveform distortion  (Read 5971 times)

0 Members and 1 Guest are viewing this topic.

Offline keshab.patelTopic starter

  • Contributor
  • Posts: 22
Microcontroller output waveform distortion
« on: June 07, 2013, 11:54:47 am »
Hi guys,
    I have been working on a project in 16f887. The 10 khz output waveforms distorts(see picture) in higher time base. The waveform looks better with 50 or 100 us timebase with just little overshoot. Please help me to solve the issue.
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: Microcontroller output waveform distortion
« Reply #1 on: June 07, 2013, 12:39:46 pm »
Show your circuit and code. The effect could be due to many things, including unstable power supply voltages on the MCU or some quirk in your oscilloscope. You don't mention how  you are generating this wave form or what the the several different time base settings are!
 

Offline keshab.patelTopic starter

  • Contributor
  • Posts: 22
Re: Microcontroller output waveform distortion
« Reply #2 on: June 07, 2013, 12:51:56 pm »
The wave form is generated by toggling a pin in timer interrupt.

 INTCONbits.GIE=1;
        INTCONbits.PEIE=1;
        PIE1bits.TMR2IE=1;
        PIR1bits.TMR2IF=0;
        PR2=250;
        T2CONbits.TOUTPS=0; //1:1 postscaler
        T2CONbits.T2CKPS=0; //1:1 prescaler
        T2CONbits.TMR2ON=1;

   
        while(1)
       {
}


void interrupt isr(void)
{
   PORTAbits.RA0=1-PORTAbits.RA0;
  PIR1bits.TMR2IF = 0;
}
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8331
Re: Microcontroller output waveform distortion
« Reply #3 on: June 07, 2013, 12:52:27 pm »
The waveform looks better with 50 or 100 us timebase with just little overshoot.
That sounds more like a scope artifact... of course it could also be some periodic events that you didn't capture at the faster timebase. (A CRO or DPO will be very useful for this.)
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: Microcontroller output waveform distortion
« Reply #4 on: June 07, 2013, 12:55:30 pm »
Again, check your mcu supply voltages with a scope.
 

Offline keshab.patelTopic starter

  • Contributor
  • Posts: 22
Re: Microcontroller output waveform distortion
« Reply #5 on: June 07, 2013, 12:58:15 pm »
It looks neat with 1x probe. I dont know why??
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: Microcontroller output waveform distortion
« Reply #6 on: June 07, 2013, 01:15:16 pm »
The x1 probe acts as a capacitor load on the circuit filtering out the noise. Also look carefully at your lead placement relative to other wires, are you using unshielded wires?, do you have a CCFL lamp on near the measurement point? Does changing the length of leads from the MCU pin to the scope measuring point affect this?, check the way you are grounding your oscilloscope to the the MCU board you are working with. Where are you placing your fingers...near the probe tip?
« Last Edit: June 07, 2013, 01:20:35 pm by Paul Price »
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27346
  • Country: nl
    • NCT Developments
Re: Microcontroller output waveform distortion
« Reply #7 on: June 07, 2013, 01:32:43 pm »
It looks neat with 1x probe. I dont know why??
You need to adjust the frequency compensation of your 1:10 probe.
http://www.picotech.com/applications/how-to-tune-x10-oscilloscope-probes.html
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: Microcontroller output waveform distortion
« Reply #8 on: June 07, 2013, 01:39:53 pm »
Adj'ing the freq. compensation of your probe will not change the waveform displayed in this case, only changes the rising/falling edge of each slower sq. waveform and flatness of high-freq. response of your scope with sinusoidal like signals .
 

Offline ftransform

  • Frequent Contributor
  • **
  • Posts: 728
  • Country: 00
Re: Microcontroller output waveform distortion
« Reply #9 on: June 07, 2013, 02:29:28 pm »
I agree that scope compensation is not causing this problem, it seems to be a transient event.

have you tried different output pins on your chip? Is there any kind of load being driven?

perhaps the navy deployed a ELF submarine communicator in your living room. be cautious.
« Last Edit: June 07, 2013, 02:32:22 pm by ftransform »
 

Offline keshab.patelTopic starter

  • Contributor
  • Posts: 22
Re: Microcontroller output waveform distortion
« Reply #10 on: June 07, 2013, 04:06:07 pm »
 The same probe works fine with the 1 khz test signal output of oscilloscope in both 10x and 1x mode. So I dont think I have to tweak the probes.

 Actually I need a triangular waveform in an application which is amplitude sensitive. So I am integrating the square wave with an opamp. But due to the  noise in square wave the output triangular waveform is also getting distorted. How do I get rid of it ?
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: Microcontroller output waveform distortion
« Reply #11 on: June 07, 2013, 04:31:30 pm »
What frequency of range of triangular waveform frequencies, accuracy of triangular wave and max amplitudes is required?
 

Offline miceuz

  • Frequent Contributor
  • **
  • Posts: 387
  • Country: lt
    • chirp - a soil moisture meter / plant watering alarm
Re: Microcontroller output waveform distortion
« Reply #12 on: June 07, 2013, 05:14:26 pm »
errrrrr.... circuit?

Offline keshab.patelTopic starter

  • Contributor
  • Posts: 22
Re: Microcontroller output waveform distortion
« Reply #13 on: June 07, 2013, 06:55:42 pm »
The triangular waveform frequency should be 12khz.
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2368
  • Country: de
    • Frank Buss
Re: Microcontroller output waveform distortion
« Reply #14 on: June 07, 2013, 08:25:55 pm »
Maybe it is an aliasing effect of your scope? Your code will create some jitter, even more later when you implement more functionality in the same PIC. Better use the capture/compare module. I've done this once, see bottom of my project here for a description:

http://www.frank-buss.de/SkinnyLatte/

It is a bit tricky, because you have to still update registers in an interrupt after the event was generated. But it was a PIC16F628A, maybe your PIC has more advanced options.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27346
  • Country: nl
    • NCT Developments
Re: Microcontroller output waveform distortion
« Reply #15 on: June 07, 2013, 11:01:10 pm »
If you set the trigger source to 'line' (synchronous to mains) and the image is stable then its noise from the mains.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: Microcontroller output waveform distortion
« Reply #16 on: June 08, 2013, 03:07:24 am »
If you need a kinda triangular wave just feed the square wave output to a resistor that is connected to a (10K resistor to .01 capacitor) capacitor and you will get a  kinda exponential type of funky triangular wave.

If you have room for a 2 transistors and a LED you can make a very clean triangular wave using constant current sources charging and discharging a capacitor linearly.
 
Is the simple resistor-capacitor way I mention the way you are trying to create a triangular wave now?

What's the triangular wave going to be used for?

You can also easily get a triangular wave using a 555 timer this is free running as a oscillator and you get the output from the timing capacitor and an isolating transistor or an op-amp is also needed to get the triangular wave without distortion.
 

Offline keshab.patelTopic starter

  • Contributor
  • Posts: 22
Re: Microcontroller output waveform distortion
« Reply #17 on: June 08, 2013, 06:44:16 am »
Thanks....... but the triangular waveform needs to be in sync with other outputs. So I need to convert that square wave.
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1433
Re: Microcontroller output waveform distortion
« Reply #18 on: June 08, 2013, 01:17:37 pm »
If you have room for a 2 transistors and a LED you can make a very clean triangular wave using constant current sources charging and discharging a capacitor linearly.
 
Is the simple resistor-capacitor way I mention the way you are trying to create a triangular wave now?

What's the triangular wave going to be used for?

The above techniques use the MCU to create the  timing, is in sync.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf