hobby_85
Junior Member level 2
ultrasonic pwm
Hey, hope everyones good.
I am currently playing around with some ultrasound transmitters and receivers. Just some basic stuff for now before I attempt a project of mine.
I have no used micro controllers before, so Im still pretty fresh in the area. However, I am willing to learn, and I am currently going through a couple of online tutorials.
For now, I would like to somehow configure the MC (Im using PIC 16f690) to send a PWM signal of 40 KHz to the ultrasonic transmitter. Ive come across this website which does the code for you if you type in the requirements, but I rather start from scratch and understand everything.
This is what the website says:
/*
* PWM registers configuration
* Fosc = 4000000 Hz
* Fpwm = 40000.00 Hz (Requested : 40000 Hz)
* Duty Cycle = 50 %
* Resolution is 6 bits
* Prescaler is 1
* Ensure that your PWM pin is configured as digital output
* see more details on https://www.micro-examples.com/
* this source code is provided 'as is',
* use it at your own risks
*/
PR2 = 0b00011000 ;
T2CON = 0b00000100 ;
CCPR1L = 0b00001100 ;
CCP1CON = 0b00011100 ;
And then I suppose you can use the following commands:
* Pwm_Init()
* Pwm_Change_Duty()
* Pwm_Start()
* Pwm_Stop()
So is this how you go about it? Set your frequency, duty cycle and your off? Can somebody please explain why the website comes up with the above values for PR2,T2CON and so on. And what are they?
Im sorry if this has been posted before, but ive been serching forums for hours on end without luck.
Any help would be appreciated. Just want to send a PWM signal o a ultrasonic transmitter.
Thanks!!!
Hey, hope everyones good.
I am currently playing around with some ultrasound transmitters and receivers. Just some basic stuff for now before I attempt a project of mine.
I have no used micro controllers before, so Im still pretty fresh in the area. However, I am willing to learn, and I am currently going through a couple of online tutorials.
For now, I would like to somehow configure the MC (Im using PIC 16f690) to send a PWM signal of 40 KHz to the ultrasonic transmitter. Ive come across this website which does the code for you if you type in the requirements, but I rather start from scratch and understand everything.
This is what the website says:
/*
* PWM registers configuration
* Fosc = 4000000 Hz
* Fpwm = 40000.00 Hz (Requested : 40000 Hz)
* Duty Cycle = 50 %
* Resolution is 6 bits
* Prescaler is 1
* Ensure that your PWM pin is configured as digital output
* see more details on https://www.micro-examples.com/
* this source code is provided 'as is',
* use it at your own risks
*/
PR2 = 0b00011000 ;
T2CON = 0b00000100 ;
CCPR1L = 0b00001100 ;
CCP1CON = 0b00011100 ;
And then I suppose you can use the following commands:
* Pwm_Init()
* Pwm_Change_Duty()
* Pwm_Start()
* Pwm_Stop()
So is this how you go about it? Set your frequency, duty cycle and your off? Can somebody please explain why the website comes up with the above values for PR2,T2CON and so on. And what are they?
Im sorry if this has been posted before, but ive been serching forums for hours on end without luck.
Any help would be appreciated. Just want to send a PWM signal o a ultrasonic transmitter.
Thanks!!!