Hi,
I need a program to read the information of an ADXL202 PWM signal.
There is no library in Mikrobasic and I'm new in use PICs.
In my system I have a 16F876A PIC and an ADXL202JE.
Whow I can read out the pulse and pause?
Can you send me the program / code?
Best regards
Bastler
Measure PWM Signal of ADXL202???
-
- Posts: 11
- Joined: 22 Jul 2005 09:33
Calculate angle in degrees
Hi Charlie,
the ADXL202 outputs a PWM with 8ms periode. At 0 degree is puls / pause =1/2 (pulse 4ms / pause 4ms).
If now the sensor is +90 degree (pulse 7ms / paus 1ms) and at -90 degree (pulse 1ms / pause 7ms).
I can calculate the angle of the sensor with: x=(puls:pause)*var
Now I need only help to detect the pulse and pause as time or better as an variable as byte or word.
Best regards
Bastler
the ADXL202 outputs a PWM with 8ms periode. At 0 degree is puls / pause =1/2 (pulse 4ms / pause 4ms).
If now the sensor is +90 degree (pulse 7ms / paus 1ms) and at -90 degree (pulse 1ms / pause 7ms).
I can calculate the angle of the sensor with: x=(puls:pause)*var
Now I need only help to detect the pulse and pause as time or better as an variable as byte or word.
Best regards
Bastler
Re: Calculate angle in degrees
Blaster,SMD-Bastler wrote: the ADXL202 outputs a PWM with 8ms periode. At 0 degree is puls / pause =1/2 (pulse 4ms / pause 4ms).
If now the sensor is +90 degree (pulse 7ms / paus 1ms) and at -90 degree (pulse 1ms / pause 7ms).
I can calculate the angle of the sensor with: x=(puls:pause)*var
Now I need only help to detect the pulse and pause as time or better as an variable as byte or word.
Use your TMR0 counter and INTCON timer prescaler bits to set up an interrupt routine which at precise intervals samples the PIC input (ADXL202 output) pin for a high or low (1 or 0). Since you are working with ratios, just count the total of 1's and divide by total 0's, or vice-versa if required, to determine your angle. You can do some error checking by counting the total of 1's and 0's.
Or...since you know the the total period is 8ms, you can just count the number of 1's with a known interrupt interval and calculate.
Or....some PIC's have an edge-triggered hardware interrupt on some pins. When your pin goes high, do the interrupt routine by starting an internal timer, sampling the pin until it goes low. Your timer count at that point should give you enough information to make calculations, which you will have to do during the low pin time.
WS
Simple Hardware Solution to PWM to Angle Reader
Blaster,SMD-Bastler wrote:the ADXL202 outputs a PWM with 8ms periode. At 0 degree is puls / pause =1/2 (pulse 4ms / pause 4ms).
If now the sensor is +90 degree (pulse 7ms / paus 1ms) and at -90 degree (pulse 1ms / pause 7ms).
I can calculate the angle of the sensor with: x=(puls:pause)*var
Now I need only help to detect the pulse and pause as time or better as an variable as byte or word.
I can also recommend a relatively simple and inexpensive hardware solution. It's a pulse width to voltage converter circuit connected to one ADC input of your PIC. This is a very low MPU overhead circuit that creates a voltage proportional to the pulse width. Simply read your ADC input whenever it's necessary and convert to degrees. If you can manage a full range of 0V to 5V, you can have readings with resolutions to 1/10 of a degree and better (if your ADXL202 has that capability).
The circuit is found at the EDN website:
http://www.edn.com/article/CA46255.html ... to+voltage
This permits your PIC to perform other tasks such as processing data and output without taking time to manage real-time input.
WS
-
- Posts: 11
- Joined: 22 Jul 2005 09:33
I count with a loop
Hi, thanks for the answers.
I count the puls and pause with a loop, because I'm new in programming PIC's. I can't program the PIC in assembler.
Here my loops:
puls = 0
while PORTC.6 = 1
puls = puls + 1
wend
pause = 0
while PORTC.6 = 0
pause = pause + 1
wend
If you have a better solution, please post it.
Best regards
Bastler
I count the puls and pause with a loop, because I'm new in programming PIC's. I can't program the PIC in assembler.
Here my loops:
puls = 0
while PORTC.6 = 1
puls = puls + 1
wend
pause = 0
while PORTC.6 = 0
pause = pause + 1
wend
If you have a better solution, please post it.
Best regards
Bastler
Re: I count with a loop
That's the general rudimentary idea. Remember that you must consider what to do if you start your count in the middle of a high or low. You must scan your port pin until you reach a starting point to be accurate. I recommend that you also try learning how to use software and hardware interrupts. There are some examples on the MB CD. They will serve you well in a project like this.SMD-Bastler wrote:Here my loops:
puls = 0
while PORTC.6 = 1
puls = puls + 1
wend
pause = 0
while PORTC.6 = 0
pause = pause + 1
wend
WS