Re: Firmware v5.5

Bus Pirate firmware and hardware development.

Firmware v5.5

Postby ian » Fri Jul 30, 2010 4:00 am

Firmware v5.5 will probably support the first major release of piratePICprog, with support for 4/16 and 4/24 protocol PICs.

I'd also like to add a new bulk transfer mode for the flashrom project, if I can get a hold of any active developers.

Then there are the few features that get neglected in every release:
*I2C clock stretching?
(I guess that's it)...
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: Firmware v5.5

Postby Randy » Fri Jul 30, 2010 11:36 pm

Ian,

I'm not sure I2C clock stretching is a big deal.  You can always slow down the clock rate if you need to talk to slower devices.

I have heard mention of a servo mode.  Have you given any thought to that?  I've been playing with the PWM settings in AUXpin.c and it's pretty easy to hit the frequency and duty cycles needed to run a servo.  Just need to work out the scaling factors.  It could even be scaled just like the PWM mode is now with 0 to 99.  Or if higher resolution is desired you could use 0 to 255.  I'm willing to help if you need it.

Randy
Randy
Newbie
Newbie
 
Posts: 33
Joined: Mon Jun 21, 2010 7:30 pm

Re: Firmware v5.5

Postby ian » Sat Jul 31, 2010 7:33 am

Hey Randy,

That sounds great. Can you give a rough sketch (or code ;) ) of how it would be configured, what signal and timing parameters need to be set, etc. I'm not familiar with servos, and don;t have one to test, so your work so far would be a huge help.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: Firmware v5.5

Postby Randy » Sat Jul 31, 2010 12:58 pm

Sure, I'll put something together.  I thought it would be easy to leverage off of the PWM functions in AUXpin.c but with the global variables and interaction with pic.c and basic.c, it gets kind of messy.  I'll have to rethink how to do it.

Basically, what you need is a PWM with a period of 20 mS, or 50Hz, and a duty cycle that produces a pulse in the range of 1 to 2 mS.  To center the servo, the pulse is 1.5 mS, full CCW is 1 mS and full CW is 2 mS.

I tested this by tweaking the PWM_div and PWM_period values in the function bpPWM() but this messes up the normal use of this function.

Randy
Randy
Newbie
Newbie
 
Posts: 33
Joined: Mon Jun 21, 2010 7:30 pm

Re: Firmware v5.5

Postby Randy » Sat Jul 31, 2010 6:42 pm

OK, I have something working.  I'll just paste the code here.

This function, bpServo is added to AUXpin.c :

Code: Select all
//setup the Servo PWM
void bpServo(void)
{
   unsigned int PWM_period, PWM_dutycycle;
   char done = 0;
   float PWM_pd;

   // Clear timers
   T2CON=0;      // clear settings
   T4CON=0;
   OC5CON =0;
   
   if(AUXmode==AUX_PWM){    //PWM is on, stop it
      AUXPIN_RPOUT = 0;   //remove output from AUX pin
      BPMSG1028;
      AUXmode=AUX_IO;
      if(cmdbuf[((cmdstart + 1)& CMDLENMSK)] == 0x00)
         return; // return if no arguments to function
   }

   cmdstart++;
   cmdstart &= CMDLENMSK;

   //get any compound commandline variables
   consumewhitechars();
   if (181 > (PWM_pd=getint()))
      done++;

   // Setup multiplier for 50 Hz
   T2CONbits.TCKPS1=1;
   T2CONbits.TCKPS0=1;
   PWM_period=1250;;

   if(done!=1)//if no commandline vairable, prompt for position
   {
      BPMSG1033;
      PWM_pd=getnumber(90,0,180,0);
   }

   PWM_pd/=3500;
   PWM_dutycycle=(PWM_period * PWM_pd) + 62;

   //assign pin with PPS
   AUXPIN_RPOUT = OC5_IO;

   OC5R = PWM_dutycycle;
   OC5RS = PWM_dutycycle;
   OC5CON = 0x6;         
   PR2   = PWM_period;   
   T2CONbits.TON = 1;   

   BPMSG1034;
   AUXmode=AUX_PWM;
}


I used capital 'S' to launch it from the user interface and added the function prototype to AUXpin.h

The range of the servo is 0 to 180 where 0 is about 0.990 mS, 90 is 1.5 mS, and 180 is 2.010 mS.

I have not done anything to make the messages work correctly, I'm not up-to-speed on how the message strings work yet :-)

Randy
Randy
Newbie
Newbie
 
Posts: 33
Joined: Mon Jun 21, 2010 7:30 pm

Re: Firmware v5.5

Postby ian » Mon Aug 02, 2010 1:56 am

Thanks Randy,

I added this to the source and committed it to SVN. I did not add it to the menu or compile it yet.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: Firmware v5.5

Postby ian » Mon Aug 02, 2010 11:20 am

Space, space, space. I liked Sjaaks' idea of a stable release, and a cutting edge release with some parts removed. Should be easy enough to do with a few defines.

v5.5 will add a new flashrom extension to SPI, it will looks something like this:
http://dangerousprototypes.com/forum/in ... opic=796.0
command|write H | write L| read H | read L| write data... | read data....

writeH/L is max 4096 bytes, readH/L is max 4096 bytes.
CS is automatically lowered, data is sent, data is read, CS is raised. Bus Pirate will return 0x00 after read L is sent if read or write are > than 4096.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: Firmware v5.5

Postby ian » Fri Aug 06, 2010 3:22 am

I added the servo command under 'S' too. I compiled the latest version and posted it. Unstickied this thread, will start a v5.6 thread now.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: Firmware v5.5

Postby Randy » Fri Aug 06, 2010 8:22 am

Ian,

If you can give me information on the method used to generate the messages I will clean up the servo code this weekend.

Randy
Randy
Newbie
Newbie
 
Posts: 33
Joined: Mon Jun 21, 2010 7:30 pm

Re: Firmware v5.5

Postby ian » Fri Aug 06, 2010 8:38 am

It's one of those things that is so convoluted and difficult to describe, it's probably easier if Sjaak and I do it, then send you the diffs as an example ;) It's something like this:
1. Add a new ID and text to the english translation .txt file
2. Run the text through the .html translator file
3. Paste the .h and .s code into the english .h and .s files
4. Comment out the text and replace it with the message ID

I noticed that is doesn't prompt for user input as expected. I haven't checked why.

If you have pictures and/or terminal output as usage examples, I'll put it on the wiki with the documentation. We should also add it to the help display.
Got a question? Please ask in the forum for the fastest answers.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am

Re: Firmware v5.5

Postby Randy » Fri Aug 06, 2010 1:12 pm

OK, I'll just put together some documentation and demos and let you handle the strings.
When I was testing the code I added the 'S' command to the menu using the same scheme as 'g'.  I put a test for Hi-Z mode like this:
Code: Select all
case 'S': //servo control
    if(bpConfig.busMode==HIZ)
    {   //bpWmessage(MSG_ERROR_MODE);
        BPMSG1088;
    }else{
        bpServo();
}
break;


Randy
Randy
Newbie
Newbie
 
Posts: 33
Joined: Mon Jun 21, 2010 7:30 pm

Re: Firmware v5.5

Postby Randy » Fri Aug 06, 2010 10:53 pm

OK, looks like things are working properly now.  Had to remember to bring a debugger home, makes life much easier.

Here is the latest bpServo code:

Code: Select all
//setup the Servo PWM
void bpServo(void)
{
   unsigned int PWM_period, PWM_dutycycle;
   float PWM_pd;

   // Clear timers
   T2CON = 0;      // clear settings
   T4CON = 0;
   OC5CON = 0;
   
   if(AUXmode == AUX_PWM){    //PWM is on, stop it
      AUXPIN_RPOUT = 0;   //remove output from AUX pin
      BPMSG1028;         // <---- THIS NEEDS TO SAY "Servo disabled"
      AUXmode = AUX_IO;
      if(cmdbuf[((cmdstart + 1)& CMDLENMSK)] == 0x00)
         return; // return if no arguments to function
   }

   cmdstart++;
   cmdstart &= CMDLENMSK;

   // Get servo position from command line or prompt for value
   consumewhitechars();
   PWM_pd = getint();
   if (cmderror || (PWM_pd > 180)) {
      cmderror = 0;
      BPMSG1033;         // <---- THIS NEEDS TO SAY "Position in degrees"
      PWM_pd = getnumber(90, 0, 180, 0);
   }

   // Setup multiplier for 50 Hz
   T2CONbits.TCKPS1 = 1;
   T2CONbits.TCKPS0 = 1;
   PWM_period = 1250;;
   PWM_pd /= 3500;
   PWM_dutycycle = (PWM_period * PWM_pd) + 62;

   //assign pin with PPS
   AUXPIN_RPOUT = OC5_IO;
   OC5R = PWM_dutycycle;
   OC5RS = PWM_dutycycle;
   OC5CON = 0x6;         
   PR2   = PWM_period;   
   T2CONbits.TON = 1;   
   BPMSG1034;         // <---- THIS NEEDS TO SAY "Servo active"
   AUXmode=AUX_PWM;
}


It still needs to have the messages fixed as you can see in the comments.  There also should be an entry in the help screen for the 'S' command.

I have also attached a PDF with some information about usage.

Randy
Attachments
Bus Pirate servo mode.pdf
(174.6 KiB) Downloaded 1361 times
Randy
Newbie
Newbie
 
Posts: 33
Joined: Mon Jun 21, 2010 7:30 pm

Re: Re: Firmware v5.5

Postby ian » Mon Dec 12, 2011 10:50 am

Hi Randy - This is an ancient thread, but wanted to let you know I totally missed this documentation and found it when doign v6 firmware today. I'll add it to the documentation wiki.
User avatar
ian
Crew
Crew
 
Posts: 10803
Joined: Mon Jul 06, 2009 6:14 am


Return to Bus Pirate Development