Menu

Low Frequency PWM with PIC12F1840

ashimotok0
3 days ago
3 days ago
  • ashimotok0

    ashimotok0 - 3 days ago

    Hi, I need to generate a Low Frequency PWM , preferrably with an 8 pin PIC device ... the PIC isn't doing much else other than generating a 3-stage PWM output ( i.e PWM 1 value for a period, the PWH 2 for a time period and then Period 3 continuous, until an input is triggered or the PIC is reset. The base frequency needs to around 250 Hz though. Am I correct in thinking this should be achievable with the PWM module on a PIC12F1840 with the internal oscillator set to 32kHz ? It's for a hydraulic valve application.

     
  • Anobium

    Anobium - 3 days ago

    By my calcs ( using the compiler ) the max chip frequency would be 4mHz for that slow PWM signal.

    You may be to do this will a timer and just generate your own signal at 32 mHz.

    Evan

    #chip PIC12F1840, 4 
    #option Explicit
    
        #define PWM_Freq 0.25  'Set frequency in KHz
        #define PWM_Duty 50    'Set duty cycle to 80 %
        PWMOn                  'Turn on the PWM
    
        WAIT 10 s              'Wait 10 seconds
        PWMOff                 'Turn off the PWM
    
     
  • ashimotok0

    ashimotok0 - 3 days ago

    Thanks Evan ... really appreciate your help ... I need to get a prototype board set up for the PIC12F1840, so it may be a couple of days before I can test.

    I line 2 should it be: #define PWM_Duty 50 'Set duty cycle to 50 %

    Also "You may be to do this will a timer and just generate your own signal at 32 mHz." should this be MHz ?

     
    • Anobium

      Anobium - 3 days ago

      I line 2 should it be: #define PWM_Duty 50 'Set duty cycle to 50 %

      You are correct.

      Also "You may be to do this will a timer and just generate your own signal at 32 mHz." should this be MHz ?

      You would have to set the timer2 to interrupt at the frequency you need. Then toggle the output port.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.