Search This Blog

Tuesday, May 28, 2013

HC-SR04 ultrasonic range finder (max 4000mm)

I built some time ago a "range finder" based on the cheap ultrasonic module HC-SR04 (max 4000mm). I wrote a small program in Mikrobasic and have the result displayed on a 8x2 LCD. All needed is here:
HEX, source, sch, brd (EAGLE), datasheet, pictures

A video to show how it works:
Youtube video

Note theconnections to 16F630 PIC:
LCD_RS as sbit at RC5_bit
LCD_EN as sbit at RC4_bit
LCD_D4 as sbit at RC3_bit
LCD_D5 as sbit at RC2_bit
LCD_D6 as sbit at RC1_bit
LCD_D7 as sbit at RC0_bit
RA.5 is output for trigger input of the HC-SR04, RA.4 is input from the echo output of the HC-SR04. The LED on RA.0 is for testing only.

The push-button triggers (by powering the assembly), so the distance is displayed. No consumption unless push-button is pressed.

More explanations, see these links:
http://www.mikroe.com/forum/viewtopic.php?f=97&t=53891
http://www.mikroe.com/forum/viewtopic.php?f=97&t=54466

Some pictures
Overview:
 LCD display:
Inside the box (note the 12V battery wrapped in 3M band - I could not fit a 9V battery, and a 6V would not work as I have a regular 78L05):

UPDATE 2013/11/16: cod for 16F877a also available Source+HEX .
Connections:
    LCD_RS as sbit at RB7_bit
    LCD_EN as sbit at RB6_bit
    LCD_D4 as sbit at RB5_bit
    LCD_D5 as sbit at RB4_bit
    LCD_D6 as sbit at RB3_bit
    LCD_D7 as sbit at RB2_bit
    RB1=trigge
    RB0=echo received
    RC7 is output (LED) continuously ON.

Saturday, February 16, 2013

4CH R/C system (encoder - decoder) - Home made style



Finally, I got to get all together and test my system. It works, as expected!

DIY 4ch PPM encoder-decoder system. Encoder system displays on LCD the position (in percentage) of the lever and change symbol based on position (1ms to 1.4ms - DOWNWARDS or LEFT ARROW, 1.4ms to 1.6ms - "-", 1.6ms to 2ms - UPWARDS or RIGHT ARROW - for channels 1 to 3), shows position ("L", "C" or "H") for a 3 position switch (type (ON)-OFF-(ON)), and monitored value of the Tx battery (displays "!" under the battery recharge level).

I used a 16F677 (690) to create the PPM sequence based on the 4 measured voltages. The PPM signal is to be Tx via radio link to the decoder (12F635). The Red LED on the decoder is flashing when correct signal is decoded. It is mainly useless for the Rx system, but it is a visual indication for correct communication.

I intend to use it for a R/C boat for pleasure, and yes it cost more than a ready-to-buy system.

NB: I agree the PICs are highly underused, but I had them getting dusty for about 3 years and had to give them a life too :).

PS: for curious guys, the noisy background is Helloween's "Straight Out Of Hell", a simple coincidence, no setup.

Sunday, October 28, 2012

16F88 Volt-ampermeter - LCD 2x8

Intro
As I experiment a lot in RC electronics, I really needed a way to easily monitor the voltage and the current drawn by motors while testing the power circuits.

I wanted to make my own volt-ampermeter to have it handy. The Internet is full of them, so there is really nothing new or innovative in my instrument, but here is my version.

It displays the voltage and the amps in the below format:

1st line:  U = 12.34V 
2nd line: I  = 1.234A 


Comps
I chose to use a 16F88 I had, a small 8x2 LCD (unfortunatelly no backlit, a cheap $3-4) and a small 2.5" by 3.5" by 1" ABS box (the type with a 9V battery compartment). The box height does not allowed the LCD to be installed inside, so I still have to figure out some screen protection shield. See figure 1 below:
Figure 1 - Click to zoom in

