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.

40 KHz square wave generation for driving ultrasonic sensor

Status
Not open for further replies.

mohsen_bmv

Newbie level 1
Joined
Jun 25, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
I want to generate 40khz square wave by ATtiny 2313v microcontroller in order to drive my ultrasonic sensor, how could i do this?
 

It is possible to generate 40kHz to a very high level of accuracy using a simple 555, which is easier and cheaper. Otherwise, with ATtiny2313, you could use the PWM
functionality.
 

Use a timer set to compare match that toggles the output

Code:
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 16000,000 kHz
// Mode: CTC top=OCR1A
// OC1A output: Toggle
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x40;
TCCR1B=0x09;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0xC8; // decimal 200
OCR1BH=0x00;
OCR1BL=0x00;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top