Hi Peter

Peter Chant schrieb:
> void pwm_setup(void) {
> _asm
> 
>   ;#define STATUS 0x03
> 
make sure that bank0 is selected here (BCF    STATUS, RP0)
>     CLRF   CCP1CON       ;  CCP Module is off
>     CLRF   TMR2          ;  Clear Timer2
>    ;clrf 0x11 ; timer 2 is 0x11
> _endasm;
>       CCP1CON = 0;
>       TMR2 = 0;
the last two c-code lines are equal to the first two assembler lines above
> _asm  
> 
>     MOVLW  0x7F          ;
>     MOVWF  PR2           ;
PR2 is in Bank1, you need a bsf status, RP0 before accessing PR2
>     MOVLW  0x1F          ;
>     MOVWF  CCPR1L        ;  Duty Cycle is 25% of PWM Period
CCPR1L is in bank0, dont forget to do bcf status rp0
>     CLRF   INTCON        ;  Disable interrupts and clear T0IF
>     ;BSF    STATUS, RP0   ;  Bank1
>    bsf STATUS,5
>     ;BCF    TRISC, PWM1   ;  Make pin output
>     bcf TRISB,3
>     CLRF   PIE1          ;  Disable peripheral interrupts
>     ;BCF    STATUS, RP0   ;  Bank0
>     bcf       STATUS,5
>     CLRF   PIR1          ;  Clear peripheral interrupts Flags
>     MOVLW  0x2C          ;  PWM mode, 2 LSbs of Duty cycle = 10
>     MOVWF  CCP1CON       ;
>     ;BSF    T2CON, TMR2ON ;  Timer2 starts to increment
>     bsf       T2CON,2

If the code doesn't run as expected then there is a problem in your
hardware, wirering, config etc. etc.

Things to check:
- Does your cpu runs at all? Toggle a bit on the pwm port and try to
measure the frequency.
- What else are you doing in your Programm. For testing you should have
after the initialization just a while(1) {} loop in your main().
- Important: Did you enable the watchdog in your config register? If so
disable is.

Regards,

Jan


-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to