Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB

Ads

Discussion Groups

Discussion Groups | BasicX | Re: counting pulses on the bx-24

Discussion forum for the BasicX family of microcontroller chips.

counting pulses on the bx-24 - cc0x1 - Nov 15 0:28:00 2005

Hi,

I'm a bit new to the bx-24 so please bear with me.

I need to count pulses from three different sources while at the same
time reading a continuous analog input on the bx-24. now i know that
using pulsein() or countTransitions() on the bx-24 halts all other
execution. using hardware interrupts doesn't seem like an option as
there is only one interrupt pin on the bx-24. i'm counting the pulses
every second but still need to read that analog in at 9600 baud.

can anyone offer any suggestions on how to do this? is it just a
matter of using putQueue() in the right way? i know this is probably
pretty simple, i'm just a little stuck right now.

thanks,
carlos





(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )


Re: counting pulses on the bx-24 - Mike Perks - Nov 15 1:10:00 2005

cc0x1 wrote:

> I need to count pulses from three different sources while at the same
> time reading a continuous analog input on the bx-24. now i know that
> using pulsein() or countTransitions() on the bx-24 halts all other
> execution. using hardware interrupts doesn't seem like an option as
> there is only one interrupt pin on the bx-24. i'm counting the pulses
> every second but still need to read that analog in at 9600 baud.

Sounds like you could do this with the multitasking abilities of BasicX
but we need more information on what you are trying to do.

How often do you need to count pulses and what is the frequency of
pulses? You can use some combinatorial logic to overlap the pulses so
that you receive an interrupt whenever a falling edge occurs any pulse
and then check that pulse input - this needs 4 I/O pins. Inside the
interrupt routine you may need to look for additional pulses that happen
while inside the interrupt.

What do you mean by reading a continuous analog input at 9600 baud -
does that mean you need 10,000 ADC readings per second - it's not clear
to me.

> can anyone offer any suggestions on how to do this? is it just a
> matter of using putQueue() in the right way? i know this is probably
> pretty simple, i'm just a little stuck right now.

The plan is to first of all write separate tasks for each kind of input
and test individually. Then combine the tasks together. You may have 3
tasks altogether: Control, AnalogIn and PulseIn. You may need to do some
careful tuning of the stack space for each individual task as well.

Mike




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: counting pulses on the bx-24 - cc0x1 - Nov 15 1:46:00 2005

Thanks Mike,

what I basically have is three transistor-oscillator circuits and i
want to measure the frequency of those while at the same time
measuring an analog voltage coming into an adc. the frequency of the
pulses (how many pulses per second) is what i want to measure.

what i meant by "read that analog in at 9600 baud" is that i'm
currently using countTransitions() to count every 1.0 seconds but i
need to send the ADC value continuously (over the serial port, which
is set to 9600 baud). so i don't want to wait for countTransitions().

Hope that makes better sense.

your advice was helpful. I think between that and the bx docs i
should be able to figure something out. Any other tips or code
snippets, etc that you may have would be much appreciated.

-Carlos --- In basicx@basi..., Mike Perks <basicx@a...> wrote:
[]




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Re: counting pulses on the bx-24 - Mike Perks - Nov 15 8:50:00 2005

cc0x1 wrote:

> what I basically have is three transistor-oscillator circuits and i
> want to measure the frequency of those while at the same time
> measuring an analog voltage coming into an adc. the frequency of the
> pulses (how many pulses per second) is what i want to measure.
>
> what i meant by "read that analog in at 9600 baud" is that i'm
> currently using countTransitions() to count every 1.0 seconds but i
> need to send the ADC value continuously (over the serial port, which
> is set to 9600 baud). so i don't want to wait for countTransitions().

So you definitely need several tasks here. When you write a loop in a
task make sure you have at least a sleep(0) in it so that other tasks
get a chance to run. Unless there is an interrupt or a task enters into
some kind of wait state (I/O) then each task can run for at least one
timer tick at a time.

> your advice was helpful. I think between that and the bx docs i
> should be able to figure something out. Any other tips or code
> snippets, etc that you may have would be much appreciated.

Check out my IR detector sample code for a task that uses InputCapture
(really just more sophisicated CountTransitions but same idea) and a
queue to communicate between that task and the main control task.
Debugging tasks is not easy and make sure you have enough stack space.
Decrease it when you get things working and use bxDism to help determine
the optimal size. Realistically with the small amount of RAM available,
you can only have a maximum of 3 tasks.

Mike




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: Re: counting pulses on the bx-24 - Mike Perks - Nov 15 8:52:00 2005

Mike Perks wrote:

> Check out my IR detector sample code for a task that uses InputCapture
> (really just more sophisicated CountTransitions but same idea) and a
> queue to communicate between that task and the main control task.
> Debugging tasks is not easy and make sure you have enough stack space.
> Decrease it when you get things working and use bxDism to help determine
> the optimal size. Realistically with the small amount of RAM available,
> you can only have a maximum of 3 tasks.

I forgot the link: http://home.austin.rr.com/perks/micros/Experiments/

Mike




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )

Re: counting pulses on the bx-24 - arhodes19044 - Nov 15 9:53:00 2005

re: ADC. I have used the AVR hardware to start continuous ADC
conversions at a certain rate, up to about 100K/Sec. I used a much
slower rate.

Ths way, there is a relatively fresh ADC reading in the ADC register
without having to wait to initiate and then read a conversion.

I have never tried to interract with these registers on the BX, so I
don;t know if it can be done.

Never the less, as others have said, you will need to have either a
task or a subroutine to do/read the conversions

Also you will need a task to read the pulse interrupt. I did this
with 2 separate pulse inputs but the technique is the same for a
third. The problem is that many of the devices I used for glue
logic are dual, so you will need 2 devices to do 3 pulse inputs, and
you could do a 4th for "free"

Don Kinzer showed me a schematic (posted in the files section here)
of a 1 shot vibrator plus a latch. The pulse comes in, passes thru
a schottky inverter (or 2 depending on rising vs falling edge
needs), then to the one-shot, then to the latch.

The output of the latch goes to places. One is a dedicated regular
I/O pin on the BX, and the other to a 3 or 4 input OR gate to go to
the interrupt pin. WHen the interrupt triggers, you know that at
least 1 pulse detector triggered. Then you read all the latches and
when you are done reading one, you toggle the latches reset pin.
When all the latches are reset, the interrupt pin will go inactive.

In the simplest form, you will need (for N pulse detectors) 2*N + 1
I/O pins. If you use 2 multiplexers (one for input, and one for
output), you can reduce your I/O pin usage to 5 pins for 3 sources,
or 7 for 4 sources instead of 7 and 9 respectively. If you needed 7
sources, you could still do it with 7 pins!

You can also reduce your pin count if you reset all latches with
just one pin. I have not thought out the ramifications of that
technique, but it can be done. You may well need diodes between the
BX "reset" pin and each of the latch reset pins, but I am not
positive off the top of my head.

Anyway, this is a reasonably straight forward problen, but does
require a number of external "glue logic" parts.

I can be more specific about what I did for my project if you want
to know more.

-Tony




(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )