![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
FunkyLabRat
Joined: 13 Feb 2012 Posts: 10
|
16F628A with MCP41010 problem |
Posted: Thu Apr 12, 2012 2:33 pm |
|
|
Hi again everybody,
I'm trying to replace a foot switch (working with force-sensing resistors) with a MCP41010 digital potentiometer connected to a PIC 16F628A to control a device. It's connected with a TRS jack to the device.
I know this is not a hardware forum, but maybe I'm doing something wrong or missing a connection, so please check my schematics.
I'm not sure if I can hook up the Jack TRS connector straight to the PW0, PA0 and PB0 pins on the MCP41010? (see the question marks in the picture).
But either way, I've tried a lot of combinations but it won't work and I'm not measuring anything on the MCP pins.
And of course, here's the test program I'm using:
Code: | #include <16F628A.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOMCLR, NOLVP, NOCPD
#use delay(clock=4M)
#use rs232(stream=MIDI,baud=31250,parity=N,xmit=PIN_B2,rcv=PIN_B1,stop=1,bits=8,BRGH1OK,ERRORS)
#define CS PIN_B3
#define SCLK PIN_A5
#define SI PIN_B0
void set_pot (int data) {
BYTE i;
BYTE cmd[2];
cmd[0] = data;
cmd[1] = 0x11;
output_low(SCLK);
output_low(CS);
for(i=1;i<=16;++i) {
output_bit(SI, shift_left(cmd,2,0));
output_high(SCLK);
output_low(SCLK);
}
output_high(CS);
}
void shutdown_pot () {
BYTE i;
BYTE cmd[2];
cmd[0] = 0;
cmd[1] = 0x21;
output_low(SCLK);
output_low(CS);
for(i=1;i<=16;++i) {
output_bit(SI, shift_left(cmd,2,0));
output_high(SCLK);
output_low(SCLK);
}
output_high(CS);
}
void FlashLED() {
output_high(PIN_A1);
delay_ms (100);
output_low(PIN_A1);
}
void main() {
enable_interrupts(GLOBAL);
while(1) {
shutdown_pot();
delay_ms(10);
set_pot(50);
delay_ms(1000);
FlashLED();
shutdown_pot ();
delay_ms(10);
set_pot(100);
delay_ms(1000);
FlashLED();
shutdown_pot ();
delay_ms(10);
set_pot(150);
delay_ms(1000);
FlashLED();
shutdown_pot ();
delay_ms(10);
set_pot(200);
delay_ms(1000);
FlashLED();
}
}
|
I hope someone can push me in the right direction.
Thanks in advance! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 12, 2012 3:32 pm |
|
|
Quote: |
#define CS PIN_B3
#define SCLK PIN_A5
#define SI PIN_B0
|
Download the 16F628A data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/40044G.pdf
Look at the pin descriptions in this section:
Quote: |
TABLE 3-2: PIC16F627A/628A/648A PINOUT DESCRIPTION
|
Look closely at the capabilities of the PIC pin that you have chosen for
SCLK signal.
Quote: | void main() {
enable_interrupts(GLOBAL);
|
Also, why are you enabling interrupts when you have no interrupt
service routine ? What do you expect that line to do ? |
|
![](templates/subSilver/images/spacer.gif) |
FunkyLabRat
Joined: 13 Feb 2012 Posts: 10
|
|
Posted: Thu Apr 12, 2012 7:53 pm |
|
|
Thanks for your reply PCM Programmer.
I've checked the datasheet and pins before posting, but I couldn't find anything wrong with the RA5 pin. I totally overlooked that it can only be used as a input pin. Thank you.
And the ''enable_interrupts(GLOBAL);'' line is a mistake. I'm sorry about that. I forgot to delete this line before pasting the code here. These interrupts ARE used in the ''full'' code. |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Take a step or two backwards |
Posted: Fri Apr 13, 2012 2:04 am |
|
|
Do you fully understand what the force sensing device is actually doing?
You're presenting two different sets of data when you compare the force sensor with the 25k potentiometer.
Then try replacing the force sensors with hardware potentiometer(s).
When you've got that working correctly, move on to MCP41010. It should, by then, be obvious how to connect.
Programming is a separate issue.
That's my two pennies worth.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9172 Location: Greensville,Ontario
|
|
Posted: Fri Apr 13, 2012 5:11 am |
|
|
Also a 'B' style pot is a logarithmic type, while the digipot is linear so you'll have to create a table to get the response you need to mimic the force resistor.
Simple enough to do, just another 'detail' to work out. |
|
![](templates/subSilver/images/spacer.gif) |
FunkyLabRat
Joined: 13 Feb 2012 Posts: 10
|
|
Posted: Sun Apr 15, 2012 8:09 pm |
|
|
The force sensing foot switch is just a fancy 20K linear potentiometer. The B25K pot was just to show how the connections work fine.
The digipot now works, but I can't change it's step value. It seems to be always in the middle (which seems to be the default state). I've tried some test programs with no success.
Here's my latest test program where there are two buttons added on pins B5 and A0 to change the step value of the MCP digipot which works in 256 steps. Every press should add or subtract 10 steps on the digipot.
I assume that set_pot() has to be used with values 0 to 255, but since I've had no success in changing the value, the ''pot_data'' value can go higher for testing purposes.
Code: |
#include <16F628A.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOMCLR, NOLVP, NOCPD
#use delay(clock=4M)
#use rs232(stream=MIDI,baud=31250,parity=N,xmit=PIN_B2,rcv=PIN_B1,stop=1,bits=8,BRGH1OK,ERRORS)
#define CS PIN_A3
#define SCLK PIN_A4
#define SI PIN_B0
int pot_data;
void set_pot (int data) {
BYTE i;
BYTE cmd[2];
cmd[0] = data;
cmd[1] = 0x11;
output_low(SCLK);
output_low(CS);
for(i=1;i<=16;++i) {
output_bit(SI, shift_left(cmd,2,0));
output_high(SCLK);
output_low(SCLK);
}
output_high(CS);
}
void shutdown_pot () {
BYTE i;
BYTE cmd[2];
cmd[0] = 0;
cmd[1] = 0x21;
output_low(SCLK);
output_low(CS);
for(i=1;i<=16;++i) {
output_bit(SI, shift_left(cmd,2,0));
output_high(SCLK);
output_low(SCLK);
}
output_high(CS);
}
void main() {
pot_data = 128;
while(1) {
if (input(PIN_B5) == 0) {
output_high(PIN_A1);
pot_data = pot_data - 10;
shutdown_pot();
delay_ms(10);
set_pot(pot_data);
delay_ms(500);
output_low(PIN_A1);
}
if (input(PIN_A0) == 0) {
output_high(PIN_A1);
pot_data = pot_data + 10;
shutdown_pot();
delay_ms(10);
set_pot(pot_data);
delay_ms(500);
output_low(PIN_A1);
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
FunkyLabRat
Joined: 13 Feb 2012 Posts: 10
|
|
Posted: Thu Apr 19, 2012 1:02 pm |
|
|
To answer my own question: PIN_A4 is a open-drain pin and also can't be used for the Digipot.
I used pin A2 instead of A4:
Code: |
#define CS PIN_A3
#define SCLK PIN_A2
#define SI PIN_B0
|
And now it works! |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|