Bienvenue aux nouveaux arrivants sur FantasPic !

- Pensez à lire les règles durant votre visite, il n'y en a pas beaucoup, mais encore faut-il les respecter .
- N’hésitez pas à faire des remarques et/ou suggestions sur le Forum, dans le but de l'améliorer et de rendre vos prochaines visites plus agréables.
- Vous pouvez regarder votre "panneau de l'utilisateur" afin de configurer vos préférences.
- Un passage par "l'utilisation du forum" est recommandé pour connaître les fonctionnalités du forum.

--- L’équipe FantasPic ---
Forum général en BASIC et PASCAL !

Modérateur : Gérard

Configuration 18F2550
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#1 Message par cyril13110 » dim. 12 avr. 2020 20:42

Bonjour à tous,

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<10then
               inc
(compt)
          
end if
          if (
BP_MM=0)then
             compt
=0
          end 
if
          if (
compt=1then
              toto 
toto 10
          end 
if

       if (
BP_M=1) and (compt<10then
               inc
(compt)
          
end if
          if (
BP_M=0)then
             compt
=0
          end 
if
          if (
compt=1then
              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 sortiecalcul et convertion en texte pour LCD
          tension_num 
ADC_Read(0)
          
tension tension_num 0.00488 *8

      
' Gestion du LCD
      '   
Lcd_Out(22"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

Configuration 18F2550
satinas
Expert
Expert
Messages : 1225
Enregistré en : novembre 2015

#2 Message par satinas » dim. 12 avr. 2020 21:16

Bonsoir cyril13110

Note: On a Power-on Reset, these pins, except RC4 and RC5, are configured as digital inputs. To use pins RC4 and RC5 as digital inputs,
the USB module must be disabled (UCON<3> = 0) and the on-chip USB transceiver must be disabled (UCFG<3> = 1)

D'après le datasheet au reset UCON<3> et UCFG<3> sont à 0, donc le transceiver USB est actif.

Configuration 18F2550
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#3 Message par cyril13110 » dim. 12 avr. 2020 22:03

oups il va falloir que je m'améliore en anglais.....
je sais bien que j'avais zappé un truc.
merci satinas poir tes lumières.... anglaises....

Configuration 18F2550
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#4 Message par cyril13110 » lun. 13 avr. 2020 22:29

bonsoir à tous,

je reviens avec un nouveau problème sur lequel je bloque depuis 3 jours.
Je souhaite utiliser les 2 PWM du pic.
Le PWM1 fonctionne sans problème, par contre dés que je veux utiliser le PWM2 tous mon code déraille, l'afficheur affiche n'importe quoi voir plus rien.
J'ai passé la datasheet du 18F2550, j'ai vue qu'il y a un paramétrage à faire si non l'utilisation du PWM2 perturbe le portB3 de mémoire ( ce qui expliquerais la réaction de l'afficheur).
J'ai beau passé la datasheet en revue et tester tous les registres correspondant au PWM et comparateur mais rien ny fait.
Est ce que quelqu'un aurai déjà utilisé ce pic avec les 2 PWM?

Je viens de nettoyer mon code, je vais continuer de creuser même si je ne sais plus trop quoi configurer.

Code : Tout sélectionner


program Alimentation_de_laboratoire

' Declarations section 
 ' 
Lcd module connections
dim LCD_RS 
as sbit at LATB4_bit
    LCD_EN 
as sbit at LATB5_bit
    LCD_D4 
as sbit at LATB0_bit
    LCD_D5 
as sbit at LATB1_bit
    LCD_D6 
as sbit at LATB2_bit
    LCD_D7 
as sbit at LATB3_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_PP,compt_P,compt_M,compt_MM,current_duty_T1, current_duty_T2, gestion_pwm,toto,titi_bit as byte
dim tension as float
dim tension_num, titi as word
dim txt,txt1 as string[12]

BP_PP as sbit at PORTC.4
BP_P as sbit at PORTC.5
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
LED_test as sbit at PORTC.0
LED_test_dir  as sbit at TRISC0_bit

 sub procedure INIT()
     ADCON0 = 0x01
     ADCON1 = 0x0E
     ADCON2 = 0xA4
     UCFG.UTRDIS = 1
     UCON.3 = 0
     TRISA0_bit = 1
     TRISB = 0x00      ' 
PortB en sortie
     PWM1_Init
(10000)                    ' Initialize PWM1 module at 10KHz
     PWM2_Init(10000)                    ' 
Initialize PWM2 module at 10KHz
     BP_MM_dir 
1
     BP_M_dir 
1
     LED_test_dir 
0
     current_duty_T1 
0
     current_duty_T2 
0
     titi_bit
=0
     titi 
0
     LED_test 
0
     toto 
0

end sub

sub procedure LCD_affichage
()

         
Lcd_Out(12"TENSION DE SORTIE")   ' fonction du mode

         floattostr (tension,txt1)
         Lcd_Out(2,4,txt1)
         Lcd_Out(2,15, "VOLT")

        If tension <= 19 then
           Lcd_Out(4,2,"ABAISSEUR")
        end if
        
        If tension > 19 then
           Lcd_Out(4,2,"ELEVATEUR")
        end if
        
end sub


main:
'   
Main program 
    INIT
()

    
Lcd_Init()                     ' Initialize Lcd
    Lcd_Cmd(_LCD_CLEAR)            ' 
Clear display
    Lcd_Cmd
(_LCD_CURSOR_OFF)       ' Cursor off

    while TRUE                     ' 
Endless loop

       
' Gestion des BP de réglage
         if (BP_MM=1) and (compt_MM<10) then
               inc(compt_MM)
          end if
          if (BP_MM=0)then
             compt_MM=0
          end if
          if (compt_MM=2) then
              titi = titi - 10
          end if

       if (BP_M=1) and (compt_M<10) then
               inc(compt_M)
          end if
          if (BP_M=0)then
             compt_M=0
          end if
          if (compt_M=2) then
              titi = titi - 1
          end if
          
          if (BP_P=1) and (compt_P<10) then
               inc(compt_P)
          end if
          if (BP_P=0)then
             compt_P=0
          end if
          if (compt_P=2) then
              titi = titi + 1
          end if

          if (BP_PP=1) and (compt_PP<10) then
               inc(compt_PP)
          end if
          if (BP_PP=0)then
             compt_PP=0
          end if
          if (compt_PP=2) then
              titi = titi + 10
          end if
 
   ' 
Lecture de la tension de sortiecalcul et convertion en texte pour LCD
          tension_num 
ADC_Read(0)
          
tension = (tension_num 0.00488) * 8
 
          
if titi<255 then
              titi_bit
=0
              LED_test 
0
          
else
              
titi_bit=1
              LED_test 
1
          end 
if
  
             
toto.0 titi.0
             toto.1 
titi.1
             toto.2 
titi.2
             toto.3 
titi.3
             toto.4 
titi.4
             toto.5 
titi.5
             toto.6 
titi.6
             toto.7 
titi.7

             
if titi_bit=0 then
                PWM1_Start
()
                
PWM2_Stop()
                
PWM1_Set_Duty(toto)        ' Set current duty for PWM1
              else
                PWM1_Stop()
                PWM2_Start()
                PWM2_Set_Duty(toto)        ' 
Set current duty for PWM1
              end 
if
          
          if 
titi>388 then
             titi 
388
          end 
if
  
          
' Gestion du LCD
          LCD_affichage()

    wend
end.


Merci pour vos lumières

Configuration 18F2550
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#5 Message par cyril13110 » lun. 13 avr. 2020 23:00

apres controle je confirme bien que RB3 est bien le PWM2 et je souhaiterais avoir le PWM2 sur RC1.

Configuration 18F2550
satinas
Expert
Expert
Messages : 1225
Enregistré en : novembre 2015

#6 Message par satinas » mar. 14 avr. 2020 07:56

Bonjour,
d'après le datasheet, le 18F4550 possède 2 modules PWM distincts mais de même fréquence car utilisant le même timer 2.
- un module ECCP1 qui sort soit en PWM sur C2, soit en Enhanced PWM sur 4 channels C2, D5, D6, D7.
- un module CCP2 qui sort en PWM sur C1, ou sur l'alternate pin B3.
La sélection de la pin C1 ou B3 se fait par le bit CCP2MX de l'octet de configuration hardware CONFIG3H. Regarde le chapitre sur les Configuration Bits.

Configuration 18F2550
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#7 Message par cyril13110 » mar. 14 avr. 2020 09:58

Bonjour satinas et bonjour tous le monde,

Je viens compléter en fonction de ta réponse.
Hier j'ai testé ce registre et ce bit particulier, je viens de le retester ce matin mais MIKROBASIC me dit qu'il n'est pas connu,le soft me demande de déclarer la variable.
Je suis allé voir dans le fichier d'identification du 18F2550 propre à MIKROBASIC et effectivement il n'y ai pas.
Je pense que oui mais je ne sais pas comment faire car je ne l'ai jamais fait,
comment faire pour travailler avec les adresses de registres et pas avec la symbolique? peut etre que ca passerai comme ca.......

Configuration 18F2550
satinas
Expert
Expert
Messages : 1225
Enregistré en : novembre 2015

#8 Message par satinas » mar. 14 avr. 2020 10:36

Je connais pas mikroBasic. Après l'avoir installé, je vois bien un CCP2MX déclaré dans le fichier "P18F4550.mlk" du soft.
Il est bien présent dans le choix des bits de configuration (Edit Project).
Tu as la dernière version ?

Configuration 18F2550
cyril13110
Confirmé
Confirmé
Messages : 724
Âge : 41
Enregistré en : avril 2016
Localisation : 13

#9 Message par cyril13110 » mar. 14 avr. 2020 10:55

jai fait la mise a jpur du soft oui il y a 2 jours.
et je suis sur le 2550 et pas le 4550.

Configuration 18F2550
satinas
Expert
Expert
Messages : 1225
Enregistré en : novembre 2015

#10 Message par satinas » mar. 14 avr. 2020 11:06

J'ai encore lu de travers, mais je l'ai aussi sur le 18F2550.

mikroBasic_18F2550.png
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.


Retourner vers « Langage BASIC & PASCAL »

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 38 invités