Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > General Electronics Chat


General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion?

Reply
 
LinkBack Thread Tools Display Modes
Old 8th March 2008, 03:26 PM   (permalink)
Default

Quote:
Originally Posted by JimB
OK then, "Red Van Man"

JimB
PMSL... yeah ok then I'm a red van man lol. but it's got loads of little black, grey & yellow bits stuck all over it so it's not all red!
__________________
When God was handing out the brains, I thought he said trains, so I asked for a small, slow one!
hackableFM is offline  
Old 16th March 2008, 04:39 AM   (permalink)
Default

OK, now I have been away and read up on some stuff, I have bought a few bit's and I'm almost ready for a hardware 'Play'.

This is my attempt at rebuilding this split charger using a PIC.

Can anyone advise me on my program please, It's written in 'Basic' as far as I believe, I've copied examples of other peoples snippets of code and added some other stuff which I have made educated guesses at. My description of it is as follows..

A split charger, It monitors two batteries which are seperately fused at around 100A (12V Lead Acid) and the output of an alternator on a vehicle, then it should display the results on the LCD. When the alternator is sensed as running it checks wether the fuses are blown by sensing if there is any voltage at each terminal of the solenoid which is eventually going to connect the batteries together in order to charge them, providing the fuse checks are passed.

If the fuse check fails then the proggy should go into a warning 'Alarm' condition whereby it should pulse a piezo sounder, and display on the LCD which battery has a blown fuse, At this point the proggy should NOT allow the solenoid to be energised.

I understand the "< 1" in the 'Fusecheck' sub routine may be completely wrong and this might not actually be the correct way to sense the state of the batteries connected to the analogue inputs so if I have this wrong please say so and possibly offer an alternative solution.

The main reason I am posting this here is for information which I cant find anywhere, If you look at this snippet of code.....

Result1 = Result1 * 5 / 1023 ' Scale it to volts
Result2 = Result2 *
5 / 1023 '

I know & understand the hardware side of feeding a voltage of 12 - 15 volts into the PIC through a resistor network which allows a max of 5volts to enter the pic. But, what do I put into this piece of code in order to 'scale' the pic's interpretation of the input voltage of 5 volts and display it as up to 15volts. I just can't get my head around the maths involved, Basically because I don't understand the program I have just written lol.

Here's what I have come up with so far.


Quote:
Originally Posted by My first proggy
Device 16F877
Declare XTAL4

Declare
ADIN_RES10 ' 10-bit result required
Declare
ADIN_TADFRC ' RC OSC chosen
Declare
ADIN_STIME50 ' Allow 50us sample time

Declare
LCD_TYPE0 ' Type of LCD Used is Alpha
Declare
LCD_DTPINPORTB.4 ' The control bits B4,B5,B6,B7
Declare
LCD_RSPINPORTB.2 ' RS pin on B2
Declare
LCD_ENPINPORTB.3 ' E pin on B3
Declare
LCD_INTERFACE4 ' Interface method is 4 bit

PORTB_PULLUPSTrue

Dim Result1 As Float '
Dim Result2 As Float '

Dim Last_Result1 As Float '
Dim Last_Result2 As Float '

Symbol Input1 =
PORTA.0
Symbol Input2 =
PORTA.1
Symbol Solenoid =
PORTC.0
Symbol Alternator =
PORTC.1
Symbol Sounder =
PORTC.2
Symbol AlmRst =
PORTC.3

TRISA = %00000011 ' Configure AN0 (PORTA.0+1) as an input
ADCON1 = %10000000 ' Set analogue input, Vref is Vdd
TRISC.0 = 0 ' Set PortC 0 as Output
TRISC.1 = 1 ' Set PortC 1 as Input
TRISC.2 = 0 ' Set PortC 2 as Output
TRISC.3 = 1 ' Set PortC 3 as Input

main:

DelayUS
100 ' Allow internal capacitors To charge
Result1 = ADIn
0 ' Grab A0's digital value
DelayUS
100 ' Allow internal capacitors to charge
Result2 = ADIn
1 ' Grab A1's digital value


Result1 = Result1 *
5 / 1023 ' Scale it to volts
Result2 = Result2 *
5 / 1023 '

If Last_Result1 <> Result1 Then ' Check if value has changed
Print At
1, 1, DEC2 Result1, "V " ' If it has, display new data
Last_Result1 = Result1 ' and update last value
EndIf

