Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need to generat AC signal using PIC micro...

Status
Not open for further replies.

c-dog

New Member
Hi,

I'd like to know how I can generate an AC signal using a PIC micro? A soil moisture sensor I am researching requires an ac signal for it to operate. Is it as simple as using one of the analogue outputs or is there some interface hardware I may need to use?

Any help would be appreciated. Thanks

c-dog
 
Soil moisture probably will work ok with a square wave ( you should research this ) which is easy to generate ( pwm or software timing loop ). But the pic runs on a single ended power supply so you should couple thru ( probably fairly large value ) cap, or use a bipolar supply and sutiable drive circuit. Specs on the required signal would of course help.
 
Last edited:
The signal specs would need to be anywhere between 3 - 9V peak, 20 milliamps, ~100Hz. I believe this would be ideal for the sensor I'm looking at.
 
A pic can very easily output a 9Vpp 100Hz 20mA square wave without any additional circuitry. If a square wave is adequate and that is the only thing the pic needs to do then any of the small pics will do. What language (asm, C, Basic) are you intending to use.

Mike.
 
A pic can very easily output a 9Vpp 100Hz 20mA square wave without any additional circuitry. If a square wave is adequate and that is the only thing the pic needs to do then any of the small pics will do. What language (asm, C, Basic) are you intending to use.

Mike.

I run my pic's on 5 volts single ended which gives only 2.5 peak to peak after passing thru a cap. Some people run on lower voltages, I do not quite see how you get 9 Vpp. ( feel free to enlighten me if I am mistaken ) 20ma is near the max current per port bit. I guess you can put a few in parallel if you do not want to operate near the max.

I would use a one transistor booster running on about 10 V ( single ended ) taking the output from the collector. Not very efficient but at 20 ma may be ok.

Other options.....
 
I run my pic's on 5 volts single ended which gives only 2.5 peak to peak after passing thru a cap. Some people run on lower voltages, I do not quite see how you get 9 Vpp. ( feel free to enlighten me if I am mistaken ) 20ma is near the max current per port bit. I guess you can put a few in parallel if you do not want to operate near the max.

You use two pins to give a bridged output, this doubles the output from 5V p-p to 10V p-p, and also means you don't need a coupling capacitor, as it swings either side of zero.

It's really VERY simple, and only requires a couple of extra lines of code.

I modified an old EPE project for a freezer (and the magazine printed the changes), it feed a piezo sounder, and doing this made it four times as powerful at no extra cost.
 
A pic can very easily output a 9Vpp 100Hz 20mA square wave without any additional circuitry. If a square wave is adequate and that is the only thing the pic needs to do then any of the small pics will do. What language (asm, C, Basic) are you intending to use.

Mike.

I would like to see how you set that up I'm dumb and blonde today I think I no what you and Nigel are saying but I can't see how it swings with two
pins :confused:
 
Two pins, call them 1 and 2.

Make 1 high and 2 low, so 1 is 5V positive of 2.

Now make 1 low and two high, so 1 is now 5V negative of 2.

10V swing from a 5V supply.

It's exactly how bridged amplifiers (and h-bridges) work, giving twice the voltage from a single supply.
 
Thanks Nigel I see now i was thinking right switch it fast and it's 10 volts
 
Then this just happens
Need to generate AC signal using PIC micro...
You have to switch some thing come on here if like Nigel said set pin 1 high pin 2 low
then make pin 1 low and and 2 high
Your going to tell me there no switching there Has to be.
 
Then this just happens
You have to switch some thing come on here if like Nigel said set pin 1 high pin 2 low
then make pin 1 low and and 2 high
Your going to tell me there no switching there Has to be.

I think his point was, it doesn't have to be fast - that just sets the frequency of the AC - switching it slowly generates exactly the same voltage, just at a lower frequency.
 
This makes ac volts p-p 9volts
Code:
	list      p=12F683        ; list directive to define processor
	#include <p12F683.inc>    ; processor specific variable definitions

	errorlevel  -302          ; suppress message 302 from list file

	__CONFIG   _FCMEN_OFF & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_OFF & _INTRC_OSC_NOCLKOUT 

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings

		Cblock	0x20  
		d1
		d2
		endc
		
		#define	Data 	GPIO,0
		#define Clock	GPIO,1

		org   	0x0000      	; org sets the origin, 0x0000
        goto    Start   		; go to beginning of program 
		org	  	0x0004			;interrupt vector
		goto 	Start

Start		
		movlw   07h            ; Set GPIO <2:0) to
        movwf   CMCON0         ; digital I/O
		clrf   	ANSEL         ; digital I/O
		movlw   b'1110101'
        movwf   OSCCON         ;8MHz internal oscillator
	

		banksel	TRISIO
		movlw	b'00000000'
		movwf	TRISIO
		banksel	GPIO
		clrf	GPIO
		goto	main
main:	
		banksel GPIO
		movlw	b'00000001'
		movwf	GPIO
		call	Delay
		movlw	b'00000010'
		movwf	GPIO
		call	Delay
		goto	main

Delay
			;1993 cycles
	movlw	0x8E
	movwf	d1
	movlw	0x02
	movwf	d2
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return



	end
 
Sinusoidal

Hi,

I'd like to know how I can generate an AC signal using a PIC micro? A soil moisture sensor I am researching requires an ac signal for it to operate. Is it as simple as using one of the analogue outputs or is there some interface hardware I may need to use?

Any help would be appreciated. Thanks

c-dog

I recall reading that probes are driven not with square waves but sinusoidal ones...
 
Sinewaves

Not a problem - see detailed instructions here :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top