Jump to content

Picxie

Moderator
  • Content Count

    277
  • Joined

  • Last visited

Everything posted by Picxie

  1. For actual details on using the PWM to control a motor you would probably be better off looking at some of the amateur robotics (Robot Wars!) type websites. Pic manuals can be somewhat confusing due to the multifunction of the hardware. The PWM controlled by Timer 2. The Timer2 module has an 8-bit period register, PR2. Timer2 increments from 00h until it matches PR2 and then resets to 00h on the next increment cycle. When Timer2 matches PR2(in PWM mode) it sets the PWM out pins to 1. It also can generate an interrupt but you may ignore that if not required. So timer 2 and PR2 set the PWM period, ie the time between two rising edges on the output of the pwm pins. The prescalers of Timer2 combined with the system oscillator set the time for a one bit count of Timer2. The duty cycle of the PWM is set by a 10 bit value 8 msbs into the CCPRxL register and 2 lsbs into CCPxCON bit 5 and 4. when Timer 2 matches the value in CCPRxL and the 2lsbs match the value of the 2 msbs in teh divider driving timer2, PWMx is cleared. Note that if thevalue in CCPRxL is greater than in PR2 then PWMx will remain high. When designing a PWM system you should set the prescale of Timer 2 to give the largest possible value of PR2 to give a greater range of PWM control. Setting up timer 2's period is straight forward, its base input is fosc/4 ie at 20MHz it is being driven at 5MHz. The prescaler can further divide down the clock to timer2. Timer 2 also has a post scaler, this is used alter the trigger of timer2 interrupt. So looking at pwm period= [PR2+1]*4*Tosc*[TMR2 prescale value] Suppose we wanted a pwm period of 100us ie a frequencyof 10KHz Tosc is 1/20,000,000. Times 4 to get the base rate is 4/20,000,000 ie 200ns. Assume no prescaler divide our period by our base rate gives us 100us/ 200ns to give us PR2+1 which come to 500 so PR2 should be set at 500-1, 499. However PR2 is only 8 bits so we need a smaller value. lets apply prescaler of 16. 200ns*16 = 3.2us so 100us / 3.2 us gives 31.25, so load PR2 with 30. Mmh a bit coarse and 30+1 * 3.2 us give 99.2us or 10.08Khz. Lets apply prescale of 4, 200ns *4 = 800ns, 100us / 800 give 125 so load PR2 with 124, this gives exactly 10KHz or 100us and is the largest possible value of PR2 to get a 10KHz pwm with a 20MHz clock so gives the finest control of the pwm duty cycle.
  2. The PIC device programming specifications do allow the EEPROM and program memeory to be programmed seperately. It all depends whether your programmer impliments this.
  3. That's strange because in the BoostC Reference Manual (page 42) it says: "Arrays can have any number dimensions" So there's no way to do such lookup table in BoostC ? Anyone some ideas ? <{POST_SNAPBACK}> Sorry, my partial mistake the exact quote from the manual is Arrays can have any number of dimensions. The only constraint is that an array must fit into a single RAM bank. ie , ok for arrays of variables but not for arrays of rom data. Maybe Dave or Pavel could confirm this.
  4. BoostC does not support multi-dimensional arrays.
  5. Sorry no, you are going to have to tell us what the problem is.
  6. You also need to set the device configuration correctly, like oscillator type, disable watchdog etc. Take a look at some of the supplied BoostC sample programs and go from there. Regards Dave <{POST_SNAPBACK}> Picxie, How do you change it to digital ports? <{POST_SNAPBACK}> Read page 128 in the data sheet.
  7. You should consult Microchips datasheet on this device http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf On reset PORTA pins are assigned as analogue inputs for the ADC, its not just a matter of clearing the required TRISA bits, you have to unassign the port bits you equire. This is set in ADCON1. See page 128 in the datasheet for further details.
  8. Its not usual to put code in headers. I bet if you took all that code out of the .h files and put it in .c files your problem will disappear
  9. Also be aware of hidden calls, for instance BoostC uses a call to access a table in program space, other hidden calls are possible if you use multiply or divide operations.
  10. C has two shift operator << and >>. eg x = y << 3; // y is left shifted 3 bits , the result is stored in x. z = w >> t; // w is right shifted according to the contents of t, result stored in z beware wrong y<<2;// y is shifted left two places but the result is not stored so y stays the same correct y = y << 2; note that zeros are always shifted in, there is no arithmetic shift You should consult a C manual for more detail
  11. Ra68qi has a tutorial thread which is probably going to be a good starting point. You can find it at http://forum.sourceboost.com/index.php?showtopic=2399
  12. the duty cycle is set by CCPR1L and CCPR1H for pwm 1 and CCPR2L and CCPR2H for pwm 2. As far as I can see they operate independantly at the same frequency, though I have never run both, so I cant confirm it.
  13. Use a bit mask and shift the mask eg mask = 1; if (byteundertest & (mask << numberofshifts) !=0)
  14. BoostC does not support extended instructions.
  15. If the PIC you are using has only 1 or 2K of code space than increasing the compilers code max will not make the code ft the device. What device are you using?
  16. (* VS_GUARDEXPR_TYPE) (VS_VOID) is a definition for a function pointer. Sourceboost does not support function pointers.
  17. The limiting factor is the size of program memory (and data EEPROM) for the device you are using. The PIC16F877 has 8K of program words and 256 bytes of EEPROM. The hex file uses 2 bytes to represent a program word so the largest hex file would be have 16K bytes of program 256 bytes of data and probably 1 byte of config. The file's physical size will be slightly larger due to additional information that the hex file format uses.
  18. BoostC18 seems to use only FSR0 and INDF0 for indirect accesses. Copying indirect source to indirect destination would be greatly optimised by using FSR0 as the source and FSR1 as the destination. whilst on the subject. FSR2, INDF2 could be used during the interrupt thread so that FSR0 and INDF0 would not need saving and restoring during interrupt. If you don't use FSR1 for indirect destination operations it could be used for the low level interrupt.
  19. Emte, I don't know what your expectations of the internal CAN interface are but I guess it pretty low and based upon experience of other serial PIC peripherals:) The Microchip guys have done a good job (for a change) with CAN interface, it does all the work of filtering and buffering and requires very little processor overhead once set, up consider it more of an MCP2515 conjoined twin. However... the documentation supplied for the PIC18F2680 CAN is overwhelming (particularly for a CAN virgin) due to the complication thrown in by eCAN, it would be easier on the eyes if it was split into a standard CAN and enhanced CAN chapter.
  20. I dont think any of these are valid optimisations with BoostC. BoostC performs additional optimisations on shift operations.
  21. The on board CAN controller fitted to the PIC182680 when used in legacy mode is surprizingly similar to the MCP2515, if you ignore the windowing system for relocating buffers int base RAM it is in fact easier because you dont have the overhead of SPI comms. Unlike the MCP2515 There is no RESET instruction (the processor reset does that!) All you need to do to set up for standard (Not extended) legacy is Request config mode When config granted (should be immediate) Set up the three control register for setting the bit period (follow the example for the external CAN) Set the TX regs priorities etc(again identical to external) Set up RX regs priorites etc(again identical to external) Set up any required MASKS and Filters Set up any interrupts (again not needed you can always poll) Set Normal mode and off you go! Note that you do not need to set any masks and filters but the controller will accept all received messages That should get you going. Dont forget you still need a CAN driver such as the MCP2551. Have fun!
×
×
  • Create New...