I chose a rail-to-rail opamp as a buffer and signal amplifier. You can see the schematic below. No explanations needed. It is really minimalistic version, while all calibration is software (by means of calculate, implement and test - wasn't easy, but I tried to minimize the component count); I wish I would have put there 2 pots for the ease of calibration - I'd suggest you do it if you have a bigger box in your plan to build this instrument. See figure 2 below.

Figure 2 - Click to zoom in


Note that the PCB I made allows for the PIC PCB (right side of the schematic) to be stacked on the V-A interface (left side of the schematics). The pot for the LCD contrast is soldered directly on the LCD so it is not shown in the schematic, while R/W, D0 to D3 are all grounded directly on the LCD.


Firmware

The Mikrobasic PRO source and HEX are here!

Notes:

Remember that 1A leads to 0.1V voltage drop only in the 0R1 shunt; 5A lead to 0.5V drop. I have not considered the drop on the power wires (and the drop is maybe more than in the shunt itself). Use short wires and make sure they're properly sized (AWG10 or 4sqmm I would recommend).



Monday, December 26, 2011

16F690 R/C ESC (speed controller) - full-bridge mode over the range of 1 to 2ms PPM signal

Everything started when I saw this version of uni-directional ESC (Libstock projects - rc-motor-control-cmos-output-version). Deserved credits to the original poster!

I used the same method to measure the pulse width as the original poster. The difference is that my design is a full-bridge mode.

The PIC is a 16F690, with a P-N H-bridge attached to it. Probably will drive 10-15A continuously. The Mosfet driver can drive much bigger Mosfets. See the datasheet linked below.

It drives the motor from 0 to 100% in forward direction for PPM signal between 1.6 to 2ms, it stops the motor (free coast) between 1.4 and 1.6ms, and it drives the motor from 0 to 100% in reverse direction from 1.4 to 1ms.

Mainly, I use the linear interpolation to calculate the Duty Cycle the PWM will be driven. For details see the comments in the code and this Wiki link (Linear interpolation). I made all needed  calculations so the PIC will have to do the minimum of calculations (i.e. I considered 0-100 as being -100, and arranged the formula I put in the code), for a quicker execution of the code in the PIC.

As the  mikroBasic PRO does not have a library for the full-bridge I had to add some additional code (the present PWM library "knows" to output the PWM signal on the designated pin of the PIC in single-mode PWM - which is good enough for many applications!).


Here is how I did it (if you read the datasheet, you'll see why):

PWM initialisation:
'Init PWM
    CCP1CON  =   0X4E                ' CCP ON mode, FWD (default)
                                                       ' P1A/C active "L"
                                                       ' modulated P1B/D active "H"
    CCPR1L     =   0x00
    T2CON      =   0x05                  ' TMR2 ON, 1:4 prescaler
    PR2            =   0xFA                 ' f=498Hz
    TMR2        =   0
'End init PWM

Direction change:
SetBit(CCP1CON,7) for Reverse or ClearBit(CCP1CON,7) for Forward.

At "zero position" I simply put the Duty Cycle at 0, regardless the direction bit.

Duty Cycle set-up:
CCPR1L = something (where "something" is calculated based on the PPM pulse width).

The schematic is the following:
CLICK TO ZOOM!
The schematic is self-explanatory, but I will add some wording:
- It is based on the 16F690 PIC (I used the SOIC package this time).
- The PIC supply is by a 7805 regulator (as the circuit power supply is 12Vdc). I put a diode as a "fool-proof" protection.
- The Mosfet driver is a TC446x (where x is 8 or 9 and you set-up the jumper JMP1 accordingly: "1" for 4468, "0" for 4469). It is shown a 4468 but the 4469 has the same pin #s, except one input is negated (see datasheet TC446x). The mosfets are STD30PF03 (P-ch 0.025ohm, 24A) and STD35NF3LL (N-ch 0.014ohm 35A) in DPAK packages (ideal RDSon indicated ;)).

On the PPM input put a 10k resistor to ground, it will help by preventing input floating (this is helping the Loss Of Signal fix).

The PCB (not the perfect one, as it is a single layer and needs wire jumpers...). I suggest you do your own for a better layout, you can add the ICSP (I temporarily solder some wires for software update). But, as a sample here you have it. You can use the free version of Eagle, but you may need to create yourself some components.
PCB
 Note that the code contains also the LCD connections. The version on breadboard (using a DIP package PIC) had a LCD connected to continuously show the pulse width and the Duty Cycle (needed for small adjustments). You do not need that, and you can remove that part from the code. It will not interfere with the full-bridge functionality.

For the future I will use 16F1823 PIC that can do the same as the 16F690 but is better used (characteristics, memory, etc). The 16F690 is under-used in this application. Wrong, 16F1823 knows a lot of new stuff compared to 16F690!

Source, HEX and schematics are here! And on LIBSTOCK (mikroElektronika community sharing website) here!

Enjoy and comment, you can help to improve this design!
Mircea