Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can pic microcontroller generate spike !!

Status
Not open for further replies.

ennng

Junior Member level 2
Joined
Nov 1, 2012
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,420
Hi everyone,

I have a sine wave and detect the maximum values, I would the pic generate spike or square wave in these maximum values like in the picture. any idea !!

6769199600_1366738385_thumb.jpg
 

you can sample the signal using ADC and find the max values
 

Thank you very much for your answer. I have done this part I detect the max of the sine wave from ADC.
What I ask about how to generate square wave or spikes in these max.

Thanks again
 

Thanks for the link

but I think you misunderstand!!

I insert analog sine wave to ADC in the pic microcontroller and then detected the max values (this already done)

my question is there any way to generate from the pic a square wave in respect with max values.
 

If the output value from the ADC is increasing, do nothing but as soon as it starts to decrease, meaning you are at the peak of the sine wave, toggle one of the port pins on the PIC. If the PIC has a built in analog comparator, you can also do it by joining the two comparator inputs together, one through a short RC delay network and looking for the output changing state as the direct input drops below the delayed one.

Brian.
 

If the PIC has a built in analog comparator, you can also do it by joining the two comparator inputs together, one through a short RC delay network and looking for the output changing state as the direct input drops below the delayed one.

Brian.

Thank you very much,

I do not get it could you explain a bit more because the pic has comparator and I used before and work fine with fixed sine amplitude, however, if the amplitude go up and down this will make a problem because I fix the second input of the comparator for the certain voltage as the thresould and the first input I insert the sine wave. So, the first input of the comparator take the sine wave and the second input take the fix voltage as a reference but this will make a problem as I said earlier if the signal go up and down (amplitude).
 

I can't draw a schematic at the moment but connect one comparator input to the signal and instead of connecting the other input to a fixed threshold voltage, also connect it to the signal but through a resistor. From this input also add a capacitor to ground. The signal through the RC network will be slightly delayed with respect to the direct one so at peak waveform voltage it will reverse polarity across the comparator input as one voltage falls before the other. Use the comparator output to trigger the rise/fall of your square wave output. Note that there is an inherent delay in this system which you may be able to correct in software depending on the waveform frequency and stability.

Brian.
 

I can't draw a schematic at the moment but connect one comparator input to the signal and instead of connecting the other input to a fixed threshold voltage, also connect it to the signal but through a resistor. From this input also add a capacitor to ground. The signal through the RC network will be slightly delayed with respect to the direct one so at peak waveform voltage it will reverse polarity across the comparator input as one voltage falls before the other. Use the comparator output to trigger the rise/fall of your square wave output. Note that there is an inherent delay in this system which you may be able to correct in software depending on the waveform frequency and stability.

Brian.

Thank you very much Brian, in this case does not matter what max is ?
I want the spike in the max values, what I think about is that detect the max values and store in the array A and then I make the array A = B and then use if condition
if (A==B){portb.f0=1;delay_ms(10);portb.f0=0}
is it correct or not. I have tried but did not work!!!!!!!!!!!
 

The comparator method will work with any max voltage.

If you want to do it with an ADC there is no need to use an array. Just keep sampling and do somethng like this (not real code):

1. take sample A
2. take sample B
3. if B >= A value is rising - make B equal to A
4. if B < A value is falling - make B equal to A and start the pulse
5. go back to step 1.

The very first pulse may be wrong but you can fix that by initializing B to the maximum value before you start. Now at the point where the samples start to go down you know you are at the voltage peak. This method only uses two single variables, no array is needed.

Brian.
 

The comparator method will work with any max voltage.

If you want to do it with an ADC there is no need to use an array. Just keep sampling and do somethng like this (not real code):

1. take sample A
2. take sample B
3. if B >= A value is rising - make B equal to A
4. if B < A value is falling - make B equal to A and start the pulse
5. go back to step 1.

The very first pulse may be wrong but you can fix that by initializing B to the maximum value before you start. Now at the point where the samples start to go down you know you are at the voltage peak. This method only uses two single variables, no array is needed.

Brian.

I appreciate that Brian,

yes I will do it with ADC. I understand what you said. could you please see what I did and give me your suggestions.
1- Insert sine wave (5Hz-0.2s) to ADC.
2- Detect the max value in one period (0.2s).
3- store every max value in an array of A[5] for 5 peaks, that mean 5 period of sine wave.

Then what shall I do. I think about
1- define another array of 5 B[5]
2- if (A[0]==B[0]){ rise for 1ms} it will be a slit shift but no matter because every rise will have the same shift.

I am doing wrong please any advice for that. I already detected 5 max values what next.

Cheers !
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top