Pic PWM programming in C, cant figure out how to change the duty cycle

NorthGuy

Joined Jun 28, 2014
611
Is there a more intuitive way to set an individual bit than specifying the binary equivalent of an 8-bit register value in hexadecimal?
it seems that being able to code something like
setLDAbit = 1 is more intuitive to me than
PWM1LDCON = 0x80.
Sure (if you use XC8):

C:
PWM1LDCONbits.LDA = 1;
 

Thread Starter

Travm

Joined Aug 16, 2016
363
No point in using machine generated code. Read the data sheet and you will always write the correct code, every single time.
That might make sense for someone who works with this stuff all-day. I need tools like MCC to simplify the process. I get the purists perspective, but that will never be me. The microcontroller itself is just another tool for me to get something real done. Time spent being Linus Torvalds of the microchip world is money wasted.
I am pretty sure I've read this data sheet 20 times. It's comprehension at this point.
 

Thread Starter

Travm

Joined Aug 16, 2016
363
then get an arduino. they do exactly what you wanted to do.
No, this isn't a hobby. I researched this thoroughly, it is pic programming i intend to learn. MCC is a wonderful tool to speed development. Not a crutch for not learning the registers. Nothing in this thread has been about MCC making bad code. In fact if I had tried to hand code all of the registers I'm sure I would have failed. MCC has given me working example code. Considering how well it worked I see no reason to ever fully hand configure a chip. You still have to understand what all the registers are and how they work. It just lets you visualize everything graphically.

Your statement that hand coding is less error prone, I do not agree.

Pic chips actually do exactly what I want to do, in a smaller package, with more peripherals, at lower cost. I have already designed my hardware, now it's just learning the software.
 

johndeaton

Joined Sep 23, 2015
63
MCC is a wonderful tool to speed development. Not a crutch for not learning the registers.
I agree with this. Just use it with caution because the code generation was written by software developers just like us. They make mistakes, too. I like to generate it with MCC and then check to make sure everything jives with the datasheet. Also, don't pick the wrong chip like I did earlier :)


In fact if I had tried to hand code all of the registers I'm sure I would have failed.
I don't agree with this. You seem very capable :) Good luck!
 
Top