|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Project Questions about Programming and Electrical
First off, a description of my project:
I started building a contraption that I call the "Weather Alert." It basically houses a 12V battery, microcontroller, switches, LEDs, Power Inverter, 12V outlet, 120V outlet, and integrated flood lights. My last version of this thing used a BS2 controller, but that proved to be very flaky and didn't have enough ports for me to use. Now this one is controlled by using the 2005 robot controller. I have the controller to run continuously in autonomous mode without the Operator Interface so all programming will be done int he autonomous code. Here are my questions: Since I know nothing of programming, what variable is used to show the battery voltage, and if there is an equation to detect the exact voltage, can you please supply it? Is there a way to output a frequency to a speaker to use for an alarm? This will have to be capable of producing many different types of sounds. How would you charge the battery for this? I was thinking of just using a regular 20AMP Headlight relay to connect and disconnect the charger, but if I do this and run the battery completely down and it cannot connect the charger, how would I charge the battery? I can't have it setup on a normally closed circuit either because when I turn the Weather Alert system off, the charger would remain on, killing my battery(ies). Some additional information: My power switch is a DPDT Momentary switch. Both poles are used: one gives the system a "jumpstart" so it can come on (Switch gives power to the power relay, which provides power to the whole system), the other pole is used to send the kill signal to the robot controller. I think I have a way to connect the charger by using some diodes and letting the RC only charge the battery for like 30 seconds if the battery if full or continue to charge it if it is dead. If this all seems very confusing, it probably is... Just ask me a particular question and I'll answer it to the best of my knowledge. |
|
#2
|
|||||
|
|||||
|
Re: Project Questions about Programming and Electrical
What source of power is available to charge the battery? If you have 120 AC, then a small charger like the ones used for FIRST would be perfect - leave them on and connected forever and no overcharging.
If it's some other power source, then provide more details please. Don |
|
#3
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Quote:
|
|
#4
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Look in ifi_aliases.h, You will find the variables for the battery.
I hope this helps. /* *----------------------------------------------------------------------------------------------------- *---------- Aliases for Battery Voltage bytes -------------------------------------------------------- *----------------------------------------------------------------------------------------------------- * Formula to calculate voltage in volts: * current_voltage = battery_voltage * 0.038 + 0.05; */ #define battery_voltage rxdata.rc_main_batt*15.64/256 #define backup_voltage rxdata.rc_backup_batt*15.64/256 |
|
#5
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Quote:
Also, I'm going to add something. I think for the charger, I might have a manual override so I can force it to charge while off (like just a small switch in the back) |
|
#6
|
|||||
|
|||||
|
Re: Project Questions about Programming and Electrical
You could pretty easily use the CCP ports represented by PWMs 13-16 to output single frequency tones. You'd set it up to output a square wave at the particular frequency you want. You'd have to filter it fairly heavily if you wanted a pure tone, of course. Square waves have harmonics at odd multiples of the fundamental frequency, so if it were me, I'd pick what your high frequency is, make yourself something like a 4th or 6th order low pass filter with a corner frequency at that highest frequency. Then you can put out frequencies down to about 1/2 that highest frequency and still have a pretty pure tone. You'd need to make up a separate amp to drive your speaker, and you'd want it to filter out the DC offset inherent in that initial PWM-style square wave and you'd probably need to create a virtual ground split between your 0V and 12V and various other things as well, of course.
|
|
#7
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Quote:
|
|
#8
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Quote:
User_routines_fast.c Code:
/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/
int powerrelay;
int tempb;
int tempc;
int tempd;
int pwrofftmout;
int powerout;
int poweroutb;
int volts;
(Skip a lot of the stuff that doesn't matter in this post)
printf("volts %d\n","battery_voltage %d\n");
volts = battery_voltage*0.038+0.05; /*Should give the correct voltage*/
Also, the value 15865 does not change at all. It is constant when I disconnect the charger or when I put a load on the battery, which indicates something else is not working properly. Last edited by RyanN : 12-10-2007 at 22:23. |
|
#9
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Quote:
Code:
printf("volts %d\n","battery_voltage %d\n",volts_variable, battery_voltage_variable);
|
|
#10
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Quote:
Code:
printf("volts %d\n","battery_voltage %d\n",volts_variable,battery_voltage_variable);
Code:
C:\FrcCode2005v2.2\user_routines_fast.c:168:Error [1105] symbol 'volts_variable' has not been defined C:\FrcCode2005v2.2\user_routines_fast.c:168:Error [1105] symbol 'battery_voltage_variable' has not been defined C:\FrcCode2005v2.2\user_routines_fast.c:168:Warning [2058] call of function without prototype Halting build on first failure as requested. Code:
printf("volts %d\n","battery_voltage %d\n",(int)volts,(int)battery_voltage);
|
|
#11
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Are you doing the volts equation before printf?
|
|
#12
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Code:
printf("volts %d\n","battery_voltage %d\n",(int)volts,(int)battery_voltage);
Code:
printf("volts %d\n battery_voltage %d\n",(int)volts,(int)battery_voltage);
|
|
#13
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Well, I tried your code and same thing... I then defined battery_voltage in user_routines_fast and it's now updating, but the values are still in the 15 and 16000 range. I totally took out all the multiplication and stuff to get the normal volts and just created values using that equation so now I'm doing stuff like:
Code:
if (battery_voltage < 361)
{
relay02_fwd = 1 (<- this may be wrong, I'm writing this from memory)
}
Edit: Just thought of another problem. My charger should stop charging when the value is greater than like 370 or something, but even though it's 16000, the charger remains on. I can connect the charger to a switch with the software and it works, so I'm probably screwing something up with the programming. |
|
#14
|
||||
|
||||
|
Re: Project Questions about Programming and Electrical
Well, no one has replied in over a week, so I'm going to ask again...
Okay... I've tried to program the controller to read the battery voltage, but it's giving me raw values of over 16,000 (if you go to this post, they're experiencing the same problem). No body answered their question, and I posted there yesterday and also got no answer. Please please, any ideas are greatly appreciated, otherwise this thing will overcharge as it did last time. |
|
#15
|
|||||
|
|||||
|
Re: Project Questions about Programming and Electrical
Ryan,
PWM outputs 13-16 are directly connected to the user processor's CCP modules, so you can use them to generate timed pulses. The default code has a section briefly covering this: Code:
/* FIFTH: Set your PWM output types for PWM OUTPUTS 13-16.
/* Choose from these parameters for PWM 13-16 respectively: */
/* IFI_PWM - Standard IFI PWM output generated with Generate_Pwms(...) */
/* USER_CCP - User can use PWM pin as digital I/O or CCP pin. */
Setup_PWM_Output_Type(IFI_PWM,IFI_PWM,IFI_PWM,IFI_PWM);
/*
Example: The following would generate a 40KHz PWM with a 50% duty cycle on the CCP2 pin:
CCP2CON = 0x3C;
PR2 = 0xF9;
CCPR2L = 0x7F;
T2CON = 0;
T2CONbits.TMR2ON = 1;
Setup_PWM_Output_Type(USER_CCP,IFI_PWM,IFI_PWM,IFI_PWM);
*/
So, using the CCP, you can get a square wave signal at (mostly) whatever frequency you want, but two problems remain. First, the signal will oscillate between 0(ish)V and 5(ish)V. Sending something like this through a speaker isn't particularly nice. Especially if the 0V side isn't 0V, as then you'd be constantly sending a current through the speaker. So you'd need an op-amp circuit to shift the square wave so it oscillates around 0V. You could, in fact, send this through the speaker, but it'd sound a bit odd as it's not a nice sine wave like a pure audio tone is. It's possible to get a nice pure tone out of a square wave, however. The sharp edges (more or less) represent higher frequency components of the signal. So if you create a filtering circuit to filter out high frequencies, you'll get a much purer, cleaner tone. That bit isn't as necessary to making a sound come out of the speaker, though. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| two electrical questions | mechanicalbrain | Electrical | 9 | 11-07-2005 09:41 |
| Problems and questions about programming | hedgehogger | Programming | 4 | 15-01-2005 18:18 |
| Questions about DNS, URL Forwarding, and Cloaking | sanddrag | Website Design/Showcase | 7 | 22-10-2004 21:32 |
| Questions about Textures and Models | thoughtful | 3D Animation and Competition | 28 | 11-02-2004 22:13 |
| Pneumatics electrical wiring and programming | archiver | 2001 | 1 | 23-06-2002 23:10 |