MOBILE HOME Technical Tips  

USB FREQUENCY COUNTER AND VOLTMETER

Updated on 11.6.2015
Using PIC18F2550 for connecting analogue and digital signals to USB port . Included Visual Basic 6 code, Visual Studio 2005 C# code, PIC ASM code, PIC C code and a circuit diagram. The PIC microcontroller has 10 bit analogue to digital converter, by selecting 8 bits conversion the 2 LSB are ignored. The circuit is powered by the USB. The interface to the PC is HID class.
The frequency counter has a range of up to 4MHz (24bits). Inputs samplings can be done at rates of 1 per second and 1 every 0.1 second.
HID class (human interface device) is a class of devices like the mouse and the keyboard, the data transfer rate is limited to 64KB/S. The PC already has a driver for HID USB.
C# code is modified Microchip code from the USB framework, Microchip Solutions v2012-04-03.
VB6 code
includes guidance to setting up the PC. The PC register the PID and VID (product ID) of the USB device when it's plugged, the VB code uses these ID's to communicate with the device. For commercial VID it is needed to buy it from USB-IF, but in your lab you can use any number.
The source code is derived from freeware from these sources:
http://janaxelson.com/usb.htm , http://openprog.altervista.org/USB_firm_eng.html
You are free to use the circuit diagram and the VB software with no limitations.

The VB6 application is a combined digital and analogue voltmeter.

Circuit Description
See also Technical Tips

PIC18F2550
Pin 3 is the analogue input, voltage range 0 to 5V. Max input voltage is 5.5V .
Pin 11 is the counter input, TTL voltage levels.
Pin 14 is 3.3V internal supply for the USB transceiver. 0.22uF is required for regulation.
Pins 15,16 are the data lines to the USB connector on the PC.
Pin 20 is the PC 5V powering the PIC. It is limited to 100mA by the PC. 0.47uF is for decoupling.
For USB wiring info: http://www.interfacebus.com/Design_Connector_USB.html





Name:

Comments and questions

Copy the number from the picture It stops net-robots from adding comments.



14.04.2017 - 02:42
Name: Moty
Comment: The HEX file has to be programmed to the pic without any bootloader. You can use PICKIT 2/3 or similar programmer.

14.04.2017 - 00:19
Name: Ahmed
Comment: i meant source for the HIDbootloader, thanks

14.04.2017 - 00:18
Name: Ahmed
Comment: hi Moty, could you please provide de 18f2550 hidbootloader.hex and source for this excellent project? thanks for your help.

01.10.2016 - 02:27
Name: kanishka wijayananda
Comment: great! great! well done! thanks moty

02.03.2016 - 08:50
Name: wimpie
Comment: Hi my email is wimpieswanepoel1@gmail.com .if any one can help thanks

02.03.2016 - 08:48
Name: wimpie
Comment: Hi can i ask .i am building a sd card player useing a pic 16f690 i want 4 select switches that will play 4 short wav files on sd card .i am useing flowcode 4 but can not get it to work .and dont understand c code .any help thanks in advance

24.10.2015 - 21:40
Name: Moty
Comment: Hi Olakunle. I don't know the answer, try to get help from electronics forums.

24.10.2015 - 06:09
Name: Olakunle
Comment: please, how can I transmit a monochrome picture bit map from one pic 16f877 microcontroller, then at the destination pic16f877, how can I assemble the transmitted bit map into a file and give it d name of the source image monochrome bit map file e.g truck_bmp.c and then pass this file to Glcd_Image to help me draw the image on the Glcd of the destination pic 16f877. with the help of the mikro c online ebook, I have been able to display a monochrome image on the glcd using Glcd_Image (truck_bmp), so what I would like to do now is to transmit this image from the source to the destination. Thanks. Kunle

23.08.2015 - 23:46
Name: Richard Bahr
Comment: Some of the website links are dead Error 404 etc.

15.05.2015 - 03:49
Name: Ернар
Comment: хорошая идея

26.04.2014 - 11:24
Name: Moty
Comment: Hi. I've looked at your work, it is very impressive. Unfortunately I don't have the knowledge and the tools to use C#. I'm glad to be an inspiration.

25.04.2014 - 10:53
Name: N1c0
Comment: Hi Moty, An extended version of the USB Voltmeter was developed based on your schema & firmware. The client application sources can be found here: https://github.com/neremin/USB_Voltmeter It was developed using C# 4.0. It will work with you counter as well, in case you are interested in trying it. Thank you for publishing your project as a starting point for my work.

10.01.2014 - 02:14
Name: Moty
Comment: Hi ttede, I don't have experience with Proteus. Please ask your question but I can't promise to give help.

09.01.2014 - 11:29
Name: ttwde
Comment: Hello! I tried the in program Proteus your scheme to see it works correctly. Voltmeter shows nothing but Proteus it reacts, flashes 27 input PIC. Write please me your e-mail. My e-mail: ttwde@rambler.ru

25.05.2012 - 00:32
Name: Luis Alfonso Pulido Perez
Comment:

