View unanswered posts | View active topics It is currently Tue Nov 12, 2019 8:14 pm



Reply to topic  [ 28 posts ]  Go to page Previous  1, 2, 3
My first program 
Author Message
LQFP112 - Up with the play
User avatar

Joined: Wed Jul 16, 2008 9:21 am
Posts: 140
Location: NSW, Australia
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:
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....


Thu Jul 16, 2009 7:25 am
Profile
1N4001 - Signed up

Joined: Thu May 29, 2008 1:23 am
Posts: 307
Location: Long Beach CA
When you get a chance, attach your latest version and I'll have another look.


Thu Jul 16, 2009 8:38 am
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 15342
Location: Home sweet home!
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!


Thu Jul 16, 2009 1:24 pm
Profile WWW
LQFP112 - Up with the play
User avatar

Joined: Wed Jul 16, 2008 9:21 am
Posts: 140
Location: NSW, Australia
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.]
Fri Jul 17, 2009 2:38 am
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 15342
Location: Home sweet home!
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!


Fri Jul 17, 2009 12:45 pm
Profile WWW
1N4001 - Signed up

Joined: Thu May 29, 2008 1:23 am
Posts: 307
Location: Long Beach CA
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.


Sat Jul 18, 2009 5:29 am
Profile
LQFP112 - Up with the play
User avatar

Joined: Wed Jul 16, 2008 9:21 am
Posts: 140
Location: NSW, Australia
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.


Wed Jul 22, 2009 3:53 am
Profile
Moderator
User avatar

Joined: Tue Jan 15, 2008 2:31 pm
Posts: 15342
Location: Home sweet home!
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!


Thu Jul 23, 2009 10:41 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 28 posts ]  Go to page Previous  1, 2, 3

Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF. ColorizeIt.