MCP42010 on PIC40x1 SDI interface

Addi123

New Member
Hi guys,

currently I'm trying to connect a MCP42010 digital pot to my 40x1, but I haven't got any idea about the code. I found some examples on the www, but they didn't work. (e.g.: http://little-scale.blogspot.com/2007/07/spi-on-picaxe.html)
The chip has two built-in pots. I have to control them seperately.
Maybe someone can help me. =)
A code (-snippet) with comments would be a awesome gift for the coming x-mas. :p

Greetings

Addi123
 

westaust55

Moderator
Funnily have just ordered a couple of single channel Microchip digital pots to experiment with last night for myself.

Had a look at the code in the link you gave and it seems correct relative to the datashseet. Could be tidied/tightened up but should work.

Can you post what ever code you have tried together with your schematic circuit diagram and if possible a photo of you circuit so we can better check for errors.
 

Addi123

New Member
I have connected the two devices this way:

Picaxe MCP42010

24(SDO)--> 3(SI)
18(SCK)--> 2(SCK)
40(O7)---> 1(CS)

I used this code. I think I defined the pins in the right way.

; Setup

symbol CS = 40 ; set chip select pin
symbol SCK = 18 ; set spi clock pin
symbol MOSI = 24 ; set master out, slave in pin
symbol cmd_byte0 = %00010001 ; write to pot 0
symbol dat_byte0 = b0 ; data output for pot 0
symbol work = b1 ; working byte
symbol counting = b2



; Program

main:

let dat_byte0 = dat_byte0 + 1

low CS
let work = cmd_byte0
let counting = 0
for counting = 0 to 7
if work > 127 then spi_high1
low MOSI
goto spi_out1

spi_high1:

high MOSI

spi_out1:
high SCK
let work = work * 2
low SCK
next

let work = dat_byte0
let counting = 0
for counting = 0 to 7
if work > 127 then spi_high2
low MOSI
goto spi_out2

spi_high2:

high MOSI

spi_out2:
high SCK
let work = work * 2
low SCK
next
high CS
goto main
 

westaust55

Moderator
MCP42010 on 40X1

Can you please chnge the PICAXE pins for two of your wires and try this very slightly modified code:

Code:
Picaxe MCP42010

;[COLOR="Red"]38[/COLOR](SDO)--> 3(SI)
;[COLOR="Red"]39[/COLOR](SCK)--> 2(SCK)
;[COLOR="Red"]40[/COLOR](O7)---> 1(CS)



; Setup

symbol CS = [COLOR="Red"]7[/COLOR] ; set chip select output pin 7 - physical pin 40
symbol SCK = [COLOR="Red"]6[/COLOR] ; set spi clock pin on output pin 6 - physical pin 39
symbol MOSI =[COLOR="Red"] 5[/COLOR] ; set master out, slave in pin on output pin 5 - physical pin 38
symbol cmd_byte0 = %00010001 ; write to pot 0
symbol dat_byte0 = b0 ; data output for pot 0
symbol work = b1 ; working byte
symbol counting = b2



; Program

main:

let dat_byte0 = dat_byte0 + 1

low CS
let work = cmd_byte0
let counting = 0
for counting = 0 to 7
if work > 127 then spi_high1
low MOSI
goto spi_out1

spi_high1:

high MOSI

spi_out1:
high SCK
let work = work * 2
low SCK
next

let work = dat_byte0
let counting = 0
for counting = 0 to 7
if work > 127 then spi_high2
low MOSI
goto spi_out2

spi_high2:

high MOSI

spi_out2:
high SCK
let work = work * 2
low SCK
next
high CS
goto main
at the moment you are trying to use the pins assigned for hspi but the high low commands on the 40X1 only work with port B (physical pins 33 to 40)
 

Addi123

New Member
For testing I have connected an LED to ground and the wiper of pot 0. It seems to work with this code, because the brightness of the LED got a little brighter after ca. 1 sec the circuit was powered.
I haven't found the variable to adjust the pot, yet.
Is it this line: symbol dat_byte0 = b0 ? If that's true, what kind of value du I have to put in there?

Greetz

Addi123
 

Addi123

New Member
Thanks guys... You have solved my problem. It works perfectly. =)

I have a 2x16 lc-display to add to the SPI-line. If I understand the code correctly, I hope it isn't that difficult to implement the display. If I am perplexed again, I'll post again. But if anybody want's to spend time on that, datasheets of the lcd-module and the built-in controller are here:

Display: http://www.lcd-module.com/eng/pdf/doma/dog-me.pdf

Controller: http://www.lcd-module.de/eng/pdf/zubehoer/st7036.pdf

Thank you guys for the quick help! =)

Addi123
 

westaust55

Moderator
Thanks guys... You have solved my problem. It works perfectly. =)

I have a 2x16 lc-display to add to the SPI-line.

Addi123
The DOG-ME type LCD modules have been discussed in a past thread on this forum. You might want to do a search for information.

Before anyone can help you, you have to decide how you are going to conenct it.

You mention SPI line but those LCD's are 4/8 bit parallel interfacing with come control lines.

You need to decide if you will use:
- a serial interface such as PH Andersons - typically minimal program space required
- a shift register approach in 4 or 8 bit (can be slow) needs around ~100 bytes of program space to drive
- a 4 or 8 bit parallel data approach which needs 6 or 10 signals lines respectively but fastest. needs around ~70 bytes of program space to drive
 

Addi123

New Member
if I underdstood the datasheet of the display correctly, those displays have an spi-interface. You can see a picture on the 4th page at the bottom right.
 
Top