My first program

A place to discuss software and code that isn't automotive related. Free and open source preferred but not compulsory.
User avatar
longracing
LQFP112 - Up with the play
Posts: 140
Joined: Wed Jul 16, 2008 9:21 am
Location: NSW, Australia

Re: My first program

Post by longracing »

That is correct, the Pic32 is a MIPS uC. I'm using the evaluation version of C32 compiler, it's a free download from the Microchip website after you've registered. I've been learning a lot in C using it. The Arduino is still a lot easier to use because there are a lot more libraries already available for just about any Hardware you need to connect or software functions.

Thanks MotoFab for that help.
I've changed the code so it is now loading the values for the testing instead of the address.
Also found you need to clear the RABPU bit in the option register to get control of the WPUs.

Code: Select all

bcf		OPTION_REG,NOT_RABPU	; enable WPU on PortB
Still having trouble getting the batt_type select to work.
I've gone back to the LPC demo board and a switch to try and get this working correctly. Might add an external pull-up resistor because this is frustrating (good learning though). I can't seem to get the BTFSS working correctly on the PORT or PORTcopy.
Pity they don't have a smiley for a fried brain....
MotoFab
1N4001 - Signed up
Posts: 307
Joined: Thu May 29, 2008 1:23 am
Location: Long Beach CA

Re: My first program

Post by MotoFab »

When you get a chance, attach your latest version and I'll have another look.
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: My first program

Post by Fred »

Just to follow up on Jim's comments about unused pins...

He's dead right, but you may be interested to know why it is good to do as he says. If you leave the device with floating pins as inputs and don't tie them with resistors they do float and they put the transistors inside the chip into the linear region instead of saturated and therefore use more power and generate more heat - for nothing. If you have them as outputs and short them, kiss them goodbye too. Hence the best solution is to lay out with resistors tied to rail.

Thanks for all the great posts, Jim. Good to see.

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
longracing
LQFP112 - Up with the play
Posts: 140
Joined: Wed Jul 16, 2008 9:21 am
Location: NSW, Australia

Re: My first program

Post by longracing »

8-) Finally have success.

I changed the batt select to Port-A pin2 since that was already configured as an input. Not sure why portB gave so much trouble but did see that it had USART & SSP on that port. Anyway tried portA with a hardware pull-up resistor and a switch to ground, that worked. Then it was a little bit of playing around to get the internal weak pull-up working. The unused pins are set as outputs at (0).

Now it still works with the original board. If left as is it is set for lithium packs. To set up for SLA simply requires a short jumper from portA pin2 to a nearby unused pin that is at (0), or longer jumper to the main ground. Will be testing in one of the units soon.

Also came up with the idea of adjusting the values in the voltage divider to be able to measure the peak battery voltage. That way it could detect the battery type and change the levels to suit.....
I think I will shelve that idea some where up the back. :geek: trying to get too smart with the software could get into all sorts of trouble.

Thanks to everyone for their feedback and help. I think I owe you guys a beer if you make it to Oz ;)

Now I can get back to learning 'C' for the FreeEMS project.
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: My first program

Post by Fred »

Well done :-)

With respect C, it sounds like you fully "get" the ASM, if so, a good way to see C might be to write some simple statements in a new file and build the project. My makefile leaves the intermediate artifacts in place to view so you can see the ASM that is generated from the C. It is actually pretty much 1:1 as C isn't really all that expressive, it just cuts down the manual labour :-)

Do you have the FreeEMS stuff building? I can't remember if you are in that thread of "I've built it" or not.

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
MotoFab
1N4001 - Signed up
Posts: 307
Joined: Thu May 29, 2008 1:23 am
Location: Long Beach CA

Re: My first program

Post by MotoFab »

Good job!

After configuring peripherals, ports, and pins, there's a coding technique for ruggedness you can add in. It's loosely called 'housekeeping'. Generally stated, make a complete list of all the configuration settings, including the chip's default settings when that's what you're using. Then regularly, or at some commonly passed point in the code, run through that ''configuration routine' and reassert the configuration. For simple applications, that housekeeping can be done when the Watch Dog Timer is reset.

I see that too, Fred. The more I look at C, the more it looks like assembly with shortcuts. I think with the various 'light' versions of pic C compilers there's a way to build the C and view the generated assembly with the comments. From what I understand, that can be done from inside the IDE. Prolly none of this is unique, but it's all new to me.
User avatar
longracing
LQFP112 - Up with the play
Posts: 140
Joined: Wed Jul 16, 2008 9:21 am
Location: NSW, Australia

Re: My first program

Post by longracing »

I think I'm getting Ok with writing parts of C but the main thing to learn will be how to best organise the program flow and techniques for making it readable/portable.
The rest of the instructions are more about getting familiar with the chipset or compiler.

I have downloaded eclipse and other files but haven't built it on my laptop yet. Damn thing came with Vista, I went back to XP a couple of times to get a few programs working but then I didn't have all the drivers and other programs wouldn't work :mad: Guess that's the evil MicroS0ft way.
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: My first program

Post by Fred »

You should dual boot it with vista and ubuntu (or whatever you want) and maybe xp also (triple). You may find you like Linux :-)

No need to build freeems, just get GCC setup on there and build native stuff or for the AVR family (much simpler instruction set than x86). A simple "hello world" program would be a good start, then add some basic math to it and see what the compiler creates assembly wise for that.

Program flow and portability wise, you want to follow this :

http://c2.com/xp/OnceAndOnlyOnce.html

If you are good at following that, all else should fall into place around it. The low level nature of C and the types of things we do with it in embedded world make it kinda hard to do really well though.

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
Post Reply