Home › ELEKTOR FORUMS › DigiButler (April & May 2008) › How to program more digital outputs?

ELEKTOR FORUMS

Please log in to post a reply or subscribe / unsubscribe to topics

Topic: How to program more digital outputs?

Author Post

Lande

19 posts

Popping In
Popping In

Read post 09-05-2009 02:50

Hello all.

After a while without being able to experiment with my DigiButler, I finally got a chance now. After I got familiar with the many files in the project and with invaluable input from jart in another post I have managed to program the other 3 digital outputs (GPT0-3), so they can be switched on and off.

Does anyone know if there is a way to program the analog intputs (AN0-7) to work as digital outputs in a similar way as GTPx?

Regards

Lande

TheUSBoss

8 posts

Popping In
Popping In

Read post 11-05-2009 12:01

Hi Landi,

I have been wanting to do this myself, so would appreciate you publishing exact details on how to do this.

many thanks

TheUSBoss

8 posts

Popping In
Popping In

Read post 11-05-2009 12:02

Appologise for the misspelling of your name Lande

HLaidet

61 posts

Frequent Visitor
Frequent Visitor

Read post 12-05-2009 00:46

Hello,


Here is the method to programm AN0-7 as GPIO:
- Initialisation sequence
#define MASK_BITS 0x0F // AN0-3 as GPIO and AN4-7 as analog inputs (4 example...)
MCF_GPIO_PANPAR &= ~(MASK_BITS); // Port Assignment Register (0=GPIO, 1=Primary function)
MCF_GPIO_DDRAN = MASK_BITS; // Data Direction Register (0=input, 1=output)
- Set Reset Bits
MCF_GPIO_PORTAN = 1; // set bit0 and reset others (example...)

Now you can use to port AN MCF_GPIO_PORTAN as MCF_GPIO_PORTTA for GPT0-3.

You can find what you want in doc Freescale:"MCF52235RM"
(MCF52235 ColdFire Integrated Microcontroller Reference Manual)


Greetings, Henri

Lande

19 posts

Popping In
Popping In

Read post 12-05-2009 02:42

Thanks Henri.

I have not a lot of experience with this sort of programming, but I will try to revise the document and with your input and what I already have, it should be possible to get something working.

If anyone else has more input, please feel free.

I will publish my findings here.

Lande

Lande

19 posts

Popping In
Popping In

Read post 13-05-2009 14:00

Hello Henri and others.

I understand the concept you've explained, but I have trouble fiding the correct place for the statements. So far I have done the following:

1. In the file freescale_http_server.h in the section "Mains Control" I have added #define MASK_BITS 0x00 (I did not add 0x0F as suggested, since I would want all ANx to be outputs).
In the section of the same file I have added
#define SSA0_ON MCF_GPIO_PORTTA = (uint8)(MCF_GPIO_PORTTA| MCF_GPIO_PORTAN_PORTAN1);
I have tried different combinations, since I do not know the syntax.

2. In the file freescale_static_fss_utils.c I have created function

void form_SSA0_function( char *data )
{
UINT32 *flag = &html_vars[15];
char *str;
if (str = strchr(data, '&')) *str = 0x0; /* clear & character */
if (!(strcmp(data,"LIGHT_ON"))){
MCF_GPIO_PANPAR &= ~(MASK_BITS);
MCF_GPIO_DDRAN = MASK_BITS;
SSA0_ON;
*flag = 1;
// disable interrupt on the RTC
//MCF_RTC_IER &= ~MCF_RTC_IER_ALM;
//MCF_INTC0_IMRH |= MCF_INTC_IMRH_MASK63;
return;
}
}

which is heavily based on existing code. The code compiles and I am able to flash the DigiButler.

In the browser I enter
http://192.168.0.152/index.htm?SSA0=LIGHT_ON

where I expect AN1 to change state. That does not happen, nor it does for any other ANx. I can see that there is som kind of reaction, since the page apparently is reloaded.

Any ideas of what's wrong?

Regards

Lande

HLaidet

61 posts

Frequent Visitor
Frequent Visitor

Read post 13-05-2009 19:16

Hello Lande,

there are some errors in the code:

1/ MASK_BITS = 0x00 is not correct
MASK_BITS = 0xFF is good: each bit to 1 means GPIO

2/ init section:
***MCF_GPIO_PANPAR &= ~(MASK_BITS);
***MCF_GPIO_DDRAN = MASK_BITS;
you must place the init section in "main.c" (after start_AD()
to be called only one time.

3/ the macro SSA0_ON is not correct
it must be as this:
#define SSA0_ON MCF_GPIO_PORTAN = (uint8)(MCF_GPIO_PORTAN| MCF_GPIO_PORTAN_PORTAN0);
#define SSA0_OFF MCF_GPIO_PORTAN = (uint8)(MCF_GPIO_PORTAN&~MCF_GPIO_PORTAN_PORTAN0);

don't mix MCF_GPIO_PORTTA and MCF_GPIO_PORTAN

now in your procs form_SSA0_function() you call SSA0_ON or SSA0_OFF without init section.

Greetings, Henri

Lande

19 posts

Popping In
Popping In

Read post 15-05-2009 00:57

Hello.

Thanks Henri for the code sample. It works just fine now. I am able to switch pin 4 og J7 (AN0) on and off just by entering http://192.168.0.152/index.htm?SSA0=LIGHT_ON or http://192.168.0.152/index.htm?SSA0=LIGHT_OFF in the browser. Now it should be easy to control the other outputs.

If anyone would like more details, I would be pleased to post, otherwise the correspondence might speak for itself.

Lande

TheUSBoss

8 posts

Popping In
Popping In

Read post 08-06-2009 14:39

Hi Lande,

Please can you publish or email me the exact process for adding digital ports and circuit diagrams on how to max out on input and output ports.
thanks

Please log in to post a reply or subscribe / unsubscribe to topics

Subscribe now

Subscribe to our free
E-weekly Newsletter!

Enter your Email address:

Follow Elektor

      

Act now!

Sponsored

FAQ

Before submitting questions, review our FAQ section!

Bestseller

Controller Area Network Projects

The aim of this book is to teach you the basic principles of CAN networks and in addition the development of microcontroller based projects using the CAN bus.

Package Deals

Elektor Bundles

Check our Package Deals and save money! Discounts up to 19% now available!

Price Slashed

Elektor OSPV

This Open Source People Vehicle is perfect for factory halls, warehouses, hospitals, colleges, schools etc.