PIC16F1847 PWM output need pull up / down resistor - Page 1
Forum section: electronics / general

author: Veketti
author_rank: Regular Contributor
timestamp: August 14, 2023, 04:41:17 pm
content: Dear All,I know this might sound stupid but I'm about to use PIC 16F1847 to control RC digital servo and using the PWM CCP1 output. As I'm using the standard CCP1 and not enchanced CCP I didn't read the whole PWM chapter from the datasheet. Now I accidentally noticed under Enchansed topic following:QuoteThis made me confused that do I need to use pull up or pull down resistor for the PWM output pin? And which one do I need and why? I've googled few PIC - Servo examples and on their schematics didn't find any pull x resistors. Could somebody explain what this means. I have a feeling that this is about startup when these pins are floating and if it's critical for them to be eg. 0 it is needed, but I might be wrong.Then second question regarding the PWM pin, CCPx and timer relationship. Can CCP1 pin RB3 be standard PWM even though it is said to be Enhanced? Or is it must to use pins RA3 and RA4 which are said to be standard PWM? I've already designed the PCB to RB3 CCP1 pin and timer6 for the PWM, but now I'm bit hesitant whether it works.. I assume these others are what's called PxB, PxC and PxD.. Bit confusing.Thank you in advance

author: woofy
author_rank: Frequent Contributor
timestamp: August 14, 2023, 05:30:14 pm
content: CCP1 will be fine on RB3.You don't need pull up/down resistors for your application.They are needed when you drive H-bridges with a two phase PWM. At reset all pins are inputs until configured by the CPU. Floating pins could enable both high and low drives with rather disastrous consequences. So then pull up/down resistors are used to ensure safe voltages at startup.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 14, 2023, 05:50:39 pm
content: Quote from: Veketti on August 14, 2023, 04:41:17 pmFloating pins would be the reason. Imagine you were using the PWM to control a FET/driver as a boost converter. It would be bad if the gate of the FET/driver was floating while the PIC was in reset, and DC drain current started flowing. So in that case you'd use a pulldown to keep the FET/driver off while in reset.QuoteSounds like you can make the enhanced do the simple PWM function. Just need to change your code I would think:Quote

author: jpanhalt
author_rank: Super Contributor
timestamp: August 14, 2023, 06:26:40 pm
content: Some questions you might want to address:1) What refresh rate (frame frequency) does your digital servo use? Most common was 50 Hz, but some today are 100 Hz, as I recall.2) What resolution do you need? Resolution depends on fosc and frame frequency. See equation 24-4 and the tables that follow it.PIC hardware PWM can have difficulty getting down to 50 Hz; although, I have operated a standard 50Hz digital servo at 100 Hz without problems. I didn't need great resolution. Another approach is to set an interrupt (e.g,. TMR2) for your refresh rate and do the PWM with firmware.

author: Veketti
author_rank: Regular Contributor
timestamp: August 14, 2023, 07:45:33 pm
content: Thanks. I've configured the PWM to 125Hz as I read digital servos should be able to cope up to 200Hz.Code:TRISB3_bit = 1;PR6 = 250; // 125 HzCCP1CON = 0b00111100;CCPR1L = 0b01000100; // set dutycycle. 150 = 1,2ms. 275 = 2,2msCCPTMRS = 0b00000010; // User timer 6 for PWM modeTMR6IF_bit = 0;T6CON = 0b00000111; // 111 for prescaler 64TRISB3_bit = 0;I'm using servo "Corona DS339HV" and I haven't found any specification how high Hz will it accept. Fingers crossed the 125Hz is ok. At least it advertizes to be Digital servo..

author: jpanhalt
author_rank: Super Contributor
timestamp: August 14, 2023, 08:25:37 pm
content: Thank you for the added information. I have been inactive in the hobby for 10 to 12 years -- too busy on my "hobby farm." The specifications seem modest for modern top-line digital servos but are certainly in line with the JR servos then and others today. The highest I could go with a JR digital without faults was about 110 - 120 Hz in 2003. Considering advancements, your plan will probably work.John

author: Veketti
author_rank: Regular Contributor
timestamp: August 19, 2023, 02:07:50 pm
content: Just wanted to report back that the 125Hz worked perfectly for this particular servo. Also it seems it didn't matter if the PWM signal was 5VDC and power supply 7.2VDC for servo.