If Last_Result2 <> Result2 Then ' Check if value has changed
Print At
2, 1, DEC2 Result2, "V " ' If it has, display new data
Last_Result2 = Result2 ' and update last value
EndIf

If Alternator =
1 Then ' If alternator is running then
GoSub Fusecheck
Print At
2, 8, "Y " ' If it is, Display "Y" on LCD line 2 position 7
Solenoid =
1 ' Switch sharge solenoid on
EndIf

If Alternator =
0 Then ' If alternator is NOT running Then
Print At
2, 8, "N " ' Display "N" On LCD Line 2 position 7
Solenoid =
0 ' Switch off charge solenoid
EndIf

DelayUS
250 ' Delay

GoTo main ' Loop for ever


Fusecheck:
If Last_Result1 <
1 Then GoSub Alarm1 ' If main battery (no voltage on terminal) fuse blown then alarm1
If Last_Result2 <
1 Then GoSub Alarm2 ' If slave battery (no voltage on terminal) fuse blown then alarm2

GoTo main

Alarm1:
Cls ' Clear LCD screen
Print At
1, 1, "M F Dead" ' Print Main Fuse Dead on LCD
DelayUS
500 ' Delay
Sounder =
1 ' Trigger sounder
DelayUS
500 ' Delay
Sounder =
0 ' Turn off sounder

If AlmRst =
1 Then GoTo main ' If alarm reset button pressed the return to main program

GoTo Alarm1 ' Cycle alarm until reset pressed

Alarm2:
Cls ' Clear LCD screen
Print At
1, 1, "S F Dead" ' Print Slave Fuse Dead on LCD
DelayUS
500 ' Delay
Sounder =
1 ' Trigger sounder
DelayUS
500 ' Delay
Sounder =
0 ' Turn off sounder

If AlmRst =
1 Then GoTo main ' If alarm reset button pressed the return to main program

GoTo Alarm1 ' Cycle alarm until reset pressed
I know there are probably much more compact ways of writing this code out but believe me this is my first attempt at writing any PIC program.

Marks out of ten anyone??

hackableFM.
__________________
When God was handing out the brains, I thought he said trains, so I asked for a small, slow one!

Last edited by hackableFM; 16th March 2008 at 04:43 AM.
hackableFM is offline  
Old 17th March 2008, 11:34 PM   (permalink)
Default

Can anyone help on this bit please?
Quote:
Originally Posted by hackableFM
I know & understand the hardware side of feeding a voltage of 12 - 15 volts into the PIC through a resistor network which allows a max of 5volts to enter the pic. But, what do I put into this piece of code in order to 'scale' the pic's interpretation of the input voltage of 5 volts and display it as up to 15volts. I just can't get my head around the maths involved, Basically because I don't understand the program I have just written lol.
__________________
When God was handing out the brains, I thought he said trains, so I asked for a small, slow one!
hackableFM is offline  
Old 18th March 2008, 02:07 AM   (permalink)
Default

Well, the ADC is gonna return a number between 0 and 1023 for an ADC input of 0 - 5V. So think 10.23V and multiply this voltage by 2 to get a range of 0 - 20.46V. Put the decimal point in when you display it but keep the number internally in the PIC as an integer of 0 - 2046. Use a resistive divider that would give you 5V at the PICs ADC input if you put 20.46V into it. Say a 3.9K and 1.2K resistor with a 250R trimmer in the middle added for calibration.
__________________
--- The days of the digital watch are numbered. ---
kchriste is offline  
Old 18th March 2008, 09:29 AM   (permalink)
Default

OK, now I think I understand that lol.

I'll have a further play and see what I come up with.

Many thanks.

hackableFM.
__________________
When God was handing out the brains, I thought he said trains, so I asked for a small, slow one!
hackableFM is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Nokia S60 v1 USB Charger antok.tm Electronic Projects Design/Ideas/Reviews 4 15th November 2007 01:30 AM
Nokia charger bananasiong General Electronics Chat 6 7th August 2007 04:04 PM
Lead Acid Battery Charger Help Request jagzviruz Electronic Projects Design/Ideas/Reviews 17 16th January 2007 11:46 AM
Battery charger for mobile phone Motorola 2PAC Mafia General Electronics Chat 0 4th October 2005 04:20 PM
Split Charger jezzz Electronic Projects Design/Ideas/Reviews 7 12th April 2003 08:13 AM



All times are GMT. The time now is 07:48 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker