Voor een project gebruik ik een een PIC16F1527. Er worden 8 ccp modules gebruikt voor pwm aansturing van leds. alles werkt goed, behalve dat er exact iedere 2,44 seconden een fout zit in al de pwm signalen.
Ook als ik de scaler van de interne oscillator (16MHz) naar 8 of 4 MHz blijft de fout zich iedere 2,44 seconden voordoen.
Hieronder de code van mijn MPLab X project:
hieronder een scope beeld van de tijd tussen 2 fouten:

en hieronder een scope beeld van een fout uitvergroot:

Het gele signaal is telkens de pwm uitgang aan de pic, het groene signaal is de retour van de led's, de storing hierop ligt aan onvoldoende ontkoppeling (en iets minder goed print ontwerp)
De fout komt op alle pwm kanalen voor op exact hezelfde moment. Ik heb al al de prescalers uit gezet, maar dit verhelpt de fout niet, ik heb ook al de globale interupts uitgezet en al gevoed vanuit de pickit en vanuit een externe bron, de 3v3 lijn blijft stabiel.
Ik heb geen idee meer waar ik moet zoeken om deze fout eruit te krijgen,
iemand die nog iets weet om te proberen om van deze fout af te raken?
alvast bedankt
Ook als ik de scaler van de interne oscillator (16MHz) naar 8 of 4 MHz blijft de fout zich iedere 2,44 seconden voordoen.
Hieronder de code van mijn MPLab X project:
C:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| /******************************************************************************/ /* Files to Include */ /******************************************************************************/ #if defined(__XC) #include <xc.h> /* XC8 General Include File */ #elif defined(HI_TECH_C) #include <htc.h> /* HiTech General Include File */ __CONFIG(FOSC_INTOSC & WDTE_ON & PWRTE_OFF & MCLRE_ON & CP_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_ON & FCMEN_ON); __CONFIG(WRT_OFF & VCAPEN_OFF & STVREN_ON & 0 & LPBOR_OFF & LVP_ON); #endif #include <stdint.h> /* For uint8_t definition */ #include <stdbool.h> /* For true/false definition */ /******************************************************************************/ /* User Global Variable Declaration */ /******************************************************************************/ /******************************************************************************/ /* Main Program */ /******************************************************************************/ void main(void) { OSCCONbits.SCS = 0b10; //gebruik internal oscillator OSCCONbits.IRCF = 0b1101; //zet interne oscillator op 4MHz TRISCbits.TRISC2 = 0; //ccp1 pin output TRISCbits.TRISC1 = 0; //ccp2 pin output TRISGbits.TRISG0 = 0; //ccp3 pin output TRISGbits.TRISG3 = 0; //ccp4 pin output TRISGbits.TRISG4 = 0; //ccp5 pin output TRISEbits.TRISE6 = 0; //ccp6 pin output TRISEbits.TRISE5 = 0; //ccp7 pin output TRISEbits.TRISE4 = 0; //ccp8 pin output TRISEbits.TRISE3 = 0; //ccp9 pin output TRISEbits.TRISE2 = 0; //ccp10 pin output T2CONbits.T2CKPS = 0b11; //timer 2 prescaler 16:1 T2CONbits.T2OUTPS = 0b0000; //timer 2 postscaler 1:1 T2CONbits.TMR2ON = 0b1; //timer 2 aan PR2 = 0b11111111; //pwm period CCPTMRS0bits.C1TSEL = 0b00; //gebruik timer 2 voor pmw1 CCPTMRS0bits.C2TSEL = 0b00; //gebruik timer 2 voor pmw2 CCPTMRS0bits.C3TSEL = 0b00; //gebruik timer 2 voor pmw3 CCPTMRS0bits.C4TSEL = 0b00; //gebruik timer 2 voor pmw4 CCPTMRS1bits.C5TSEL = 0b00; //gebruik timer 2 voor pmw5 CCPTMRS1bits.C6TSEL = 0b00; //gebruik timer 2 voor pmw6 CCPTMRS1bits.C7TSEL = 0b00; //gebruik timer 2 voor pmw7 CCPTMRS1bits.C8TSEL = 0b00; //gebruik timer 2 voor pmw8 CCP1CONbits.CCP1M = 0b1100; //ccp1 PWM mode CCP2CONbits.CCP2M = 0b1100; //ccp2 PWM mode CCP3CONbits.CCP3M = 0b1100; //ccp3 PWM mode CCP4CONbits.CCP4M = 0b1100; //ccp4 PWM mode CCP5CONbits.CCP5M = 0b1100; //ccp5 PWM mode CCP6CONbits.CCP6M = 0b1100; //ccp6 PWM mode CCP7CONbits.CCP7M = 0b1100; //ccp7 PWM mode CCP8CONbits.CCP8M = 0b1100; //ccp8 PWM mode CCP1CONbits.DC1B = 0b11; // duty cycle 2LSB PWM1 CCP2CONbits.DC2B = 0b00; // duty cycle 2LSB PWM2 CCP3CONbits.DC3B = 0b00; // duty cycle 2LSB PWM3 CCP4CONbits.DC4B = 0b11; // duty cycle 2LSB PWM4 CCP5CONbits.DC5B = 0b00; // duty cycle 2LSB PWM5 CCP6CONbits.DC6B = 0b00; // duty cycle 2LSB PWM6 CCP7CONbits.DC7B = 0b00; // duty cycle 2LSB PWM7 CCP8CONbits.DC8B = 0b00; // duty cycle 2LSB PWM8 CCPR1L = 0b00000100; //duty cycle 8MSB PWM1 //IC2 CCPR2L = 0b00000000; //duty cycle 8MSB PWM2 //IC1 CCPR3L = 0b00000100; //duty cycle 8MSB PWM3 //IC6 CCPR4L = 0b10000000; //duty cycle 8MSB PWM4 //IC7 CCPR5L = 0b00000000; //duty cycle 8MSB PWM5 //IC8 CCPR6L = 0b00000000; //duty cycle 8MSB PWM6 //IC3 CCPR7L = 0b00000000; //duty cycle 8MSB PWM7 //IC4 CCPR8L = 0b00000000; //duty cycle 8MSB PWM8 //IC5 while(1) { } } |
hieronder een scope beeld van de tijd tussen 2 fouten:

en hieronder een scope beeld van een fout uitvergroot:

Het gele signaal is telkens de pwm uitgang aan de pic, het groene signaal is de retour van de led's, de storing hierop ligt aan onvoldoende ontkoppeling (en iets minder goed print ontwerp)
De fout komt op alle pwm kanalen voor op exact hezelfde moment. Ik heb al al de prescalers uit gezet, maar dit verhelpt de fout niet, ik heb ook al de globale interupts uitgezet en al gevoed vanuit de pickit en vanuit een externe bron, de 3v3 lijn blijft stabiel.
Ik heb geen idee meer waar ik moet zoeken om deze fout eruit te krijgen,
iemand die nog iets weet om te proberen om van deze fout af te raken?
alvast bedankt