Avec le confinement les vieux projets ressortent du cahier pour combler le temps et vider la tête.
Le projet que je tente de mener à bien est une alimentation de laboratoire réglable à 2 étages d’ hacheur.
1 étage représente un hacheur abaisseur et 1 étage pour un hacheur élévateur.
Une fois avancé je ferais un sujet complet.
Mais voila je rencontre quelques problèmes de paramétrages avec l'µC choisi, un 18F2550.
J'ai la solution de changer de référence mais bon j'aimerais comprendre.
Voila mon code:
Code : Tout sélectionner
program Alimentation_de_laboratoire
' Declarations section
' Lcd module connections
dim LCD_RS as sbit at LATB4_bit ' RB4_bit
LCD_EN as sbit at LATB5_bit 'RB5_bit
LCD_D4 as sbit at LATB0_bit 'RB0_bit
LCD_D5 as sbit at LATB1_bit 'RB1_bit
LCD_D6 as sbit at LATB2_bit 'RB2_bit
LCD_D7 as sbit at LATB3_bit 'RB3_bit
LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit
' End Lcd module connections
dim ADD_DUTY,SS_DUTY,compt,current_duty_T1, current_duty_T2, gestion_pwm,toto as byte
dim tension as float
dim tension_num as word
dim txt,txt1 as string[6]
BP_PP as sbit at PORTC.4
BP_PP_dir as sbit at TRISC4_bit
'BP_P as sbit at PORTC.5
'BP_P_dir as sbit at TRISC5_bit
BP_M as sbit at PORTC.6
BP_M_dir as sbit at TRISC6_bit
BP_MM as sbit at PORTC.7
BP_MM_dir as sbit at TRISC7_bit
sub procedure INIT()
ADCON0 = 0x01
ADCON1 = 0x0E
ADCON2 = 0xA4
' TRISA = 0xFF ' PortA en entrée
TRISA0_bit = 1
TRISB = 0x00 ' PortB en sortie
TRISC = 0xF0 ' PC0 à PC3 en sortie et PC4 à PC7 en entrée
' PWM1_Init(10000) ' Initialize PWM1 module at 10KHz
' PWM2_Init(10000) ' Initialize PWM2 module at 10KHz
BP_MM_dir = 1
BP_M_dir = 1
BP_PP_dir = 1
'BP_P_dir = 1
' current_duty_T1 = 0
' current_duty_T2 = 0
gestion_pwm = 0
end sub
main:
' Main program
INIT()
' PWM1_Start() ' start PWM1
' PWM2_Start() ' start PWM2
' PWM1_Set_Duty(current_duty_T1) ' Set current duty for PWM1
' PWM2_Set_Duty(current_duty_T2) ' Set current duty for PWM2
Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear display
Lcd_Cmd(_LCD_CURSOR_OFF) ' Cursor off
toto = 10
while TRUE ' Endless loop
' Gestion des BP de réglage
if (BP_MM=1) and (compt<10) then
inc(compt)
end if
if (BP_MM=0)then
compt=0
end if
if (compt=1) then
toto = toto - 10
end if
if (BP_M=1) and (compt<10) then
inc(compt)
end if
if (BP_M=0)then
compt=0
end if
if (compt=1) then
toto = toto - 1
end if
' if (BP_P=1) and (compt<10) then
' inc(compt)
' end if
' if (BP_P=0)then
' compt=0
' end if
' if (compt=1) then
' toto = toto + 1
' end if
if (BP_PP=1) and (compt<10) then
inc(compt)
end if
if (BP_PP=0)then
compt=0
end if
if (compt=1) then
toto = toto + 10
end if
' Lecture de la tension de sortie, calcul et convertion en texte pour LCD
tension_num = ADC_Read(0)
tension = tension_num * 0.00488 *8
' Gestion du LCD
' Lcd_Out(2, 2, "ABAISSEUR") ' fonction du mode
Lcd_Out(1, 2, "TENSION DE SORTIE") ' fonction du mode
floattostr (tension,txt1)
Lcd_Out(2,2,txt1)
' ByteToStr(toto,txt)
' Lcd_Out(4,2,txt)
wend
end.
Impossible d'utiliser PC4 et PC5 comme entrée, les BP restent invisibles.
J'ai tenté d'utiliser le Port A pour les BP mais pas mieux, et l'effet remarqué et que du coup l'entrée ANA est complétement perturbé.
Pour le moment, je n'ai pas encore testé la partie PWM.
Est ce que j'ai fait une erreur de configuration pour les Port C 4 et 5?
Merci pour votre aide
