Ultrasonic Range Finder, AT89C51

Thread Starter

myztic_man

Joined Apr 27, 2009
21
Hi there.

I am building an Ultrasonic range finder which runs at 40kHz. I have it running from a waveform Generator at present however I want to switch this to PWM from the Micro (AT89C51AC3).

I have code that sets up the PWM, and gets it running at 4kHz, however I do not know how I can increase this to 40kHz.

void MyInitPwm(){
CR = 1; //Turn on the PCA Timer/Counter
CCAPM0 = 0b01000010; //Enable PWM, Enable Compare
CCAP0H = 0x7F; // Sets Capture
CMOD = (CMOD | 0b00000011) & 0b11111011; // Enable PCA counter overflow and set to use internal clock/2
}

Any ideas?
 
Top