![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hello, I have a project I am working on. I was hoping someone could look over my notes & tell me if this is possiple & which chip would be best. If that chip is available as an 'easy to use' development board - great. If not - then I'll 'bread-board' it & experiment. If possiple - I would prefer the PIC chip to use direct USB communications - as that makes things easy for power & comms. I am trying to build a homemade dyno. The two inputs are engine RPM & Dyno drum rpm. These can be conditioned so that each 'event' is represented as 0 or 5+ volt signals. I have these signals working. For engine RPM - absolute min is 2 events per second (4 cycle engine, 1 event per cycle = 480 RPM). Absolute max is 500 events per second (2 cycle 'screamer' racing engine = 30,000 RPM). For dyno RPM - absolute min is 0. Absolute max is 83.33 events per second (single event per rpm - max 5,000 rpm). I wish to time when these events occur as accurately as possible (within reason). I was hoping to run a timer to 1 million of a second. Faster would be better if available. Here's how I imagined it might work... 1) Start the timer at 1Mhz 2) Every time there is an engine event - it triggers the PIC to send the timer count to the PC - with an identifier for engine rpm - like the value E200000 3) Every time there is a dyno drum event - it triggers the PIC to send the timer count to the PC - with an identifier for dyno drum rpm - like D300000 4) When the timer hits it's upper limit - reset it to 0 & send a message to the PC saying 0. That way - it would know when the timer is reset each time & it gives me a 0 reference relevant to the other readings. Does this sound realistic to achive with a PIC chip? Thanks Paul | |
| |
| | (permalink) |
| It is not trivial to use the USB on PIC. Also consider that you might need to write drivers for your device, unless you are using build-in staff. Try to implement it using USART if you can, this way you don't need to worry about the USB staff. Or, you can also use the Microchip application notes to implement the rs-232 over USB. | |
| |
| | (permalink) | |
| Quote:
As noted earlier the USB part is not trivial. For the most part you are just looking at building a pair of tachs. I am curious about the hardware?
__________________ search engine for electronic partsJunebug USB PIC programmer kit., USB Bit Wacker, 3v0's Homepage The 15 Minute Printed Circuit Board! (+drill time) | ||
| |
| | (permalink) |
| You can use the TMR1 as a counter, and there’s even an application note on how to make a 50Mhz Frequency Meter, but the error rate rises as the frequency does. Your Program would be very easy with the use of the PORTB Change Interrupt. Basically, this interrupt occurs when the state of PORTB.4/PORTB.5/PORTB.6/PORTB.7 changes. Your program will instantly leave what ever it is doing, and goto an interrupt handle. Here you simply check what pin has changed, and "poll" the state to compare against the last value to check which Pin has changed. Code: Interrupt PORTB_Change(2)
Save(0) // Save the system variables
If RBIF = 1 Then // Check if the interrupt was a PORTB change
RBIF = 0
WREG = PORTB // Be sure to read the contents of PORTB to clear the mismatch (hardware requirement)
If RPM.Pin <> RPM.LastPin Then // Check if the RPM has changed
RPM.Counter = RPM.Counter + 1
RPM.LastPin = RPM.Pin
EndIf
If DYNO.Pin <> DYNO.LastPin Then // Check if the DYNO signal has changed
DYNO.Counter = DYNO.Counter + 1
DYNO.LastPin = DYNO.Pin
EndIf
EndIf Restore // Restore system variables
End Interrupt And of course you would have a seperate Interrupt (with a higher priority) for the Timer. Code: Interrupt TMR2_Interrupt(1)
Save(0) // Back up system variables
If TMR2IF = 1 Then // Check if the interrupt was from TMR2
TMR2IF = 0 // Clear the TMR2 interrupt flag
Inc(mS) // Increment the mS counter
If mS = 1000 Then // Check if one second has occured
Disable(PORTB_Change) // If so, then turn off the interrupts
Disable(TMR2_Interrupt) //
Done = True // and set the Done flag
EndIf EndIf //
Restore // Restore system variables
End Interrupt UART would be a much eaiser option (and low cost), to send something to your PC; Code: Include "USART.bas" Include "Convert.bas" USART.Write(RPM = ", Convert.DecToStr(RPM.Counter)) USART.Write(DYNO = ", Convert.DecToStr(DYNO.Counter))
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net Last edited by gramo; 8th May 2007 at 08:18 AM. | |
| |
| | (permalink) |
| The simplest way to get USB functionality on a micro controller is to use one of FTDI's line of serial/parallel to USB interface chips. I have one on order from Futurelec (USBMOD2) if I ever get it. Mouser carries a module called the VDIP1 which looks a bit more sophisticated as it allows it to be connected as a USB storage class device, though it's probably more complicated to setup. The USBMOD2 chip I got is a straight forward high speed parallel interface to a virtual serial port on the PC.
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | (permalink) |
| Man, that chip (USBMOD2) costs US$29.20 ! And the one at Mouser costs $26.80 With the above program, and an 18F4550 for $6.42, you have USB with your PC/another device. Here's how you would wire it up; ![]()
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | |
| |
| | (permalink) |
| Microchip supplies royalty free license free drivers to let the PIC communicate to the PC as a virtual com port? Between labor and parts you're looking at 20-30 dollars in effort/bits to create even a basic PIC USB implementation.
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." Last edited by Sceadwian; 8th May 2007 at 02:42 PM. | |
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| That's why I like the modules. No code required PC side, it will interface directly to any program that can access a com port. It also comes with a DLL for direct use if you want to make custom USB device ID's and distribution of the drivers is completly user customizable and free.
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | (permalink) |
| gramo: what are you using to draw your schematics? | |
| |
| | (permalink) |
| Thanks for all the responses. Yes - I can program - VB 6 / VB .NET 1.1 & 2.0 I could tolorate C, C++, C# if I had to - but the development time would slow. I'm not clever but I am stubbon - I'll get there! ;-) It seems similar to a pair of tachs - but I need to know the time between each event (instead of counting pulses) AND 'where' in time each separate event happens with relation to each other. Gramo - very useful - thank you very much Yes - I've read the newer 'USB' PIC chips make life easy with regards to connection, power & programming. I found this site & this guy makes it look very easy to wire up the PIC chip - http://www.alanmacek.com/usb/ It's essentially what Gramo posted. Costs are all relevant to what you are used to. $7 or $30 for chips (and some tinkering time) seems dirt cheap to me when the electronics for a commercial dyno are $600 to $1000. Paul Last edited by PJ Adams; 8th May 2007 at 06:28 PM. | |
| |
| | (permalink) | |
| Quote:
Just wanted to add that SF has a free plug-in called EasyHID, it will create the Visual Basic/C++/Delphi code depending on the settings you required for your device. Handy. Sample code written by EasyHID Code: ' vendor and product IDs
Private Const VendorID = 6017
Private Const ProductID = 2000
' read and write buffers
Private Const BufferInSize = 8
Private Const BufferOutSize = 8
Dim BufferIn(0 To BufferInSize) As Byte
Dim BufferOut(0 To BufferOutSize) As Byte
' ****************************************************************
' when the form loads, connect to the HID controller - pass
' the form window handle so that you can receive notification
' events...
'*****************************************************************
Private Sub Form_Load()
' do not remove!
ConnectToHID (Me.hwnd)
End Sub
'*****************************************************************
' disconnect from the HID controller...
'*****************************************************************
Private Sub Form_Unload(Cancel As Integer)
DisconnectFromHID
End Sub
'*****************************************************************
' a HID device has been plugged in...
'*****************************************************************
Public Sub OnPlugged(ByVal pHandle As Long)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
End If
End Sub
'*****************************************************************
' a HID device has been unplugged...
'*****************************************************************
Public Sub OnUnplugged(ByVal pHandle As Long)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
' ** YOUR CODE HERE **
End If
End Sub
'*****************************************************************
' controller changed notification - called
' after ALL HID devices are plugged or unplugged
'*****************************************************************
Public Sub OnChanged()
Dim DeviceHandle As Long
' get the handle of the device we are interested in, then set
' its read notify flag to true - this ensures you get a read
' notification message when there is some data to read...
DeviceHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify DeviceHandle, True
End Sub
'*****************************************************************
' on read event...
'*****************************************************************
Public Sub OnRead(ByVal pHandle As Long)
' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontrolller...
End If
End Sub
'*****************************************************************
' this is how you write some data...
'*****************************************************************
Public Sub WriteSomeData()
BufferOut(0) = 0 ' first by is always the report ID
BufferOut(1) = 10 ' first data item, etc etc
' write the data (don't forget, pass the whole array)...
hidWriteEx VendorID, ProductID, BufferOut(0)
End Sub
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | ||
| |
| | (permalink) |
| Thanks Gramo - EasyHID is interesting. I've just looked at your site. I see you've experimented with a hall effect sensor for RPM - that's exactly the route I used for the dyno drum. And the reasons you list about inaccuracy of counting pulses is the reason I decided to run a fast timer / counter & count the time between pluses. Paul | |
| |
| | (permalink) | |
| Quote:
Your idea is great; I only leant toward the "Count for X milliseconds, and then scale up" as a simple to understand "suit any job" type application. But you’re right, if your signal is clean, there is no reason why you can't count between pulses. Be sure to use PORTC as the input source, as it has built in Schmitt triggers that will make your pulse sampling much more accurate, and less susceptible to noise. eg,
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | ||
| |
| | (permalink) | |
| Quote:
| ||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| ULTRA clean 9VDC Power Supply Project | Peter_wadley | Electronic Projects | 47 | 19th November 2008 01:54 PM |
| Need advice for choosing a PIC | ChemE | Micro Controllers | 10 | 15th April 2007 11:39 AM |
| interfacing PIC to 4511 and ICs | mikedf | Micro Controllers | 2 | 1st March 2007 07:04 AM |
| PIC Project advice - doubling frequency | coze | Micro Controllers | 8 | 26th February 2007 08:05 PM |
| Newcomers, please read! (PIC regarded) Upd. 0xD | Jay.slovak | Micro Controllers | 0 | 17th April 2005 02:05 PM |