CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Simple MCP42xx driver

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

Simple MCP42xx driver
PostPosted: Mon Aug 27, 2012 4:09 pm     Reply with quote

For MCP4251 and others in the MCP42x1 family DUAL pots
with 0-257 step control - these are used in an audio appliance
and the SPI Lines are up to 6 feet long - with terminators at the far end.
The delay functions are needed ONLY for use with an 18F46K22 running at Fosc 64 Mhz.

There are other features I neither need nor care about - this merely sets the pots accurately and to any step required.
Code:

// #define PLS  pin_a0
// #define PCK  pin_a1
// #define PDI  pin_a2
// write pot simple - DUAL channel MCP 42xx effective
// work is the value from 0 to 257 to send to the pot
// whichpot=0 is A pot  = 1 is B pot

void setMCP42pot(int1 whichpot, unsigned int16 work){

  unsigned int8 i;
  #bit pob = work.15

  // note: even tho a 10 bit field ,
  // bit 9 is always zero as 257 is max arg for the part

  work &=0b0000000111111111;  // clear any value outside 9  bit range
  if (!whichpot) work |=0b0001000000000000;

  output_high(PCK);
  delay_cycles(4);
  output_low(pls);
  delay_cycles(4);
  output_low(PCK);

  for ( i=0; i<16; i++){
      delay_cycles(2);
      if(pob)  output_high(PDI );
      else     output_low(PDI);
      output_high(PCK);
      work <<=1;
      output_low(PCK);
  }
  delay_cycles(2);
  output_high(pls);
  output_low(PCK);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group