New from MAssachusetts

Say "hi" here, and any general non PIC related chat.

New from MAssachusetts

Postby geo » Wed Feb 24, 2016 3:12 pm

Hello All,

Just joined the forum from Massachusetts (Field of expertise is ASIC/FPGA design with VHDL and Verilog)...

I have been messing around with the Curiosity board (16F1619), got my first main.c running with the blinking LED
macros (delay & blink) from <pin_manager.h>, enabled by the on board tact-switch.

I'm trying to modify my main() to have code that will read the Curiosity potentiometer, then,
if it's > "some_value", enable the LED to blink(for starters). I would really like to understand details of how
to create pragmas & macros for the SFRs, and, where all of the calls/macros in the underlying code are such as:

//Start conversion by setting the GO/DONE bit. (lifted from the forum)
ADCON0bits.GO_nDONE = 1;

Anyone willing to point me in the right direction would be much appreciated!
...simple code, lot's of cockpit errors not knowing the environment.

Best Regards,
Paul
geo
 
Posts: 7
Joined: Wed Feb 24, 2016 2:38 pm

Re: New from MAssachusetts

Postby AussieSusan » Thu Feb 25, 2016 4:15 am

Which compiler and IDE are you using?
With Microchip devices you generally don't need to use functions and macros except to make your own code easier. My experience recently is that this cannot be said for ARM type devices where there are functions and software layers galore to do the simple things like setting an I/O bit.
If you look at the data sheets for your device, you will see on page 203 the register definition for ADCON0 - hence the first part of the name you mention.
Because most registers are actually collections of bits, compilers such as XC16 will define a structure for each SFR (special function register) that is the register names followed by 'bits' - hence the full name you mentioned 'ADCON0bits'.
The reason I asked about the compiler is that the XC16 compiler normally uses the name of the bit field in the data sheet in the structure definition. Therefore I would expect to see the name being ADCON0bits.GODONE - however it may be that they used the slightly different name for this bit field to highlight the negated nature of the 'DONE' interpretation of the bit.
The typical structure of your program will be to include a file that contains the SFR definitions. For the XC16 compiler this is hidden behind the <xc.h> include that uses the device seleciton in the IDE (passed as a preprocessor symbol in the command line to the compiler). However there will be a file named something like "p16F1619.h" in the system include directory path that will tell you the exact SFR names and bit fields if you ever need to look them up.
What I normally do is to use the 'autocomplete' feature of the MPLABx IDE to help with SFR names and the various bitfields - saves you looking them up all the time.
Susan

Edit: I meant XC8 and not XC16 in the above!!!! SIgh!
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: New from MAssachusetts

Postby geo » Thu Feb 25, 2016 9:22 pm

Thanks Susan,

I'm using the XC8 compiler just to get my feet wet with a PIC16F1619 that came with the Curiosity board. After I posted, I did a lot more digging through code that has been posted and am starting to get the feel of the PIC environment. I also found the "p16F1619.h" file which explained a LOT! I can see how it would be confusing to someone if you don't understand overloading looking at the unions and structs in the header files. I'm pretty comfortable with these structures as I have done similar overloading in VHDL and Verilog for ASIC design in the past.

So, my next step is to try to get the ADC to convert the signal from the on board POT and decide how fast to blink the LED based on the conversion value. I intend to start by single stepping using the debugger (with a watch window on the ADC results register) to see if my code is actually working.

Thanks again for your input!
Paul
geo
 
Posts: 7
Joined: Wed Feb 24, 2016 2:38 pm


Return to Introductions and general chat

Who is online

Users browsing this forum: No registered users and 8 guests

cron