From here when the counts in TMR2 match the CCPR1L(plus 2 bits) the signal goes low. The way the PWM works is when the TMR2 register rolls over to zero the line goes high. The fact that it can support up to 10 bits does not mean that the processor subdivides the period in to 1024 pieces, it can't because it is already running as fast as possible. That also restricts the maximum resolution of the duty cycle to a single timer count. This means that the maximum resolution of the the timer is a single count. If your timer 2 prescalar is set to 1 then the timer is running as fast as possible. Nothing in the processor can happen any faster then the provided clock. With some trickery timer 2 (the timer for PWM) and the duty cycle supports up to 10 bits. You can only set a duty cycle between 0-65. The duty cycle your trying to set is 255. The duty cycle is a fraction of the period. Only use xc.hĪlso your overloading your duty cycle. Unsigned int voltage = ADRESL | (ADRESH start a new PWM cycleĭon't use #include and #include at the same time. #define CHECK_BIT(var,pos) ((var) & (1> 2 What could the problem be?ĮDIT: I am following this procedure which is written in the PIC12F683 datasheet, but I am either not doing it right or there's something else I need to do. Instead I get a 5kHz "weird" PWM signal such that when I set the duty to be 255, which should be maximum, I get this 5kHz wave. According to my calculations I should get an 8 bit 20kHz PWM at GPIO2, but that does not happen. I'm trying to make PWM to work on the PIC12F683.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |