Quote:
Originally Posted by e*clipse
Regarding frequency - it would be nice to have a way to adjust for different oscillator frequencies and PWM frequency settings without messing up code behavior later. I would really like to play with the PWM frequency.
- E*clipse
|
I noticed that Paul uses a Delay function dependent on the instruction clock - Fcy (yes?). This forms the basis for seconds and tenths of seconds delays. There's also a uS delay function but it is hardcoded dependant on the clock frequency.
Right now that portion of code, from the program I have, assumes a 30MHz clock but based on the new board the system clock is 29.4912MHz:
Code:
-> Fcy = FOSC/4= crystalFreq*PLLmultiplier/4 = 7.3278*16/4.
Based on what I read in the manuals, I think this is correct. Paul hard-codes a counter to be used by the delay function to count the clock ticks that add up to the time unit required (1 second, 1/10th of a second). I've adjusted the code I have to work with the clock frequency defined on the new board design - at least I'm hoping that's what I did.
I'm thinking that modifying these so the multiplier used by the functions is predetermined based on the clock frequency can help with what you want to do. Possibly the clock frequency can be one of the initialization parameters and the multiplier determined from it.
Regarding PWM frequency, adjusting PTPER value in the initializing function for the AD and PWM seems like it should help. This is also tied to the Fcy so again the abstraction concept above can allow easier adjustment perhaps? Incidentally the Fcy is defined based on crystal in the new board design.
If this doesn't make sense please let me know as it will help with my understanding of the code.