PDA

View Full Version : HPWM signal transfered to an other pin!



lilimike
- 21st April 2010, 18:49
Hi,

Using PBP 2.6
16F627A, 4MHz

Using HPWM Duty Cycle 50% at 40Khz for a period of 150 us with waiting time of 1 ms between periods.
It is generating the signal on RB3 as expected.
(Yup, the book says max of 32767Hz but it works at 40KHz)
It obviously have something to do with "long version of PBP" which I don't know the difference between the "long" and the "not long version"
I am just glad I seam to have the long version!


Getting back to my question, I am driving an ultrasonic transducer but applying the signal to only one of its pins does not generates enough Tx power.
Before I add more hardware I was wondering if it is possible to have RB3 trigger 1 other pin replicating the opposite of RB3s signal which would drive the Tx in a fashion where both Tx pins have opposit voltages (making it 10VPP) ?

Mike

Melanie
- 21st April 2010, 19:00
You can cross-feed your HPWM to one of the Hardware Comparators and have it invert the signal.

lilimike
- 21st April 2010, 22:50
Sounds simple,

I presume I only need one comparator so I would make CMCON = %100101
I would then connect RA1 (VIN-) to ground and feed RA2(VIN+) from RB3 (PWM signal)
I would connect my Tx to RA2 and pick another unsused pin (RB5)

I figure I would get the inverted signal from RA2 by reading CMCON.7

But how to I pass the value of CMCON.7 to RB5?

Or am I going the wrong way?

This is what works feeding just one pin of the Tx


Main:

;reset timer
hpwm 1, 127,40000 ; Send burst, Ch1, D.Cycle50%, Freq 40Khz
pauseus 150 ; length of burst.
CCP1CON = 0 ; Turn off PWM
pause 100 ; Wait to prevent picking up
; noise generated by Tx
; detect timer overflow
; do the maths
; display results
GOTO Main



Mike

lilimike
- 22nd April 2010, 17:20
Ok so I think I have my answer (mostly).

I realized I must use this operating mode to access the output directly from an I/O pin:
4240

Therefore I have used CMCON = %110
Connected RB3 (PWM signal) to RA0
and I can see the inverted signal on RA3


Now I still have an issue, the rising edge of RB3 happens at the same time as the falling edge of RA3 but the rising edge of RA3 happens 4uS after the falling edge of RB3.

Is there something I can do to fix this?

Thanks

Mike

lilimike
- 22nd April 2010, 18:32
Found it...!
I added a 100K resistor between RA2 and +5, not sure if 100K is the perfect value but it works.

Thanks for the guidance.

Mike

lilimike
- 22nd April 2010, 19:02
Now I am starting to feel psycho responding to myself that many times but after putting my glasses on, it is a 180 ohms I have there and the delay is now 80nS, tried 1k and got 120nS, also tried direct but no go.
So 80nS is acceptable and way better than 4uS.

If anyone can figure out a way to make it 0 delay that would make things just perfect.

Mike

Melanie
- 22nd April 2010, 19:09
You won't make it zero. There's hardware between the input and output, and it takes time for the little electrons to wiggle their way through very tiny wiring. You could always strap RA2 directly to +5, but it won't get much better than that. The performance limits are somewhere in the back of the Datasheet.

lilimike
- 22nd April 2010, 19:25
I tried to connect RA2 direct to +5 but that gives me a straight 5 V at RA3

But its good now, I have improved the range, driving one side of the Tx was 10 feet and now having the inverted output I get 28 feet.

I will probably improve more when I get to the mechanical aspect.

Thanks for your help.

Mike