Skip to content

Carbot is grounded but unsensored

October 16, 2014

14-10-16 carbot

I gave myself the morning to get this silly thing on the ground.  I haven’t given up on the single source power supply but it’s not looking good and, for expediency I’ve just added an extra battery pack for the motor.  The original carbot used a 9v battery for the logic and a 3 cell pack from a cordless phone to power the motors.  That’s sort of where I am for now with a couple of AAs and a boost regulator for the logic and the cordless phone pack for the motors.  I’m going to retry the single source with 3 decent sized nimh AAs and see if that works.  The car weighs a to now and is *not* sprightly!

The code uses a toggle table for software PWM.  All it does is drive forward a bit then attempt a left turn.


#include <olduino.h>
#include <nstdlib.h> //supports c d s x l cx
#define putc(x) out(7,x)
#include "softpwm.h"
#include "carbot.h"

void main(){
	analogWrite(pwmb,255);//full power right
	analogWrite(pwma,255);//full power left
	digitalWrite(bin1,HIGH); digitalWrite(bin2,LOW);
	digitalWrite(ain1,HIGH); digitalWrite(ain2,LOW);
	asm("	seq\n");
	pwmcycleN(100);//forward a bit
	PIN4=0;out(4,0); //kill it all
	asm("	req\n");
	analogWrite(pwmb,255);//full power right
	analogWrite(pwma,128);//half power left
	digitalWrite(bin1,HIGH); digitalWrite(bin2,LOW);
	digitalWrite(ain1,LOW); digitalWrite(ain2,HIGH); //reverse
	asm("	seq\n");
	pwmcycleN(200);//drive a bit
	PIN4=0;out(4,0); //kill it all
	asm("	req\n");
#include <olduino.c>
#include <nstdlib.c>
#include "softpwm.c"


//softpwm.c routines for olduino software pulse width management.
//Oct 12 - pwmstep included in pwmcycleN
void analogWrite(unsigned int bit, unsigned int val){
	if (bit<2){
		dct[bit]=val>>5; //step down range to 0..7
void pwmcycleN(unsigned int howmany){ //run howmany*8 steps of the software pwm
	unsigned int step; //toggle table index
	unsigned char * togglep=toggle; //maybe togglep will be in a register
		togglep[dct[0]]|=1; //set the end of the duty cycle for bit 0
		togglep[dct[1]]|=2; //set the end of the duty cycle for bit 1
		togglep[0]^=~PIN4; //set up with current state of port4 low bits
		togglep[0]&=0x03; //only the pwm bits are set
			PIN4^=togglep[step];	//toggles the bit off if the duty cycle is over
			//printf("dct[0]=%cx, step %d, toggle[%d]=%cx, PIN4=%cx\n",dct[0],step, step, toggle[step],PIN4);

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: