Sign in

username:

password:



Not a member?

Search rabbit-semi



Search tips

Subscribe to rabbit-semi



Ads

Discussion Groups

Discussion Groups | Rabbit-Semi | using anainvolts and pwm simultaneously

This is a group for folks designing and programming embedded systems using the Rabbit Semiconductor C-programmable microcontroller. Rabbit Semi is a spin-off from Z-World who makes a variety of embedded modules and tools. This group is not affiliated with either Rabbit or Z-World, but is a user forum for sharing ideas, asking questions, flaunting knowledge, and other typical user group stuff. The Rabbit is a powerful uC, supported by a full-featured C-compiler.

using anainvolts and pwm simultaneously - Marinelle - May 24 14:44:24 2008

Hi, I would like to drive my motors using pwm and read voltage input
using anavolts from my IR sensor.

I am using rabbit 4000 and rcm 4100.

My problem is, when pwm is running (i.e. fwd function below),
anainvolts doesnt seem to work. How can I work around this that is be
able to drive the motor and receive voltage reading?

the following is the code:

#class auto
#use RCM41xx.LIB

#ifndef ADC_ONBOARD
#error "This core module does not have ADC support. ADC programs
will not "
#fatal " compile on boards without ADC support. Exiting
compilation."
#endif

void fwd()
{
// pwm_set(1, (int)(0* 1024.0), PWM_USEPORTE); //PE5 hi
// pwm_set(0, (int)(1 * 1024.0), PWM_USEPORTE); //PE4 hi/low
printf("fwd\n");
pwm_set(1, (int)(0* 1024.0), PWM_USEPORTC); //PE5 hi
pwm_set(0, (int)(1 * 1024.0), PWM_USEPORTC); //PE4 hi/low
printf("fwd\n");
}

void stop()
{
pwm_set(1, (int)(0* 1024.0), PWM_USEPORTE); //PE5 hi
pwm_set(0, (int)(0 * 1024.0), PWM_USEPORTE); //PE4 hi/low
printf("stp\n");
pwm_set(1, (int)(0* 1024.0), PWM_USEPORTC); //PE5 hi
pwm_set(0, (int)(0 * 1024.0), PWM_USEPORTC); //PE4 hi/low
printf("stp\n");
}
main ()
{
auto unsigned int gain;
auto float voltRead;
brdInit();
gain = 0;
fwd();

while (1)
{
costate
{
voltRead = anaInVolts(2,gain);
printf("%.3f V\n",voltRead);
waitfor(DelaySec(2));
}
costate
{
if (voltRead <20)
{
printf("obstacle ahead\n");
waitfor(DelaySec(3));
}
}
}
}// end main
------------------------------------



(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )