New kid trying PSoC3

A catchall for PSoC3 discussions not captured by the other forums.

Moderator: ericb

New kid trying PSoC3

Postby Zafod on Mon Apr 02, 2012 6:20 am

I am very new to PSoC3 and i am just trying to do a simple analog mux. The documentation is good but not specific enough. Can someone give me some help on doing the main.c code for a 4 channel mux. I have the inputs and outputs connected to pins and all I want to do is multiplex a voltage divider across the inputs and monitor it on the output. this will give me an idea of how the components work.

Thank you
Mike
Zafod
Newbie
Newbie
 
Posts: 7
Joined: Mon Apr 02, 2012 4:28 am

Re: New kid trying PSoC3

Postby bobmarlowe on Mon Apr 02, 2012 7:40 am

Welcome in the fascinating world of PSoCs!
Very much help to help you is the look at your project. To upload it do the following:
In PSoC Creator select "Build->Clean Project"
"File->Create Workspace Bundle(minimal)"
and then upload the .ZIP file here, so we all can have a look at and make some nasty comments on it. :wink:

We all here started as a brandnew "Kid with a Kit" (Formerly we had a Kite), so do not be afraid to ask your questions.
May I ask: Which of the kits have you got? And: Is your analog-mux-project just a test or do you want to implement something specific?

Have fun
Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1194
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: New kid trying PSoC3

Postby danadak on Mon Apr 02, 2012 7:40 am

Basically you would do the following -

1) Place a mux, configure it to be 4 inputs. Use mux type Analog mux
or Analog mux sequencer, depends on what you prefer. These are
SW controlled muxes. If you wanted to use a HW controlled mux that
is also offered.

2) Place 4 analog pins and connect them to the mux.

**** You config things by double clicking them and a GUI wizard pops up to assist you ****

3) Place A/D, config it as single ended, its range and sample rate.....
Connect that to mux output. Note mux's can also be configed as differential,
as well as A/D, should you so desire.

PSOC 3 Analog Mux.jpg
PSOC 3 Analog Mux.jpg (12.46 KiB) Viewed 557 times


In SW (Using APIs in datasheet) -

1) Start analog mux.

2) Start A/D.

3) Write loop to select mux channel using API provided, and take an A/D measurement.

For the major components on Creator start page there are example projects you can
open and view code and setup. Mux does not have one per se due to its simplicity.
Link on page is "Find Example Project". Also www.cypress.com has videos on using
Creator to build a project.

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 1837
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: New kid trying PSoC3

Postby Zafod on Mon Apr 02, 2012 9:06 am

Dana, Thanks. The part that i am not getting right now is what commands to put in the main.c file. i think I may be over complicating the commands.

Bob, This is just to get a feel for the PSoC commands. I will be using a mux in my final design.
Zafod
Newbie
Newbie
 
Posts: 7
Joined: Mon Apr 02, 2012 4:28 am

Re: New kid trying PSoC3

Postby bobmarlowe on Mon Apr 02, 2012 9:52 am

Hi Zafod (Beeblebox?) :mrgreen: ,
PSoC comes with a C-compiler (for PSoC3 the Keil). So i hope that you are a bit (or even a byte?) familar with C programming. When you left-click on a module in the schematic you get the option to view at the datasheet. Besides all the other information there is a detailled description of all the APIs (Application Program Interface) the module provides. Study those!!! They give you a feeling how your program MAY interact with the module. For example: You will always have to initialize the module with a "ModuleName_Start()" call. You can switch from one input to the next by applying the right API to the analogMUX. And (depending on your kit) you can drop an character-LCD-module on the schematic (look at your kit's examples for the right pins) Initialize it and display the result(s).
A look at the ADC-datasheet will reveal which conversion mode (continueous or single) will be right and if you have to drop some ADC-readings after switching the mux....
It is getting complicated? No, not yet, when later you are using interrupts and DMA it's getting complicated.

Happy coding
Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1194
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: New kid trying PSoC3

Postby Zafod on Mon Apr 02, 2012 10:07 am

Beeblebrox it is, great books. I am familiar with C haven't used it in quite a few years but it is coming back. I am just making this simple mux to get a handle on the syntax of PSoC.

Thanks for the help
Mike
Zafod
Newbie
Newbie
 
Posts: 7
Joined: Mon Apr 02, 2012 4:28 am

Re: New kid trying PSoC3

Postby danadak on Mon Apr 02, 2012 11:18 am

Here are the key commands you would use -

Code: Select all
AMux_1_Start(void);
ADC_DelSig_1_Start(void);
....
....
....
// in loop to select mux chan and get a/d result

AMux_1_Select(uint8 chan);          // Chan # is 0 - 3 in your case
ADC_GetResult16(void);               // This is for continuous conversion mode ADC. You might want a little
                                       // delay after mux change to allow for settling. Or set ADC to one shot mode,
                                       // and issue start command in loop, then test for finished.

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 1837
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: New kid trying PSoC3

Postby Zafod on Tue Apr 03, 2012 6:26 am

Dana, Bob;

Here is what I have done but it is not working. the code looks correct and it does compile but when I load it in nothing happens.

#include <device.h>
#include <AMux.h>

void main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
void AMux_Init(void);
void AMux_Start(void);
uint8 channel = 0;


/* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
for(;;)
{
channel = 0;
/* Place your application code here. */
while(channel <= 3)
{


AMux_Select(uint8 channel);
channel = channel++;

}

}
}


All I have is a 4 bit mux with the inputs tied to a voltage divider so that each mux input sees a lower voltage and the output of the mux is floating and hooked up to a 'scope. What is wrong with the code? Thanks in advance.
Zafod
Newbie
Newbie
 
Posts: 7
Joined: Mon Apr 02, 2012 4:28 am

Re: New kid trying PSoC3

Postby bobmarlowe on Tue Apr 03, 2012 6:48 am

Again, Zafod, will you please upload the completer project so that we can have a look at everything?
There are a couple of lines that should cast a compile error or at least a warning, We cannot see that without the whole project.

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1194
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: New kid trying PSoC3

Postby Zafod on Tue Apr 03, 2012 7:09 am

Bob,
Here it is. thanks.
Attachments
mux.Bundle01.zip
(972.05 KiB) Downloaded 28 times
Zafod
Newbie
Newbie
 
Posts: 7
Joined: Mon Apr 02, 2012 4:28 am

Re: New kid trying PSoC3

Postby danadak on Tue Apr 03, 2012 7:39 am

Try this -

Code: Select all
     channel = 0;

     for(;;) {
         
       AMux_Select(channel);
       channel = ( channel < 3 ) ? channel + 1 : 0;
      
    }


Before you fell out of loop with channel set to 4 and never executed again.

Also note there is no delay for settling between channel changes, that will
affect what output looks like. The code is a very tight loop, so runs very
fast, mux switch may not have a chance to fully turn on. Delay could be as
simple as a variable counting down from a "big" number, then reseting it to
a big number when it gets to 0 so loop keeps executing. More efficient way
would be to use a timer/isr combination, sleep timer, whatever...... Note
you did not state values used for V divider, if they are really high then
settling time is aggravated due to low charge current for scope probe and
stray capacitance. Use low K's for divider.

You can add a digital output pin, toggle it in loop, to see roughly how fast
loop is running, and as a scope trigger. More sophisticated loop speed de-
termination is look at lst file and count instruction codes and their cycles
inside the loop.
Last edited by danadak on Tue Apr 03, 2012 7:58 am, edited 1 time in total.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 1837
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: New kid trying PSoC3

Postby bobmarlowe on Tue Apr 03, 2012 7:56 am

Back again.
Commented, but untested version yet. Should run.

Bob
Attachments
Mux.zip
(216.69 KiB) Downloaded 36 times
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1194
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: New kid trying PSoC3

Postby Zafod on Tue Apr 03, 2012 10:31 am

Thanks, I will try it out and let you know. Looking at your program I think I see what I was doing wrong.
Zafod
Newbie
Newbie
 
Posts: 7
Joined: Mon Apr 02, 2012 4:28 am

Re: New kid trying PSoC3

Postby Zafod on Tue Apr 03, 2012 10:48 am

Thanks for the help. I see shat I was doing wrong, yours works.

Mike
Zafod
Newbie
Newbie
 
Posts: 7
Joined: Mon Apr 02, 2012 4:28 am

Re: New kid trying PSoC3

Postby bobmarlowe on Tue Apr 03, 2012 12:13 pm

Fine, Now remove ALL commented-out lines and check every line if the comment is really needed.

Happy Cleanup :mrgreen:
Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1194
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany


Return to PSoC3 General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest