Microcontroller output waveform distortion - Page 1
Forum section: electronics / projects

author: keshab.patel
author_rank: Contributor
timestamp: June 07, 2013, 11:54:47 am
content: 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.

author: Paul Price
author_rank: Super Contributor
timestamp: June 07, 2013, 12:39:46 pm
content: 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!

author: keshab.patel
author_rank: Contributor
timestamp: June 07, 2013, 12:51:56 pm
content: 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 postscalerT2CONbits.T2CKPS=0; //1:1 prescalerT2CONbits.TMR2ON=1;while(1){}void interrupt isr(void){PORTAbits.RA0=1-PORTAbits.RA0;PIR1bits.TMR2IF = 0;}

author: amyk
author_rank: Super Contributor
timestamp: June 07, 2013, 12:52:27 pm
content: Quote from: keshab.patel on June 07, 2013, 11:54:47 amThat 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.)

author: Paul Price
author_rank: Super Contributor
timestamp: June 07, 2013, 12:55:30 pm
content: Again, check your mcu supply voltages with a scope.

author: keshab.patel
author_rank: Contributor
timestamp: June 07, 2013, 12:58:15 pm
content: It looks neat with 1x probe. I dont know why??

author: Paul Price
author_rank: Super Contributor
timestamp: June 07, 2013, 01:15:16 pm
content: 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?

author: nctnico
author_rank: Super Contributor
timestamp: June 07, 2013, 01:32:43 pm
content: Quote from: keshab.patel on June 07, 2013, 12:58:15 pmYou need to adjust the frequency compensation of your 1:10 probe.http://www.picotech.com/applications/how-to-tune-x10-oscilloscope-probes.html

author: Paul Price
author_rank: Super Contributor
timestamp: June 07, 2013, 01:39:53 pm
content: 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 .

author: ftransform
author_rank: Frequent Contributor
timestamp: June 07, 2013, 02:29:28 pm
content: 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.

author: keshab.patel
author_rank: Contributor
timestamp: June 07, 2013, 04:06:07 pm
content: 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 ?

author: Paul Price
author_rank: Super Contributor
timestamp: June 07, 2013, 04:31:30 pm
content: What frequency of range of triangular waveform frequencies, accuracy of triangular wave and max amplitudes is required?

author: miceuz
author_rank: Frequent Contributor
timestamp: June 07, 2013, 05:14:26 pm
content: errrrrr.... circuit?

author: keshab.patel
author_rank: Contributor
timestamp: June 07, 2013, 06:55:42 pm
content: The triangular waveform frequency should be 12khz.

author: FrankBuss
author_rank: Unknown
timestamp: June 07, 2013, 08:25:55 pm
content: 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.

author: nctnico
author_rank: Super Contributor
timestamp: June 07, 2013, 11:01:10 pm
content: If you set the trigger source to 'line' (synchronous to mains) and the image is stable then its noise from the mains.

author: Paul Price
author_rank: Super Contributor
timestamp: June 08, 2013, 03:07:24 am
content: 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.

author: keshab.patel
author_rank: Contributor
timestamp: June 08, 2013, 06:44:16 am
content: Thanks....... but the triangular waveform needs to be in sync with other outputs. So I need to convert that square wave.

author: Paul Price
author_rank: Super Contributor
timestamp: June 08, 2013, 01:17:37 pm
content: 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.