UBW interrupt driven inputs?

USB PICs and the UBW

Moderator: phalanx

Post Reply
bpwwer
Posts: 3
Joined: Sun Dec 16, 2007 3:50 pm

UBW interrupt driven inputs?

Post by bpwwer » Tue Dec 18, 2007 11:40 am

Hi,

I just ordered a UBW to test for a personal project I'm working on. But I think I'm going to have to modify the firmware to make it work. Searches here and on the web haven't provided any solid information so here goes....

I need a method to count pulses and have the pulse count available to my host PC. I don't think the rate will be above 60Hz so that should be supportable by the UBW. I could probably poll UBW fast enough to catch most of the pulses, but it would be much better if the UBW could keep track of them so I could query it for a count at a slower rate, say .5 or .1 second intervals.

What I'd like to do is hook up my pulse generator (a hall effect switch) to an input pin on the UBW, set up that pin as an interrupt. Then write an interrupt handler in the firmware that simply increments a variable.

I'll need a couple of new commands in the firmware, one to clear/write that variable and another to read it. (maybe the MW/MR commands would work for that?).

On the surface, this seems like it would be pretty simple to do, but since I don't yet know what I'm doing, I suspect that it isn't as easy as it seems :) I have quickly scanned the 1.4.2 firmware source and my initial questions are:

1) How do you configure one of the I/O pins as an interrupt?
2) Where in the source would that code go?

I'm also curious to know if this would be of general interest. If so, I'll try to incorporate it into the existing firmware as a new feature. If not, I'll probably end up ripping out most of the code I don't need and make the firmware specific to my application.
--
Bob

User avatar
EmbeddedMan
Support Volunteer
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Post by EmbeddedMan » Tue Dec 18, 2007 12:04 pm

bpwwer,

Cool! I think your idea is great, and one that I have wanted to include in the firmware for a long time.

I think the best way for you to do this is to add some extra commands into the firmware. You'll probably have to use PORTB interrupt on change. You'll add your ISR code into the void low_ISR(void) function in user.c, and then add the command code as one of the parse_<xx>_packet() functions. One way to do it would be to have a 'configure' command that sets up this mode, tells the UBW which pins to 'care about', and tells it to count rising edges, falling edges, or both, and turns on/off the functionality. Then there would be another command that sends back the current edge count on all of the pins. It should be pretty straightforward.

If you code it in such a way that it is easy for me to add into the 1.5.0 firmware that I'm working on, I'd love to have it be part of the normal firmware.

*Brian

bpwwer
Posts: 3
Joined: Sun Dec 16, 2007 3:50 pm

Post by bpwwer » Tue Dec 18, 2007 6:45 pm

Thanks Brian,

You've pretty much confirmed what I thought was needed. I'll try to incorporate my changes cleanly into the existing firmware and send you the changes. Of course this could be a while since I don't even have the UBW yet (it shipped today).
--
Bob

bpwwer
Posts: 3
Joined: Sun Dec 16, 2007 3:50 pm

Post by bpwwer » Tue Jan 08, 2008 2:06 pm

I've been busy with other projects but wanted to give anyone interested an update.

It was actually very easy to get an interrupt driven counter implemented. The changes to the software are minimal and I was able to integrate it fairly well with the existing code.

I added two commands:

CC - configure counter. This configures the RB0 pin as INT0 and initializes the count to zero.

GC - get counter. This returns the current value of the counter.

I added code in the interrupt hander that checks if it was the int0 interrupt that triggered and if so, increment the counter.

That's it. Initial testing has been positive.
--
Bob

User avatar
EmbeddedMan
Support Volunteer
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Post by EmbeddedMan » Tue Jan 08, 2008 3:26 pm

Bob,
Those sound like great commands. When you have it where you want it, would you like to send me the code? I can integrate it into the upcoming 1.5.0 release.

*Brian

spdonegan
Posts: 1
Joined: Wed Jan 23, 2013 7:25 am

Re: UBW interrupt driven inputs?

Post by spdonegan » Wed Jan 23, 2013 7:32 am

I have a use for this ability - current firmware appears to be 1.4.9 - is 1.5.0 going to be released? Can you release the CC/GC code additions? My use is for a Hall sensor on the chassis of a race car counting front wheel rotations :-) The car in question has two magnets on the rim and a industrial strength hall sensor to pick up the pulses, so it is 2 pulses per rotation. At 160+ MPH I expect the pulse rate is fairly reasonable.

User avatar
EmbeddedMan
Support Volunteer
Posts: 1362
Joined: Sun Mar 05, 2006 9:23 pm

Re: UBW interrupt driven inputs?

Post by EmbeddedMan » Wed Jan 23, 2013 2:04 pm

The 1.5.0 version is not ready to be released. I also have not received the code updates from this thread. My advice is to try and contact bpwwer directly and get his code.

*Brian

Post Reply