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 from pic 16f877a with 4 mhz

Status
Not open for further replies.

tamer1221

Newbie level 5
Joined
Jan 2, 2009
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,334
pic 40khz

void main()
{

PORTC = 0;
TRISC = 0;

PR2 = 0b00011000 ;
T2CON = 0b00000100 ;
CCPR1L = 0b00001100 ;
CCP1CON = 0b00011100 ;

}
the problem is Pwm port is 5v all the time, is there another way to obtain 40khz without pwm
 

pwm 40 khz

Hi tamer1221

I normally work in assembler - much easier - and not subject to poor compilers!

Check that your compiled C is loading the correct RAM banks.

I used a slightly different value for CCP1CON but that is for 50%M/S ratio.

I have just run the code below on an 16F877A through MPLAB 8.30 and
ICD2 Debugger with no problems.

As a bonus if you HALT the 16F887A via the ICD2 Debugger the PWM keeps
running and you can modify the registers through the WATCH window and see
the results on a scope straight away - good for fine tuning hardware!

This also works:
MAKE an .asm file containing just an END statement
Program the processor via the ICD2 Debugger
Run the processor, HALT the processor
then - just poke the registers via the Watch Window with
the right values and the PWM will start running.

hope this helps
Polymath

;------------------------------------------------
;************************************************
;
banksel PORTC ; bank 00
clrf PORTC
;
banksel TRISC ; bank 01
clrf TRISC
;
movlw B'00011000'
movwf PR2
;
banksel T2CON ; bank 00
movlw B'00000100'
movwf T2CON

movlw B'00001100'
movwf CCPR1L
;
movlw B'00101100'
movwf CCP1CON
;
forever goto forever
;
;------------------------------------------------
;************************************************
 

pwm 40khz

Do you need constant 40kHz or do you need it for ultrasound range meter?

If you need it for US meter than it is easy .... turn on and off pin 8 times for ~12us and you have ~40kHz. (I used 12us on and 13 off in my project)
 

    tamer1221

    Points: 2
    Helpful Answer Positive Rating
pwm using pic16f877a 4mhz

sorry for delay bungee- and thank you yes i was ultrasonic and got stuck i converted to infrared , but if you can give your circuit diagram :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top