On Fri, 21 Nov 2003 14:26:00 +0100, you wrote: >New to PIC's and not having a degree in electronics, I have a question: > >I want to drive an ultrasound transmitter (pi=EBzo, 40 kHz) directly = from picpins. I tested this using the PWM on a 877A. The transmitter is = connected between the pwm-output and Vdd. This produces a very good = ultrasound sinewave. > >Next, to increase the transmitter's output, I connected the transmitter = between RD0 and RD1 on a 18F452 running at 40Mhz and wrote some code to = generate a 40kHz block. I toggle both pic-pins in a single cycle in an = attempt to create a pure wave as much as possible. This means that one = pin goes from sinking to sourcing and the other pin going from sourcing = to sinking in a single 100ns cycle. This did not work a I expected. After= some more experimenting using the scope, I came with the following = explanation: > >What I am doing asks to much from the pins as pin switching-times for = sourcing to sinking is not equal to the time from sinking to sourcing. = Furthermore, the timings on the pins are not necessarily equal on both = pins (probably they are not). This results in effectivily shorting Vdd to= Vss for a very brief moment through both pin-drivers. > >Is this assumption correct? What timing should I use to do the toggling = safely? Is seperating the toggle into two instructions enough? This is probably not working as the capacitance of the transducer is = causing read-modify-write problems, i.e. when you write the second pin, the first has not reached = its intended state, so the wrong value is read and written back. A simple solution is to switch bith pins simultaneously in one = instruction, either :=20 movlw 1 ; setup movwf portd loop movlw 3 xorwf portd ; this will invert both pins or =20 loop movlw 1 movwf portd =20 movlw 2 movwf portd The former method has the advantage that it is easier to guarantee a 50% = duty cycle, which can be important for some types of piezo transducer -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body