Measure PWM Signal of ADXL202???

General discussion on mikroBasic.
Post Reply
Author
Message
SMD-Bastler
Posts: 11
Joined: 22 Jul 2005 09:33

Measure PWM Signal of ADXL202???

#1 Post by SMD-Bastler » 22 Jul 2005 09:43

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

Charlie
Posts: 2744
Joined: 01 Dec 2004 22:29

#2 Post by Charlie » 22 Jul 2005 10:39

HI SMD-Bastler,

Can you tell me more about what you are doing? What are you doing after you read the signal?
Regards Charlie M.

SMD-Bastler
Posts: 11
Joined: 22 Jul 2005 09:33

Calculate angle in degrees

#3 Post by SMD-Bastler » 22 Jul 2005 11:58

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

Charlie
Posts: 2744
Joined: 01 Dec 2004 22:29

#4 Post by Charlie » 22 Jul 2005 22:35

Hello Blaster,

So If I understand correctly you want to read the Pulse and create a Delay based on if it is Greater or Less than 90 degrees?
Regards Charlie M.

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

Re: Calculate angle in degrees

#5 Post by xor » 23 Jul 2005 22:18

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.
Blaster,

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

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

Simple Hardware Solution to PWM to Angle Reader

#6 Post by xor » 24 Jul 2005 01:55

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.
Blaster,

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

SMD-Bastler
Posts: 11
Joined: 22 Jul 2005 09:33

I count with a loop

#7 Post by SMD-Bastler » 25 Jul 2005 06:58

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

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

Re: I count with a loop

#8 Post by xor » 25 Jul 2005 11:33

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
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.

WS

Post Reply

Return to “mikroBasic General”