30.07.2010 - 19:49
Name: Moty
Comment: Hi Eduardo. The software I sent you is for Microchip C18, it will compile on C18 only. Because of the complexity of USB it will be to hard to migrate the software. You may find USB HID software for CCS on the net. I have no experience with CCS. Download the new C software for usbio from my website, it's for C18 but may give small number of errors when compiled on CCS.

30.07.2010 - 19:48
Name: Moty
Comment: Hi Alejando. To do what you want you need a HID Bootloader, the bootloader comes with an application for the PC to write the hex file to the PIC. You can find all the information and software you need free on Microchip website. You can also use other free bootloaders available on the net. My firmware will load on a PIC with bootloader only after re-compiling with bootloader linker file. The linker file arranges the location of the bootloader and the main application in the ROM of the PIC.

30.07.2010 - 00:15
Name: Alejando Ramos
Comment: Moty, I saw my brother assembly your circuit, i have a doubt, can we use the PIC in HID mode and write to the EEPROM?, my idea is to disconnect the PIC after loading a program and put the PIC in RUN MODE so it can be the brain of a robot or any other autonomus dvice, I did it but using a JDM Serial Programmer, it will be great to use the HID and don't have to unplug the PIC to program in the JDM programmer every time we would like to modify the program voltronch@hotmail.com

30.07.2010 - 00:07
Name: Eduardo Ramos
Comment: Hello Moty, which compiler do you use?, we tried the CCS and Mplab after modifying you main.c file to have all the Port B as Outputs. eduardoramosgaz@hotmail.com, v771v771@hotmail.com

29.07.2010 - 13:06
Name: Moty
Comment: Hi Regen. I've added tips about increasing the input voltage, please see the Technical Tips page: http://www.moty22.co.uk/general.php

02.07.2010 - 15:43
Name: Moty
Comment: Hi Eduardo. The HID device receives every 10ms 8 bytes from the PC together with the 8 bytes it sends. In the firmware the array of 8 bytes is named: ReceivedDataBuffer[ ] , the frequency counter uses byte1 for selecting the timebase, you can find the code in main.c . Bytes ReceivedDataBuffer[2] up to ReceivedDataBuffer[7] can be used to receive data. The VB6 sends array named: OutputReportData( ) . Byte0 is used for ID, you can use byte2 up to byte7 to send data to the device. The firmware already drives a LED. Connect the LED cathode to ground and the anode via 1K resistor to RB5 of PIC18F2550, By selecting the timebase on the VB you switch the LED on or off. You can see the instruction for that on line 209 of main.c - PORTBbits.RB5=ReceivedDataBuffer[1];

02.07.2010 - 03:07
Name: Eduardo Ramos
Comment: The HID also permit to write to a device ? I mean can we write a program that can move a motor o turn on a led through the PIC ?

21.06.2010 - 21:23
Name: Moty
Comment: Hi Eduardo. Yes, you can use the hex file on the PIC18F2450. The programme is about 2.1KB so it will easily fit into the ROM.

19.06.2010 - 21:34
Name: Eduardo Ramos
Comment: Hello, if I use the PIC18F2450 instead of the PIC18F2550, it will work loading the same V-Fmk2.hex file ?, If not what must I change in the file? regards,


16.06.2010 - 00:52
Name: Eduardo Ramos
Comment: Wow!, Fantastic, It wasn't working in my PC until I installed a HID device, Can you send me the V-Fmk2 c file ? my email is eduardoramosgaz@hotmail.com, thanks for share your knowledge, regards,

16.06.2010 - 00:46
Name: Eduardo Ramos
Comment: Wow! Fantastic, it wasn't working in my pc until I installed a HID device, I want to learn how to program it, can you send me the V-Fmk2 c file, thanks for share your knowledge, my email is eduardoramosgaz@hotmail.com,


19.05.2010 - 04:18
Name: Eduardo Ramos
Comment: eduardoramosgaz@hotmail.com Hello Moty, I assembly the circuit, and program the firmware "V-Fmk2.hex" using the WinPIC800 program and a JDM programmer circuit, but 1.- when I connect the usb circuit to the PC this doesn't recognize a usb device attached 2.- When I run the VB program does not recognize a device attached can you give me a clue how to troubleshoot the problem, I will appreciate your help, thank you very much

18.05.2010 - 09:44
Name: Moty
Comment: Hi Eduardo, This firmware does not have a bootloader, the program itself starts at address 0x0000. If you write to the pic18f2550 the hex file the same way you write the bootloader then the program of the counter will start immediately. If you want to add bootloader then you have to change the startup address in the asm file to address where you want to put the program in the ROM. If you use Microchip bootloader then the address is 0x1000.

17.05.2010 - 19:45
Name: Eduardo Ramos
Comment: Hello from Mexico, the hexadecimal file "V-Fmk2.hex" has the bootloader already for the pic18F2550?

16.05.2010 - 15:02
Name: Moty
Comment: Hi Jesus, Please add email address to send the software to. If you don't want your email displayed don't tick the box for displaying the comment.

16.05.2010 - 04:45
Name: Jesus
Comment: Hello friend, could you send me the C code for this project. Thanks.

Name: J K BARIK
Comment: THANKS


13.04.2010 - 01:41
Name: Mother Fucker von der Spree im Schwarzwald
Comment: Vielen Dank! Schickes kleines Projekt.