- Joined
- Jul 4, 2009
- Messages
- 16,243
- Helped
- 5,140
- Reputation
- 10,309
- Reaction score
- 5,122
- Trophy points
- 1,393
- Location
- Aberdyfi, West Wales, UK
- Activity points
- 137,460
Hmmm, I managed to watch the Youtube video, despite very slow internet here. They work on a slightly different principle to what you are trying. Before going further, can you tell me what hardware you have connected to the sensors. I need to know what there is between your TX pin and the transmitting transducer and also what you have between the receiving transducer and the RX pin. This is critical to the way it works.
I don't think the clock signal is the problem and certainly 100MHz is far higher than necessary. You present code will not loop so you can't take continuous readings. The PWM will be turned off and the program will loop forever without taking any further measurements after the first interrupt occurs. May I suggest you rearrange the code slightly like this:
1. create a global variable, lets call it "MeasurementTaken", set its value to zero.
2. in the interrupt routine, stop Timer 0 from counting, copy the values in Timer 0 to a variable, make MeasurementTaken = 1, stop the PWM.
3. in the main() routine, set up the PWM and other PIC registers.
4. set Timer 0 to zero
5. turn the PWM on.
6. start a while(1) { loop
7. use "if(MyMeasurementTaken) {report the reading in the variables you set in the interrupt routine then set MeasurementTaken = 0, clear Timer 0 then turn the PWM on again}
8. close the while loop
This will take repeated measurements between interrupts and you can take as long as needed in step 7 to report the value by LCD or serial link. Steps 4 and 5 are to ensure the first measurement is valid, from then on the same steps are taken inside the while loop but only after the MeasurementTaken variable lets it know that an interrupt occurred and they need to be prepared again.
Brian.
I don't think the clock signal is the problem and certainly 100MHz is far higher than necessary. You present code will not loop so you can't take continuous readings. The PWM will be turned off and the program will loop forever without taking any further measurements after the first interrupt occurs. May I suggest you rearrange the code slightly like this:
1. create a global variable, lets call it "MeasurementTaken", set its value to zero.
2. in the interrupt routine, stop Timer 0 from counting, copy the values in Timer 0 to a variable, make MeasurementTaken = 1, stop the PWM.
3. in the main() routine, set up the PWM and other PIC registers.
4. set Timer 0 to zero
5. turn the PWM on.
6. start a while(1) { loop
7. use "if(MyMeasurementTaken) {report the reading in the variables you set in the interrupt routine then set MeasurementTaken = 0, clear Timer 0 then turn the PWM on again}
8. close the while loop
This will take repeated measurements between interrupts and you can take as long as needed in step 7 to report the value by LCD or serial link. Steps 4 and 5 are to ensure the first measurement is valid, from then on the same steps are taken inside the while loop but only after the MeasurementTaken variable lets it know that an interrupt occurred and they need to be prepared again.
Brian.